This commit is contained in:
Michael Quigley 2022-11-22 11:39:00 -05:00
parent c7d8395b89
commit b54876fcb6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 26 additions and 26 deletions

View File

@ -74,8 +74,8 @@ func (h *shareHandler) Handle(params service.ShareParams, principal *rest_model_
sid, err := str.CreateService(envId, &store.Service{ sid, err := str.CreateService(envId, &store.Service{
ZId: svcZId, ZId: svcZId,
Name: svcName, Name: svcName,
ShareMode: "public", ShareMode: params.Body.ShareMode,
BackendMode: "proxy", BackendMode: params.Body.BackendMode,
FrontendEndpoint: &frontendEndpoints[0], FrontendEndpoint: &frontendEndpoints[0],
BackendProxyEndpoint: &params.Body.BackendProxyEndpoint, BackendProxyEndpoint: &params.Body.BackendProxyEndpoint,
}, tx) }, tx)

View File

@ -24,29 +24,29 @@ func newPublicResourceAllocator() *publicResourceAllocator {
return &publicResourceAllocator{} return &publicResourceAllocator{}
} }
func (h *publicResourceAllocator) Allocate(envZId, svcName string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) { func (a *publicResourceAllocator) Allocate(envZId, svcName string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) {
cfgId, err := h.createConfig(envZId, svcName, params, edge) cfgId, err := a.createConfig(envZId, svcName, params, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
svcZId, err = h.createService(envZId, svcName, cfgId, edge) svcZId, err = a.createService(envZId, svcName, cfgId, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
if err := h.createServicePolicyBind(envZId, svcName, svcZId, envZId, edge); err != nil { if err := a.createServicePolicyBind(envZId, svcName, svcZId, envZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
} }
if err := h.createServicePolicyDial(envZId, svcName, svcZId, edge); err != nil { if err := a.createServicePolicyDial(envZId, svcName, svcZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
} }
if err := h.createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil { if err := a.createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
} }
frontendUrl := h.proxyUrl(svcName) frontendUrl := a.proxyUrl(svcName)
return svcZId, []string{frontendUrl}, nil return svcZId, []string{frontendUrl}, nil
} }
func (h *publicResourceAllocator) createConfig(envZId, svcName string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) { func (a *publicResourceAllocator) createConfig(envZId, svcName string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) {
authScheme, err := model.ParseAuthScheme(params.Body.AuthScheme) authScheme, err := model.ParseAuthScheme(params.Body.AuthScheme)
if err != nil { if err != nil {
return "", err return "", err
@ -64,7 +64,7 @@ func (h *publicResourceAllocator) createConfig(envZId, svcName string, params se
ConfigTypeID: &zrokProxyConfigId, ConfigTypeID: &zrokProxyConfigId,
Data: cfg, Data: cfg,
Name: &svcName, Name: &svcName,
Tags: h.zrokTags(svcName), Tags: a.zrokTags(svcName),
} }
cfgReq := &config.CreateConfigParams{ cfgReq := &config.CreateConfigParams{
Config: cfgCrt, Config: cfgCrt,
@ -79,14 +79,14 @@ func (h *publicResourceAllocator) createConfig(envZId, svcName string, params se
return cfgResp.Payload.Data.ID, nil return cfgResp.Payload.Data.ID, nil
} }
func (h *publicResourceAllocator) createService(envZId, svcName, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) { func (a *publicResourceAllocator) createService(envZId, svcName, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) {
configs := []string{cfgId} configs := []string{cfgId}
encryptionRequired := true encryptionRequired := true
svc := &rest_model.ServiceCreate{ svc := &rest_model.ServiceCreate{
Configs: configs, Configs: configs,
EncryptionRequired: &encryptionRequired, EncryptionRequired: &encryptionRequired,
Name: &svcName, Name: &svcName,
Tags: h.zrokTags(svcName), Tags: a.zrokTags(svcName),
} }
req := &edge_service.CreateServiceParams{ req := &edge_service.CreateServiceParams{
Service: svc, Service: svc,
@ -101,7 +101,7 @@ func (h *publicResourceAllocator) createService(envZId, svcName, cfgId string, e
return resp.Payload.Data.ID, nil return resp.Payload.Data.ID, nil
} }
func (h *publicResourceAllocator) createServicePolicyBind(envZId, svcName, svcZId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (a *publicResourceAllocator) createServicePolicyBind(envZId, svcName, svcZId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
semantic := rest_model.SemanticAllOf semantic := rest_model.SemanticAllOf
identityRoles := []string{fmt.Sprintf("@%v", envId)} identityRoles := []string{fmt.Sprintf("@%v", envId)}
name := fmt.Sprintf("%v-backend", svcName) name := fmt.Sprintf("%v-backend", svcName)
@ -115,7 +115,7 @@ func (h *publicResourceAllocator) createServicePolicyBind(envZId, svcName, svcZI
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Type: &dialBind, Type: &dialBind,
Tags: h.zrokTags(svcName), Tags: a.zrokTags(svcName),
} }
req := &service_policy.CreateServicePolicyParams{ req := &service_policy.CreateServicePolicyParams{
Policy: svcp, Policy: svcp,
@ -130,7 +130,7 @@ func (h *publicResourceAllocator) createServicePolicyBind(envZId, svcName, svcZI
return nil return nil
} }
func (h *publicResourceAllocator) createServicePolicyDial(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (a *publicResourceAllocator) createServicePolicyDial(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
var identityRoles []string var identityRoles []string
for _, proxyIdentity := range cfg.Proxy.Identities { for _, proxyIdentity := range cfg.Proxy.Identities {
identityRoles = append(identityRoles, "@"+proxyIdentity) identityRoles = append(identityRoles, "@"+proxyIdentity)
@ -148,7 +148,7 @@ func (h *publicResourceAllocator) createServicePolicyDial(envZId, svcName, svcZI
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Type: &dialBind, Type: &dialBind,
Tags: h.zrokTags(svcName), Tags: a.zrokTags(svcName),
} }
req := &service_policy.CreateServicePolicyParams{ req := &service_policy.CreateServicePolicyParams{
Policy: svcp, Policy: svcp,
@ -163,7 +163,7 @@ func (h *publicResourceAllocator) createServicePolicyDial(envZId, svcName, svcZI
return nil return nil
} }
func (h *publicResourceAllocator) createServiceEdgeRouterPolicy(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (a *publicResourceAllocator) createServiceEdgeRouterPolicy(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
edgeRouterRoles := []string{"#all"} edgeRouterRoles := []string{"#all"}
semantic := rest_model.SemanticAllOf semantic := rest_model.SemanticAllOf
serviceRoles := []string{fmt.Sprintf("@%v", svcZId)} serviceRoles := []string{fmt.Sprintf("@%v", svcZId)}
@ -172,7 +172,7 @@ func (h *publicResourceAllocator) createServiceEdgeRouterPolicy(envZId, svcName,
Name: &svcName, Name: &svcName,
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Tags: h.zrokTags(svcName), Tags: a.zrokTags(svcName),
} }
serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{ serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{
Policy: serp, Policy: serp,
@ -187,11 +187,11 @@ func (h *publicResourceAllocator) createServiceEdgeRouterPolicy(envZId, svcName,
return nil return nil
} }
func (h *publicResourceAllocator) proxyUrl(svcName string) string { func (a *publicResourceAllocator) proxyUrl(svcName string) string {
return strings.Replace(cfg.Proxy.UrlTemplate, "{svcName}", svcName, -1) return strings.Replace(cfg.Proxy.UrlTemplate, "{svcName}", svcName, -1)
} }
func (h *publicResourceAllocator) zrokTags(svcName string) *rest_model.Tags { func (a *publicResourceAllocator) zrokTags(svcName string) *rest_model.Tags {
return &rest_model.Tags{ return &rest_model.Tags{
SubTags: map[string]interface{}{ SubTags: map[string]interface{}{
"zrok": build.String(), "zrok": build.String(),

View File

@ -77,7 +77,7 @@ func (h *unshareHandler) Handle(params service.UnshareParams, principal *rest_mo
switch ssvc.ShareMode { switch ssvc.ShareMode {
case "public": case "public":
if err := newUnsharePublicHandler().Handle(senv, ssvc, svcName, svcZId, edge); err != nil { if err := newPublicResourceDeallocator().Handle(senv, ssvc, svcName, svcZId, edge); err != nil {
logrus.Errorf("error unsharing ziti resources for '%v': %v", ssvc, err) logrus.Errorf("error unsharing ziti resources for '%v': %v", ssvc, err)
return service.NewUnshareInternalServerError() return service.NewUnshareInternalServerError()
} }

View File

@ -5,13 +5,13 @@ import (
"github.com/openziti/edge/rest_management_api_client" "github.com/openziti/edge/rest_management_api_client"
) )
type unsharePublicHandler struct{} type publicResourceDeallocator struct{}
func newUnsharePublicHandler() *unsharePublicHandler { func newPublicResourceDeallocator() *publicResourceDeallocator {
return &unsharePublicHandler{} return &publicResourceDeallocator{}
} }
func (h *unsharePublicHandler) Handle(senv *store.Environment, ssvc *store.Service, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { 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 { if err := deleteServiceEdgeRouterPolicy(senv.ZId, svcName, edge); err != nil {
return err return err
} }