streamlined unshare impl (#99)

This commit is contained in:
Michael Quigley 2022-11-22 14:24:41 -05:00
parent ff3f623a74
commit 49987df381
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 22 additions and 40 deletions

View File

@ -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
}

View File

@ -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
}