mirror of
https://github.com/openziti/zrok.git
synced 2025-01-08 23:20:04 +01:00
centralize more edge delete functionality
This commit is contained in:
parent
67bd77d2c3
commit
c2bfa5ea09
@ -1,18 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_management_api_client/edge_router_policy"
|
||||
identity_edge "github.com/openziti/edge/rest_management_api_client/identity"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
type disableHandler struct {
|
||||
@ -44,11 +38,11 @@ func (self *disableHandler) Handle(params identity.DisableParams, principal *res
|
||||
logrus.Errorf("error getting edge client: %v", err)
|
||||
return identity.NewDisableInternalServerError()
|
||||
}
|
||||
if err := self.deleteEdgeRouterPolicy(params.Body.Identity, edge); err != nil {
|
||||
if err := deleteEdgeRouterPolicy(params.Body.Identity, edge); err != nil {
|
||||
logrus.Errorf("error deleting edge router policy: %v", err)
|
||||
return identity.NewDisableInternalServerError()
|
||||
}
|
||||
if err := self.deleteIdentity(params.Body.Identity, edge); err != nil {
|
||||
if err := deleteIdentity(params.Body.Identity, edge); err != nil {
|
||||
logrus.Errorf("error deleting identity: %v", err)
|
||||
return identity.NewDisableInternalServerError()
|
||||
}
|
||||
@ -71,52 +65,6 @@ func (self *disableHandler) checkZitiIdentity(id string, principal *rest_model_z
|
||||
return -1, errors.Errorf("no such environment '%v'", id)
|
||||
}
|
||||
|
||||
func (self *disableHandler) deleteEdgeRouterPolicy(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("name=\"zrok-%v\"", id)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &edge_router_policy.ListEdgeRouterPoliciesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
Context: context.Background(),
|
||||
}
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.EdgeRouterPolicy.ListEdgeRouterPolicies(listReq, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(listResp.Payload.Data) == 1 {
|
||||
erpId := *(listResp.Payload.Data[0].ID)
|
||||
req := &edge_router_policy.DeleteEdgeRouterPolicyParams{
|
||||
ID: erpId,
|
||||
Context: context.Background(),
|
||||
}
|
||||
_, err := edge.EdgeRouterPolicy.DeleteEdgeRouterPolicy(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted edge router policy '%v'", erpId)
|
||||
} else {
|
||||
logrus.Infof("found '%d' edge router policies, expected 1", len(listResp.Payload.Data))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *disableHandler) deleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &identity_edge.DeleteIdentityParams{
|
||||
ID: id,
|
||||
Context: context.Background(),
|
||||
}
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.Identity.DeleteIdentity(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted identity '%v'", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *disableHandler) removeEnvironment(envId int, tx *sqlx.Tx) error {
|
||||
if err := str.DeleteEnvironment(envId, tx); err != nil {
|
||||
return errors.Wrapf(err, "error deleting environment '%d'", envId)
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_management_api_client/config"
|
||||
"github.com/openziti/edge/rest_management_api_client/edge_router_policy"
|
||||
identity_edge "github.com/openziti/edge/rest_management_api_client/identity"
|
||||
"github.com/openziti/edge/rest_management_api_client/service"
|
||||
"github.com/openziti/edge/rest_management_api_client/service_edge_router_policy"
|
||||
"github.com/openziti/edge/rest_management_api_client/service_policy"
|
||||
@ -85,20 +87,6 @@ func deleteServicePolicy(filter string, edge *rest_management_api_client.ZitiEdg
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteService(svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &service.DeleteServiceParams{
|
||||
ID: svcId,
|
||||
Context: context.Background(),
|
||||
}
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.Service.DeleteService(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted service '%v'", svcId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("name=\"%v\"", svcName)
|
||||
limit := int64(0)
|
||||
@ -128,3 +116,63 @@ func deleteConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManag
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteService(svcId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &service.DeleteServiceParams{
|
||||
ID: svcId,
|
||||
Context: context.Background(),
|
||||
}
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.Service.DeleteService(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted service '%v'", svcId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteEdgeRouterPolicy(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("name=\"zrok-%v\"", id)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &edge_router_policy.ListEdgeRouterPoliciesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
Context: context.Background(),
|
||||
}
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.EdgeRouterPolicy.ListEdgeRouterPolicies(listReq, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(listResp.Payload.Data) == 1 {
|
||||
erpId := *(listResp.Payload.Data[0].ID)
|
||||
req := &edge_router_policy.DeleteEdgeRouterPolicyParams{
|
||||
ID: erpId,
|
||||
Context: context.Background(),
|
||||
}
|
||||
_, err := edge.EdgeRouterPolicy.DeleteEdgeRouterPolicy(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted edge router policy '%v'", erpId)
|
||||
} else {
|
||||
logrus.Infof("found '%d' edge router policies, expected 1", len(listResp.Payload.Data))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &identity_edge.DeleteIdentityParams{
|
||||
ID: id,
|
||||
Context: context.Background(),
|
||||
}
|
||||
req.SetTimeout(30 * time.Second)
|
||||
_, err := edge.Identity.DeleteIdentity(req, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("deleted identity '%v'", id)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user