2023-03-27 17:43:58 +02:00
|
|
|
package limits
|
|
|
|
|
|
|
|
import (
|
2023-03-27 19:51:48 +02:00
|
|
|
"github.com/jmoiron/sqlx"
|
2023-05-25 17:50:38 +02:00
|
|
|
"github.com/openziti/edge-api/rest_management_api_client"
|
2023-03-27 17:43:58 +02:00
|
|
|
"github.com/openziti/zrok/controller/store"
|
2023-03-27 20:01:31 +02:00
|
|
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
|
|
|
"github.com/pkg/errors"
|
2023-03-27 17:43:58 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type environmentLimitAction struct {
|
|
|
|
str *store.Store
|
|
|
|
edge *rest_management_api_client.ZitiEdgeManagement
|
|
|
|
}
|
|
|
|
|
|
|
|
func newEnvironmentLimitAction(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *environmentLimitAction {
|
|
|
|
return &environmentLimitAction{str, edge}
|
|
|
|
}
|
|
|
|
|
2023-03-27 20:01:31 +02:00
|
|
|
func (a *environmentLimitAction) HandleEnvironment(env *store.Environment, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
|
|
|
logrus.Infof("limiting '%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)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, shr := range shrs {
|
2023-05-18 20:25:53 +02:00
|
|
|
if err := zrokEdgeSdk.DeleteServicePoliciesDial(env.ZId, shr.Token, a.edge); err != nil {
|
2023-03-27 20:01:31 +02:00
|
|
|
return errors.Wrapf(err, "error deleting dial service policy for '%v'", shr.Token)
|
|
|
|
}
|
|
|
|
logrus.Infof("removed dial service policy for share '%v' of environment '%v'", shr.Token, env.ZId)
|
|
|
|
}
|
|
|
|
|
2023-03-27 17:43:58 +02:00
|
|
|
return nil
|
|
|
|
}
|