mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
This reverts commit 326ea86a57.
This commit is contained in:
committed by
GitHub
parent
228ec4c0f3
commit
96cdf77995
@@ -1,5 +1,9 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type OrgQuota struct {
|
||||
User int64 `target:"org_user"`
|
||||
DataSource int64 `target:"data_source"`
|
||||
@@ -23,17 +27,45 @@ type GlobalQuota struct {
|
||||
File int64 `target:"file"`
|
||||
}
|
||||
|
||||
func (q *OrgQuota) ToMap() map[string]int64 {
|
||||
return quotaToMap(*q)
|
||||
}
|
||||
|
||||
func (q *UserQuota) ToMap() map[string]int64 {
|
||||
return quotaToMap(*q)
|
||||
}
|
||||
|
||||
func quotaToMap(q interface{}) map[string]int64 {
|
||||
qMap := make(map[string]int64)
|
||||
typ := reflect.TypeOf(q)
|
||||
val := reflect.ValueOf(q)
|
||||
|
||||
for i := 0; i < typ.NumField(); i++ {
|
||||
field := typ.Field(i)
|
||||
name := field.Tag.Get("target")
|
||||
if name == "" {
|
||||
name = field.Name
|
||||
}
|
||||
if name == "-" {
|
||||
continue
|
||||
}
|
||||
value := val.Field(i)
|
||||
qMap[name] = value.Int()
|
||||
}
|
||||
return qMap
|
||||
}
|
||||
|
||||
type QuotaSettings struct {
|
||||
Enabled bool
|
||||
Org OrgQuota
|
||||
User UserQuota
|
||||
Global GlobalQuota
|
||||
Org *OrgQuota
|
||||
User *UserQuota
|
||||
Global *GlobalQuota
|
||||
}
|
||||
|
||||
func (cfg *Cfg) readQuotaSettings() {
|
||||
// set global defaults.
|
||||
quota := cfg.Raw.Section("quota")
|
||||
cfg.Quota.Enabled = quota.Key("enabled").MustBool(false)
|
||||
Quota.Enabled = quota.Key("enabled").MustBool(false)
|
||||
|
||||
var alertOrgQuota int64
|
||||
var alertGlobalQuota int64
|
||||
@@ -42,7 +74,7 @@ func (cfg *Cfg) readQuotaSettings() {
|
||||
alertGlobalQuota = quota.Key("global_alert_rule").MustInt64(-1)
|
||||
}
|
||||
// per ORG Limits
|
||||
cfg.Quota.Org = OrgQuota{
|
||||
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),
|
||||
@@ -51,12 +83,12 @@ func (cfg *Cfg) readQuotaSettings() {
|
||||
}
|
||||
|
||||
// per User limits
|
||||
cfg.Quota.User = UserQuota{
|
||||
Quota.User = &UserQuota{
|
||||
Org: quota.Key("user_org").MustInt64(10),
|
||||
}
|
||||
|
||||
// Global Limits
|
||||
cfg.Quota.Global = GlobalQuota{
|
||||
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),
|
||||
@@ -66,4 +98,6 @@ func (cfg *Cfg) readQuotaSettings() {
|
||||
File: quota.Key("global_file").MustInt64(-1),
|
||||
AlertRule: alertGlobalQuota,
|
||||
}
|
||||
|
||||
cfg.Quota = Quota
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user