remove frontend service policies (#171)

This commit is contained in:
Michael Quigley 2023-01-19 15:23:38 -05:00
parent 8bf060f71d
commit 1c77fdc065
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -1,6 +1,7 @@
package controller
import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/jmoiron/sqlx"
"github.com/openziti/edge/rest_management_api_client"
@ -44,6 +45,10 @@ func (h *disableHandler) Handle(params environment.DisableParams, principal *res
logrus.Errorf("error removing shares for environment: %v", err)
return environment.NewDisableInternalServerError()
}
if err := h.removeFrontendsForEnvironment(envId, tx, edge); err != nil {
logrus.Errorf("error removing frontends for environment: %v", err)
return environment.NewDisableInternalServerError()
}
if err := h.removeEnvironment(envId, tx); err != nil {
logrus.Errorf("error removing environment: %v", err)
return environment.NewDisableInternalServerError()
@ -107,6 +112,23 @@ func (h *disableHandler) removeSharesForEnvironment(envId int, tx *sqlx.Tx, edge
return nil
}
func (h *disableHandler) removeFrontendsForEnvironment(envId int, tx *sqlx.Tx, edge *rest_management_api_client.ZitiEdgeManagement) error {
env, err := str.GetEnvironment(envId, tx)
if err != nil {
return err
}
fes, err := str.FindFrontendsForEnvironment(envId, tx)
if err != nil {
return err
}
for _, fe := range fes {
if err := zrokEdgeSdk.DeleteServicePolicy(env.ZId, fmt.Sprintf("tags.zrokFrontendToken=\"%v\" and type=1", fe.Token), edge); err != nil {
logrus.Errorf("error removing frontend access for '%v': %v", fe.Token, err)
}
}
return nil
}
func (h *disableHandler) removeEnvironment(envId int, tx *sqlx.Tx) error {
shrs, err := str.FindSharesForEnvironment(envId, tx)
if err != nil {