mirror of
https://github.com/openziti/zrok.git
synced 2025-01-08 15:10:01 +01:00
streamlined unshare impl (#99)
This commit is contained in:
parent
ff3f623a74
commit
49987df381
@ -75,15 +75,9 @@ func (h *unshareHandler) Handle(params service.UnshareParams, principal *rest_mo
|
||||
return service.NewUnshareInternalServerError()
|
||||
}
|
||||
|
||||
switch ssvc.ShareMode {
|
||||
case "public":
|
||||
if err := newPublicResourceDeallocator().Handle(senv, ssvc, svcName, svcZId, edge); err != nil {
|
||||
logrus.Errorf("error unsharing ziti resources for '%v': %v", ssvc, err)
|
||||
return service.NewUnshareInternalServerError()
|
||||
}
|
||||
|
||||
default:
|
||||
logrus.Errorf("unknown share mode '%v'", ssvc.ShareMode)
|
||||
// single tag-based service deallocator; should work regardless of sharing mode
|
||||
if err := h.deallocateResources(senv, ssvc, svcName, svcZId, edge); err != nil {
|
||||
logrus.Errorf("error unsharing ziti resources for '%v': %v", ssvc, err)
|
||||
return service.NewUnshareInternalServerError()
|
||||
}
|
||||
|
||||
@ -121,3 +115,22 @@ func (h *unshareHandler) findServiceZId(svcName string, edge *rest_management_ap
|
||||
}
|
||||
return "", errors.Errorf("service '%v' not found", svcName)
|
||||
}
|
||||
|
||||
func (h *unshareHandler) deallocateResources(senv *store.Environment, ssvc *store.Service, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
if err := deleteServiceEdgeRouterPolicy(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteServicePolicyDial(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteServicePolicyBind(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteConfig(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteService(senv.ZId, svcZId, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
)
|
||||
|
||||
type publicResourceDeallocator struct{}
|
||||
|
||||
func newPublicResourceDeallocator() *publicResourceDeallocator {
|
||||
return &publicResourceDeallocator{}
|
||||
}
|
||||
|
||||
func (d *publicResourceDeallocator) Handle(senv *store.Environment, ssvc *store.Service, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
if err := deleteServiceEdgeRouterPolicy(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteServicePolicyDial(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteServicePolicyBind(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteConfig(senv.ZId, svcName, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deleteService(senv.ZId, svcZId, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user