2023-03-27 17:53:18 +02:00
|
|
|
package limits
|
|
|
|
|
|
|
|
import (
|
2023-03-27 19:51:48 +02:00
|
|
|
"github.com/jmoiron/sqlx"
|
2023-03-27 17:53:18 +02:00
|
|
|
"github.com/openziti/zrok/controller/store"
|
2023-06-05 22:01:04 +02:00
|
|
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
2023-03-27 20:06:57 +02:00
|
|
|
"github.com/pkg/errors"
|
2023-03-27 17:53:18 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type accountRelaxAction struct {
|
|
|
|
str *store.Store
|
2023-06-05 22:01:04 +02:00
|
|
|
zCfg *zrokEdgeSdk.Config
|
2023-03-27 17:53:18 +02:00
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
func newAccountRelaxAction(str *store.Store, zCfg *zrokEdgeSdk.Config) *accountRelaxAction {
|
|
|
|
return &accountRelaxAction{str, zCfg}
|
2023-03-27 17:53:18 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 20:06:57 +02:00
|
|
|
func (a *accountRelaxAction) HandleAccount(acct *store.Account, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
2023-03-27 17:53:18 +02:00
|
|
|
logrus.Infof("relaxing '%v'", acct.Email)
|
2023-03-27 20:06:57 +02:00
|
|
|
|
|
|
|
envs, err := a.str.FindEnvironmentsForAccount(acct.Id, trx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error finding environments for account '%v'", acct.Email)
|
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
edge, err := zrokEdgeSdk.Client(a.zCfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-27 20:06:57 +02:00
|
|
|
for _, env := range envs {
|
|
|
|
shrs, err := a.str.FindSharesForEnvironment(env.Id, trx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error finding shares for environment '%v'", env.ZId)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, shr := range shrs {
|
2023-03-29 21:08:04 +02:00
|
|
|
switch shr.ShareMode {
|
|
|
|
case "public":
|
2023-06-05 22:01:04 +02:00
|
|
|
if err := relaxPublicShare(a.str, edge, shr, trx); err != nil {
|
2023-05-18 19:19:16 +02:00
|
|
|
return errors.Wrap(err, "error relaxing public share")
|
2023-03-29 21:08:04 +02:00
|
|
|
}
|
|
|
|
case "private":
|
2023-06-05 22:01:04 +02:00
|
|
|
if err := relaxPrivateShare(a.str, edge, shr, trx); err != nil {
|
2023-05-18 19:19:16 +02:00
|
|
|
return errors.Wrap(err, "error relaxing private share")
|
2023-03-27 20:06:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:53:18 +02:00
|
|
|
return nil
|
|
|
|
}
|