setting_quota.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package setting
  2. type OrgQuota struct {
  3. User int64 `target:"org_user"`
  4. DataSource int64 `target:"data_source"`
  5. Dashboard int64 `target:"dashboard"`
  6. ApiKey int64 `target:"api_key"`
  7. }
  8. type UserQuota struct {
  9. Org int64 `target:"org_user"`
  10. }
  11. type GlobalQuota struct {
  12. Org int64 `target:"org"`
  13. User int64 `target:"user"`
  14. DataSource int64 `target:"data_source"`
  15. Dashboard int64 `target:"dashboard"`
  16. ApiKey int64 `target:"api_key"`
  17. Session int64 `target:"-"`
  18. }
  19. type QuotaSettings struct {
  20. Enabled bool
  21. Org *OrgQuota
  22. User *UserQuota
  23. Global *GlobalQuota
  24. }
  25. func readQuotaSettings() {
  26. // set global defaults.
  27. quota := Cfg.Section("quota")
  28. Quota.Enabled = quota.Key("enabled").MustBool(false)
  29. // per ORG Limits
  30. Quota.Org = &OrgQuota{
  31. User: quota.Key("org_user").MustInt64(10),
  32. DataSource: quota.Key("org_data_source").MustInt64(10),
  33. Dashboard: quota.Key("org_dashboard").MustInt64(10),
  34. ApiKey: quota.Key("org_api_key").MustInt64(10),
  35. }
  36. // per User limits
  37. Quota.User = &UserQuota{
  38. Org: quota.Key("user_org").MustInt64(10),
  39. }
  40. // Global Limits
  41. Quota.Global = &GlobalQuota{
  42. User: quota.Key("global_user").MustInt64(-1),
  43. Org: quota.Key("global_org").MustInt64(-1),
  44. DataSource: quota.Key("global_data_source").MustInt64(-1),
  45. Dashboard: quota.Key("global_dashboard").MustInt64(-1),
  46. ApiKey: quota.Key("global_api_key").MustInt64(-1),
  47. Session: quota.Key("global_session").MustInt64(-1),
  48. }
  49. }