mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
roughed-in CanAccessShare supporting limit classes (#606)
This commit is contained in:
parent
93ecd833b2
commit
3258c3ee73
@ -202,17 +202,56 @@ func (a *Agent) CanAccessShare(shrId int, trx *sqlx.Tx) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if empty, err := a.str.IsBandwidthLimitJournalEmpty(shr.Id, trx); err == nil && !empty {
|
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
|
||||||
slj, err := a.str.FindLatestBandwidthLimitJournal(shr.Id, trx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if slj.Action == store.LimitLimitAction {
|
if env.AccountId != nil {
|
||||||
|
alcs, err := a.str.FindAppliedLimitClassesForAccount(*env.AccountId, trx)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
maxShares := a.cfg.Shares
|
||||||
|
maxReservedShares := a.cfg.ReservedShares
|
||||||
|
maxUniqueNames := a.cfg.UniqueNames
|
||||||
|
var lcId *int
|
||||||
|
var points = -1
|
||||||
|
for _, alc := range alcs {
|
||||||
|
if a.bandwidthClassPoints(alc) > points {
|
||||||
|
if alc.Shares >= maxShares || alc.ReservedShares >= maxReservedShares || alc.UniqueNames >= maxUniqueNames {
|
||||||
|
maxShares = alc.Shares
|
||||||
|
maxReservedShares = alc.ReservedShares
|
||||||
|
maxUniqueNames = alc.UniqueNames
|
||||||
|
lcId = &alc.Id
|
||||||
|
points = a.bandwidthClassPoints(alc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if lcId == nil {
|
||||||
|
if empty, err := a.str.IsBandwidthLimitJournalEmptyForGlobal(*env.AccountId, trx); err == nil && !empty {
|
||||||
|
lj, err := a.str.FindLatestBandwidthLimitJournalForGlobal(*env.AccountId, trx)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if lj.Action == store.LimitLimitAction {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
}
|
||||||
|
} else {
|
||||||
|
if empty, err := a.str.IsBandwidthLimitJournalEmptyForLimitClass(*env.AccountId, *lcId, trx); err == nil && !empty {
|
||||||
|
lj, err := a.str.FindLatestBandwidthLimitJournalForLimitClass(*env.AccountId, *lcId, trx)
|
||||||
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
if lj.Action == store.LimitLimitAction {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user