mirror of
https://github.com/openziti/zrok.git
synced 2025-08-19 12:24:37 +02:00
share limits check owned by limits.Agent now (#277)
This commit is contained in:
@@ -43,14 +43,8 @@ func (a *Agent) Stop() {
|
||||
<-a.join
|
||||
}
|
||||
|
||||
func (a *Agent) CanCreateEnvironment(acctId int) (bool, error) {
|
||||
if a.cfg.Environments > Unlimited {
|
||||
trx, err := a.str.Begin()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "error creating transaction")
|
||||
}
|
||||
defer func() { _ = trx.Rollback() }()
|
||||
|
||||
func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) {
|
||||
if a.cfg.Enforcing && a.cfg.Environments > Unlimited {
|
||||
envs, err := a.str.FindEnvironmentsForAccount(acctId, trx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -62,6 +56,28 @@ func (a *Agent) CanCreateEnvironment(acctId int) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *Agent) CanCreateShare(acctId int, trx *sqlx.Tx) (bool, error) {
|
||||
if a.cfg.Enforcing && a.cfg.Shares > Unlimited {
|
||||
envs, err := a.str.FindEnvironmentsForAccount(acctId, trx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
total := 0
|
||||
for i := range envs {
|
||||
shrs, err := a.str.FindSharesForEnvironment(envs[i].Id, trx)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "unable to find shares for environment '%v'", envs[i].ZId)
|
||||
}
|
||||
total += len(shrs)
|
||||
if total+1 > a.cfg.Shares {
|
||||
return false, nil
|
||||
}
|
||||
logrus.Infof("total = %d", total)
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *Agent) Handle(u *metrics.Usage) error {
|
||||
logrus.Debugf("handling: %v", u)
|
||||
a.queue <- u
|
||||
|
Reference in New Issue
Block a user