mirror of
https://github.com/openziti/zrok.git
synced 2024-11-26 18:13:52 +01:00
share, environment, and account relax actions all support private shares in addition to public shares; consolidated relax code (#278)
This commit is contained in:
parent
540e3ffa74
commit
3c92b9a8d0
@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -33,25 +32,14 @@ func (a *accountRelaxAction) HandleAccount(acct *store.Account, _, _ int64, _ *B
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, shr := range shrs {
|
for _, shr := range shrs {
|
||||||
if !shr.Deleted {
|
switch shr.ShareMode {
|
||||||
if shr.ShareMode == "public" {
|
case "public":
|
||||||
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
|
if err := relaxPublicShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return errors.Wrap(err, "error finding environment")
|
|
||||||
}
|
}
|
||||||
|
case "private":
|
||||||
fe, err := a.str.FindFrontendPubliclyNamed(*shr.FrontendSelection, trx)
|
if err := relaxPrivateShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return errors.Wrapf(err, "error finding frontend name '%v' for '%v'", *shr.FrontendSelection, shr.Token)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+shr.ZId+"-dial", shr.ZId, []string{fe.ZId}, zrokEdgeSdk.ZrokShareTags(shr.Token).SubTags, a.edge); err != nil {
|
|
||||||
return errors.Wrapf(err, "error creating dial service policy for '%v'", shr.Token)
|
|
||||||
}
|
|
||||||
logrus.Infof("added dial service policy for '%v'", shr.Token)
|
|
||||||
|
|
||||||
} else if shr.ShareMode == "private" {
|
|
||||||
return errors.New("share relax for private share not implemented")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -28,24 +27,15 @@ func (a *environmentRelaxAction) HandleEnvironment(env *store.Environment, rxByt
|
|||||||
|
|
||||||
for _, shr := range shrs {
|
for _, shr := range shrs {
|
||||||
if !shr.Deleted {
|
if !shr.Deleted {
|
||||||
if shr.ShareMode == "public" {
|
switch shr.ShareMode {
|
||||||
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
|
case "public":
|
||||||
if err != nil {
|
if err := relaxPublicShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
return errors.Wrap(err, "error finding environment")
|
return err
|
||||||
}
|
}
|
||||||
|
case "private":
|
||||||
fe, err := a.str.FindFrontendPubliclyNamed(*shr.FrontendSelection, trx)
|
if err := relaxPrivateShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return errors.Wrapf(err, "error finding frontend name '%v' for '%v'", *shr.FrontendSelection, shr.Token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+shr.ZId+"-dial", shr.ZId, []string{fe.ZId}, zrokEdgeSdk.ZrokShareTags(shr.Token).SubTags, a.edge); err != nil {
|
|
||||||
return errors.Wrapf(err, "error creating dial service policy for '%v'", shr.Token)
|
|
||||||
}
|
|
||||||
logrus.Infof("added dial service policy for '%v'", shr.Token)
|
|
||||||
|
|
||||||
} else if shr.ShareMode == "private" {
|
|
||||||
return errors.New("share relax for private share not implemented")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,30 +18,66 @@ func newShareRelaxAction(str *store.Store, edge *rest_management_api_client.Ziti
|
|||||||
return &shareRelaxAction{str, edge}
|
return &shareRelaxAction{str, edge}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *shareRelaxAction) HandleShare(shr *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
func (a *shareRelaxAction) HandleShare(shr *store.Share, _, _ int64, _ *BandwidthPerPeriod, trx *sqlx.Tx) error {
|
||||||
logrus.Infof("relaxing '%v'", shr.Token)
|
logrus.Infof("relaxing '%v'", shr.Token)
|
||||||
|
|
||||||
if !shr.Deleted {
|
if !shr.Deleted {
|
||||||
if shr.ShareMode == "public" {
|
switch shr.ShareMode {
|
||||||
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
|
case "public":
|
||||||
if err != nil {
|
if err := relaxPublicShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
return errors.Wrap(err, "error finding environment")
|
return err
|
||||||
}
|
}
|
||||||
|
case "private":
|
||||||
fe, err := a.str.FindFrontendPubliclyNamed(*shr.FrontendSelection, trx)
|
if err := relaxPrivateShare(a.str, a.edge, shr, trx); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return errors.Wrapf(err, "error finding frontend name '%v' for '%v'", *shr.FrontendSelection, shr.Token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+shr.ZId+"-dial", shr.ZId, []string{fe.ZId}, zrokEdgeSdk.ZrokShareTags(shr.Token).SubTags, a.edge); err != nil {
|
|
||||||
return errors.Wrapf(err, "error creating dial service policy for '%v'", shr.Token)
|
|
||||||
}
|
|
||||||
logrus.Infof("added dial service policy for '%v'", shr.Token)
|
|
||||||
|
|
||||||
} else if shr.ShareMode == "private" {
|
|
||||||
return errors.New("share relax for private share not implemented")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func relaxPublicShare(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement, shr *store.Share, trx *sqlx.Tx) error {
|
||||||
|
env, err := str.GetEnvironment(shr.EnvironmentId, trx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error finding environment")
|
||||||
|
}
|
||||||
|
|
||||||
|
fe, err := str.FindFrontendPubliclyNamed(*shr.FrontendSelection, trx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error finding frontend name '%v' for '%v'", *shr.FrontendSelection, shr.Token)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+shr.ZId+"-dial", shr.ZId, []string{fe.ZId}, zrokEdgeSdk.ZrokShareTags(shr.Token).SubTags, edge); err != nil {
|
||||||
|
return errors.Wrapf(err, "error creating dial service policy for '%v'", shr.Token)
|
||||||
|
}
|
||||||
|
logrus.Infof("added dial service policy for '%v'", shr.Token)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func relaxPrivateShare(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement, shr *store.Share, trx *sqlx.Tx) error {
|
||||||
|
fes, err := str.FindFrontendsForPrivateShare(shr.Id, trx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error finding frontends for share '%v'", shr.Token)
|
||||||
|
}
|
||||||
|
for _, fe := range fes {
|
||||||
|
if fe.EnvironmentId != nil {
|
||||||
|
env, err := str.GetEnvironment(*fe.EnvironmentId, trx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "error getting environment for frontend '%v'", fe.Token)
|
||||||
|
}
|
||||||
|
|
||||||
|
addlTags := map[string]interface{}{
|
||||||
|
"zrokEnvironmentZId": env.ZId,
|
||||||
|
"zrokFrontendToken": fe.Token,
|
||||||
|
"zrokShareToken": shr.Token,
|
||||||
|
}
|
||||||
|
if err := zrokEdgeSdk.CreateServicePolicyDial(env.ZId+"-"+shr.ZId+"-dial", shr.ZId, []string{env.ZId}, addlTags, edge); err != nil {
|
||||||
|
return errors.Wrapf(err, "unable to create dial policy for frontend '%v'", fe.Token)
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("added dial service policy for share '%v' to private frontend '%v'", shr.Token, fe.Token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user