zrok/controller/limits/shareLimitAction.go

35 lines
938 B
Go
Raw Normal View History

2023-03-27 17:34:29 +02:00
package limits
import (
"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:34:29 +02:00
"github.com/openziti/zrok/controller/store"
"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}
}
func (a *shareLimitAction) HandleShare(shr *store.Share, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("limiting '%v'", shr.Token)
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
if err != nil {
return err
}
if err := zrokEdgeSdk.DeleteServicePoliciesDial(env.ZId, shr.Token, a.edge); err != nil {
return err
}
logrus.Infof("removed dial service policy for '%v'", shr.Token)
2023-03-27 17:34:29 +02:00
return nil
}