From c9a96aa4738d98bbd0c6724336300b6566fb2eb5 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Thu, 15 Dec 2022 11:50:30 -0500 Subject: [PATCH] smol lint and polish on zrokEdgeSdk (#112) --- controller/sharePrivate.go | 2 +- controller/sharePublic.go | 2 +- controller/zrokEdgeSdk/serp.go | 2 +- controller/zrokEdgeSdk/service.go | 3 +-- controller/zrokEdgeSdk/sp.go | 20 ++++++++++---------- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/controller/sharePrivate.go b/controller/sharePrivate.go index dafeebc4..afc66943 100644 --- a/controller/sharePrivate.go +++ b/controller/sharePrivate.go @@ -32,7 +32,7 @@ func (a *privateResourceAllocator) allocate(envZId, svcToken string, params serv return "", nil, err } - if err := zrokEdgeSdk.CreateServiceEdgeRouterPolicyForShare(envZId, svcToken, svcZId, edge); err != nil { + if err := zrokEdgeSdk.CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil { return "", nil, err } diff --git a/controller/sharePublic.go b/controller/sharePublic.go index d5999278..2cd3c835 100644 --- a/controller/sharePublic.go +++ b/controller/sharePublic.go @@ -36,7 +36,7 @@ func (a *publicResourceAllocator) allocate(envZId, svcToken string, frontendZIds return "", nil, err } - if err := zrokEdgeSdk.CreateServiceEdgeRouterPolicyForShare(envZId, svcToken, svcZId, edge); err != nil { + if err := zrokEdgeSdk.CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil { return "", nil, err } diff --git a/controller/zrokEdgeSdk/serp.go b/controller/zrokEdgeSdk/serp.go index 0138c50e..bf3e6966 100644 --- a/controller/zrokEdgeSdk/serp.go +++ b/controller/zrokEdgeSdk/serp.go @@ -11,7 +11,7 @@ import ( "time" ) -func CreateServiceEdgeRouterPolicyForShare(envZId, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { +func CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { serpZId, err := CreateServiceEdgeRouterPolicy(svcToken, svcZId, ZrokServiceTags(svcToken).SubTags, edge) if err != nil { return err diff --git a/controller/zrokEdgeSdk/service.go b/controller/zrokEdgeSdk/service.go index e152b661..46a457d4 100644 --- a/controller/zrokEdgeSdk/service.go +++ b/controller/zrokEdgeSdk/service.go @@ -11,8 +11,7 @@ import ( ) func CreateShareService(envZId, svcToken, cfgZId string, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, err error) { - cfgZIds := []string{cfgZId} - svcZId, err = CreateService(svcToken, cfgZIds, map[string]interface{}{"zrokServiceToken": svcToken}, edge) + svcZId, err = CreateService(svcToken, []string{cfgZId}, map[string]interface{}{"zrokServiceToken": svcToken}, edge) if err != nil { return "", errors.Wrapf(err, "error creating service '%v'", svcToken) } diff --git a/controller/zrokEdgeSdk/sp.go b/controller/zrokEdgeSdk/sp.go index a7f0ac7e..1d2396b0 100644 --- a/controller/zrokEdgeSdk/sp.go +++ b/controller/zrokEdgeSdk/sp.go @@ -12,15 +12,15 @@ import ( ) const ( - ServicePolicyDial = 1 - ServicePolicyBind = 2 + servicePolicyDial = 1 + servicePolicyBind = 2 ) func CreateServicePolicyBind(name, svcZId, bindZId string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) error { semantic := rest_model.SemanticAllOf identityRoles := []string{"@" + bindZId} serviceRoles := []string{"@" + svcZId} - spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, ServicePolicyBind, edge) + spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, servicePolicyBind, edge) if err != nil { return errors.Wrapf(err, "error creating bind service policy for service '%v' for identity '%v'", svcZId, bindZId) } @@ -34,8 +34,8 @@ func CreateServicePolicyDial(name, svcZId string, dialZIds []string, addlTags ma for _, zId := range dialZIds { identityRoles = append(identityRoles, "@"+zId) } - serviceRoles := []string{"@"+svcZId} - spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, ServicePolicyDial, edge) + serviceRoles := []string{"@" + svcZId} + spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, servicePolicyDial, edge) if err != nil { return errors.Wrapf(err, "error creating dial service policy for service '%v' for identities '%v'", svcZId, dialZIds) } @@ -46,9 +46,9 @@ func CreateServicePolicyDial(name, svcZId string, dialZIds []string, addlTags ma func createServicePolicy(name string, semantic rest_model.Semantic, identityRoles, serviceRoles []string, addlTags map[string]interface{}, dialBind int, edge *rest_management_api_client.ZitiEdgeManagement) (spZId string, err error) { var dialBindType rest_model.DialBind switch dialBind { - case ServicePolicyBind: + case servicePolicyBind: dialBindType = rest_model.DialBindBind - case ServicePolicyDial: + case servicePolicyDial: dialBindType = rest_model.DialBindDial default: return "", errors.Errorf("invalid dial bind type") @@ -65,7 +65,7 @@ func createServicePolicy(name string, semantic rest_model.Semantic, identityRole } req := &service_policy.CreateServicePolicyParams{ - Policy: spc, + Policy: spc, Context: context.Background(), } req.SetTimeout(30 * time.Second) @@ -79,11 +79,11 @@ func createServicePolicy(name string, semantic rest_model.Semantic, identityRole } func DeleteServicePolicyBind(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error { - return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, ServicePolicyBind), edge) + return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, servicePolicyBind), edge) } func DeleteServicePolicyDial(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error { - return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, ServicePolicyDial), edge) + return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, servicePolicyDial), edge) } func DeleteServicePolicy(envZId, filter string, edge *rest_management_api_client.ZitiEdgeManagement) error {