add trx to action interfaces; implement limit and relax for share (#276)

This commit is contained in:
Michael Quigley
2023-03-27 13:51:48 -04:00
committed by Kenneth Bingham
parent bf48ddec76
commit 427ef7e3f9
12 changed files with 72 additions and 22 deletions

View File

@ -1,8 +1,11 @@
package limits
import (
"github.com/jmoiron/sqlx"
"github.com/openziti/edge/rest_management_api_client"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -15,7 +18,28 @@ func newShareRelaxAction(str *store.Store, edge *rest_management_api_client.Ziti
return &shareRelaxAction{str, edge}
}
func (a *shareRelaxAction) HandleShare(s *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod) error {
func (a *shareRelaxAction) HandleShare(s *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("relaxing '%v'", s.Token)
if s.ShareMode == "public" {
env, err := a.str.GetEnvironment(s.EnvironmentId, trx)
if err != nil {
return errors.Wrap(err, "error finding environment")
}
fe, err := a.str.FindFrontendPubliclyNamed(*s.FrontendSelection, trx)
if err != nil {
return errors.Wrapf(err, "error finding frontend name '%v' for '%v'", *s.FrontendSelection, s.Token)
}
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+s.ZId+"-dial", s.ZId, []string{fe.ZId}, zrokEdgeSdk.ZrokShareTags(s.Token).SubTags, a.edge); err != nil {
return errors.Wrapf(err, "error creating dial service policy for '%v'", s.Token)
}
logrus.Infof("added dial service policy for '%v'", s.Token)
} else if s.ShareMode == "private" {
return errors.New("share relax for private share not implemented")
}
return nil
}