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/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
|
2023-06-05 22:01:04 +02:00
|
|
|
zCfg *zrokEdgeSdk.Config
|
2023-03-27 17:34:29 +02:00
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
func newShareLimitAction(str *store.Store, zCfg *zrokEdgeSdk.Config) *shareLimitAction {
|
|
|
|
return &shareLimitAction{str, zCfg}
|
2023-03-27 17:34:29 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 20:01:31 +02:00
|
|
|
func (a *shareLimitAction) HandleShare(shr *store.Share, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
|
|
|
logrus.Infof("limiting '%v'", shr.Token)
|
2023-03-27 19:51:48 +02:00
|
|
|
|
2023-03-27 20:01:31 +02:00
|
|
|
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
|
2023-03-27 19:51:48 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-06-05 22:01:04 +02:00
|
|
|
edge, err := zrokEdgeSdk.Client(a.zCfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := zrokEdgeSdk.DeleteServicePoliciesDial(env.ZId, shr.Token, edge); err != nil {
|
2023-03-27 19:51:48 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-03-27 20:01:31 +02:00
|
|
|
logrus.Infof("removed dial service policy for '%v'", shr.Token)
|
2023-03-27 19:51:48 +02:00
|
|
|
|
2023-03-27 17:34:29 +02:00
|
|
|
return nil
|
|
|
|
}
|