mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
enhance quota support.
now includes: - perOrg (users, dashboards, datasources, api_keys) - perUser (orgs) - global (users, orgs, dashboards, datasources, api_keys, sessions)
This commit is contained in:
@@ -1,17 +1,58 @@
|
||||
package setting
|
||||
|
||||
type OrgQuota struct {
|
||||
User int64 `target:"org_user"`
|
||||
DataSource int64 `target:"data_source"`
|
||||
Dashboard int64 `target:"dashboard"`
|
||||
ApiKey int64 `target:"api_key"`
|
||||
}
|
||||
|
||||
type UserQuota struct {
|
||||
Org int64 `target:"org_user"`
|
||||
}
|
||||
|
||||
type GlobalQuota struct {
|
||||
Org int64 `target:"org"`
|
||||
User int64 `target:"user"`
|
||||
DataSource int64 `target:"data_source"`
|
||||
Dashboard int64 `target:"dashboard"`
|
||||
ApiKey int64 `target:"api_key"`
|
||||
Session int64 `target:"-"`
|
||||
}
|
||||
|
||||
type QuotaSettings struct {
|
||||
Enabled bool
|
||||
Default map[string]int64
|
||||
Org *OrgQuota
|
||||
User *UserQuota
|
||||
Global *GlobalQuota
|
||||
}
|
||||
|
||||
func readQuotaSettings() {
|
||||
// set global defaults.
|
||||
DefaultQuotas := make(map[string]int64)
|
||||
quota := Cfg.Section("quota")
|
||||
Quota.Enabled = quota.Key("enabled").MustBool(false)
|
||||
DefaultQuotas["user"] = quota.Key("user").MustInt64(10)
|
||||
DefaultQuotas["data_source"] = quota.Key("data_source").MustInt64(10)
|
||||
DefaultQuotas["dashboard"] = quota.Key("dashboard").MustInt64(10)
|
||||
Quota.Default = DefaultQuotas
|
||||
|
||||
// per ORG Limits
|
||||
Quota.Org = &OrgQuota{
|
||||
User: quota.Key("org_user").MustInt64(10),
|
||||
DataSource: quota.Key("org_data_source").MustInt64(10),
|
||||
Dashboard: quota.Key("org_dashboard").MustInt64(10),
|
||||
ApiKey: quota.Key("org_api_key").MustInt64(10),
|
||||
}
|
||||
|
||||
// per User limits
|
||||
Quota.User = &UserQuota{
|
||||
Org: quota.Key("user_org").MustInt64(10),
|
||||
}
|
||||
|
||||
// Global Limits
|
||||
Quota.Global = &GlobalQuota{
|
||||
User: quota.Key("global_user").MustInt64(-1),
|
||||
Org: quota.Key("global_org").MustInt64(-1),
|
||||
DataSource: quota.Key("global_data_source").MustInt64(-1),
|
||||
Dashboard: quota.Key("global_dashboard").MustInt64(-1),
|
||||
ApiKey: quota.Key("global_api_key").MustInt64(-1),
|
||||
Session: quota.Key("global_session").MustInt64(-1),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user