mix in scoped bandwidth clases (#606)

This commit is contained in:
Michael Quigley 2024-06-05 17:03:24 -04:00
parent b511eeee17
commit 83e9e84dad
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 17 additions and 5 deletions

View File

@ -313,17 +313,17 @@ func (a *Agent) enforce(u *metrics.Usage) error {
return nil
}
//shr, err := a.str.FindShareWithTokenEvenIfDeleted(u.ShareToken, trx)
//if err != nil {
// return err
//}
shr, err := a.str.FindShareWithTokenEvenIfDeleted(u.ShareToken, trx)
if err != nil {
return err
}
ul, err := a.getUserLimits(int(u.AccountId), trx)
if err != nil {
return err
}
exceededLc, rxBytes, txBytes, err := a.isOverLimitClass(u, ul.bandwidth)
exceededLc, rxBytes, txBytes, err := a.isOverLimitClass(u, ul.toBandwidthArray(sdk.BackendMode(shr.BackendMode)))
if err != nil {
return errors.Wrap(err, "error checking limit classes")
}

View File

@ -14,6 +14,18 @@ type userLimits struct {
scopes map[sdk.BackendMode]store.BandwidthClass
}
func (ul *userLimits) toBandwidthArray(backendMode sdk.BackendMode) []store.BandwidthClass {
if scopedBwc, found := ul.scopes[backendMode]; found {
out := make([]store.BandwidthClass, 0)
for _, bwc := range ul.bandwidth {
out = append(out, bwc)
}
out = append(out, scopedBwc)
return out
}
return ul.bandwidth
}
func (a *Agent) getUserLimits(acctId int, trx *sqlx.Tx) (*userLimits, error) {
resource := newConfigResourceCountClass(a.cfg)
cfgBwcs := newConfigBandwidthClasses(a.cfg.Bandwidth)