2023-03-27 17:34:29 +02:00
|
|
|
package limits
|
|
|
|
|
|
|
|
import (
|
2023-03-27 19:51:48 +02:00
|
|
|
"github.com/jmoiron/sqlx"
|
2023-03-27 17:34:29 +02:00
|
|
|
"github.com/openziti/edge/rest_management_api_client"
|
|
|
|
"github.com/openziti/zrok/controller/store"
|
2023-03-27 19:51:48 +02:00
|
|
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
2023-03-27 17:34:29 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type shareLimitAction struct {
|
|
|
|
str *store.Store
|
|
|
|
edge *rest_management_api_client.ZitiEdgeManagement
|
|
|
|
}
|
|
|
|
|
|
|
|
func newShareLimitAction(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *shareLimitAction {
|
|
|
|
return &shareLimitAction{str, edge}
|
|
|
|
}
|
|
|
|
|
2023-03-27 19:51:48 +02:00
|
|
|
func (a *shareLimitAction) HandleShare(s *store.Share, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
2023-03-27 17:34:29 +02:00
|
|
|
logrus.Infof("limiting '%v'", s.Token)
|
2023-03-27 19:51:48 +02:00
|
|
|
|
|
|
|
env, err := a.str.GetEnvironment(s.EnvironmentId, trx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := zrokEdgeSdk.DeleteServicePolicyDial(env.ZId, s.Token, a.edge); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.Infof("removed service dial policy for '%v'", s.Token)
|
|
|
|
|
2023-03-27 17:34:29 +02:00
|
|
|
return nil
|
|
|
|
}
|