diff --git a/controller/limits/agent.go b/controller/limits/agent.go index d1885e46..5d2b2303 100644 --- a/controller/limits/agent.go +++ b/controller/limits/agent.go @@ -107,7 +107,11 @@ func (a *Agent) CanCreateShare(acctId, envId int, reserved, uniqueName bool, _ s } } - if ul.resource.GetShares() > store.Unlimited || (reserved && ul.resource.GetReservedShares() > store.Unlimited) || (reserved && uniqueName && ul.resource.GetUniqueNames() > store.Unlimited) { + rc := ul.resource + if scopeRc, found := ul.scopes[backendMode]; found { + rc = scopeRc + } + if rc.GetShares() > store.Unlimited || (reserved && rc.GetReservedShares() > store.Unlimited) || (reserved && uniqueName && rc.GetUniqueNames() > store.Unlimited) { envs, err := a.str.FindEnvironmentsForAccount(acctId, trx) if err != nil { return false, err @@ -129,15 +133,15 @@ func (a *Agent) CanCreateShare(acctId, envId int, reserved, uniqueName bool, _ s uniqueNames++ } } - if total+1 > ul.resource.GetShares() { + if total+1 > rc.GetShares() { logrus.Debugf("account '%d', environment '%d' over shares limit '%d'", acctId, envId, a.cfg.Shares) return false, nil } - if reserved && reserveds+1 > ul.resource.GetReservedShares() { + if reserved && reserveds+1 > rc.GetReservedShares() { logrus.Debugf("account '%v', environment '%d' over reserved shares limit '%d'", acctId, envId, a.cfg.ReservedShares) return false, nil } - if reserved && uniqueName && uniqueNames+1 > ul.resource.GetUniqueNames() { + if reserved && uniqueName && uniqueNames+1 > rc.GetUniqueNames() { logrus.Debugf("account '%v', environment '%d' over unique names limit '%d'", acctId, envId, a.cfg.UniqueNames) return false, nil } diff --git a/controller/limits/userLimits.go b/controller/limits/userLimits.go index 92c1bab3..3b40e256 100644 --- a/controller/limits/userLimits.go +++ b/controller/limits/userLimits.go @@ -11,7 +11,7 @@ import ( type userLimits struct { resource store.ResourceCountClass bandwidth []store.BandwidthClass - scopes map[sdk.BackendMode]store.BandwidthClass + scopes map[sdk.BackendMode]*store.LimitClass } func (ul *userLimits) toBandwidthArray(backendMode sdk.BackendMode) []store.BandwidthClass { @@ -50,7 +50,7 @@ func (a *Agent) getUserLimits(acctId int, trx *sqlx.Tx) (*userLimits, error) { cfgBwcs := newConfigBandwidthClasses(a.cfg.Bandwidth) bwWarning := cfgBwcs[0] bwLimit := cfgBwcs[1] - scopes := map[sdk.BackendMode]store.BandwidthClass{} + scopes := make(map[sdk.BackendMode]*store.LimitClass) alcs, err := a.str.FindAppliedLimitClassesForAccount(acctId, trx) if err != nil { @@ -65,10 +65,10 @@ func (a *Agent) getUserLimits(acctId int, trx *sqlx.Tx) (*userLimits, error) { } else { bwLimit = alc } - } else if a.isScopedBandwidthClass(alc) { + } else if a.isScopedLimitClass(alc) { scopes[*alc.BackendMode] = alc } else { - logrus.Warnf("unknown type of limit class '%v'", alc) + logrus.Warnf("unknown type of limit class '%v' for account '#%d'", alc, acctId) } } @@ -107,11 +107,11 @@ func (a *Agent) isUnscopedBandwidthClass(alc *store.LimitClass) bool { return true } -func (a *Agent) isScopedBandwidthClass(alc *store.LimitClass) bool { +func (a *Agent) isScopedLimitClass(alc *store.LimitClass) bool { if alc.BackendMode == nil { return false } - if alc.Environments > store.Unlimited || alc.Shares > store.Unlimited || alc.ReservedShares > store.Unlimited || alc.UniqueNames > store.Unlimited { + if alc.Environments > store.Unlimited { return false } if alc.PeriodMinutes < 1 {