2023-03-27 17:43:58 +02:00
|
|
|
package limits
|
|
|
|
|
|
|
|
import (
|
2023-03-27 19:51:48 +02:00
|
|
|
"github.com/jmoiron/sqlx"
|
2023-03-27 17:43:58 +02:00
|
|
|
"github.com/openziti/zrok/controller/store"
|
2023-06-05 22:01:04 +02:00
|
|
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
2023-11-21 20:27:17 +01:00
|
|
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
2023-03-27 20:01:31 +02:00
|
|
|
"github.com/pkg/errors"
|
2023-03-27 17:43:58 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type environmentRelaxAction struct {
|
|
|
|
str *store.Store
|
2023-06-05 22:01:04 +02:00
|
|
|
zCfg *zrokEdgeSdk.Config
|
2023-03-27 17:43:58 +02:00
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
func newEnvironmentRelaxAction(str *store.Store, zCfg *zrokEdgeSdk.Config) *environmentRelaxAction {
|
|
|
|
return &environmentRelaxAction{str, zCfg}
|
2023-03-27 17:43:58 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 20:01:31 +02:00
|
|
|
func (a *environmentRelaxAction) HandleEnvironment(env *store.Environment, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
|
|
|
logrus.Infof("relaxing '%v'", env.ZId)
|
|
|
|
|
|
|
|
shrs, err := a.str.FindSharesForEnvironment(env.Id, trx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error finding shares for environment '%v'", env.ZId)
|
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
edge, err := zrokEdgeSdk.Client(a.zCfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-27 20:01:31 +02:00
|
|
|
for _, shr := range shrs {
|
2023-03-28 21:05:51 +02:00
|
|
|
if !shr.Deleted {
|
2023-03-29 21:08:04 +02:00
|
|
|
switch shr.ShareMode {
|
2023-07-17 22:21:29 +02:00
|
|
|
case string(sdk.PublicShareMode):
|
2023-06-05 22:01:04 +02:00
|
|
|
if err := relaxPublicShare(a.str, edge, shr, trx); err != nil {
|
2023-03-29 21:08:04 +02:00
|
|
|
return err
|
2023-03-28 21:05:51 +02:00
|
|
|
}
|
2023-07-17 22:21:29 +02:00
|
|
|
case string(sdk.PrivateShareMode):
|
2023-06-05 22:01:04 +02:00
|
|
|
if err := relaxPrivateShare(a.str, edge, shr, trx); err != nil {
|
2023-03-29 21:08:04 +02:00
|
|
|
return err
|
2023-03-28 21:05:51 +02:00
|
|
|
}
|
2023-03-27 20:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:43:58 +02:00
|
|
|
return nil
|
|
|
|
}
|