code maintenance; lint removal

This commit is contained in:
Michael Quigley 2022-11-08 15:28:13 -05:00
parent bfdb3a1bd3
commit 84af5be304
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 24 additions and 24 deletions

View File

@ -27,7 +27,7 @@ func newTunnelHandler() *tunnelHandler {
return &tunnelHandler{} return &tunnelHandler{}
} }
func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_model_zrok.Principal) middleware.Responder { func (h *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin() tx, err := str.Begin()
if err != nil { if err != nil {
logrus.Errorf("error starting transaction: %v", err) logrus.Errorf("error starting transaction: %v", err)
@ -66,32 +66,32 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
cfgId, err := self.createConfig(envZId, svcName, params, edge) cfgId, err := h.createConfig(envZId, svcName, params, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
svcZId, err := self.createService(envZId, svcName, cfgId, edge) svcZId, err := h.createService(envZId, svcName, cfgId, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
if err := self.createServicePolicyBind(envZId, svcName, svcZId, envZId, edge); err != nil { if err := h.createServicePolicyBind(envZId, svcName, svcZId, envZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
if err := self.createServicePolicyDial(envZId, svcName, svcZId, edge); err != nil { if err := h.createServicePolicyDial(envZId, svcName, svcZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
if err := self.createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil { if err := h.createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError() return tunnel.NewTunnelInternalServerError()
} }
logrus.Debugf("allocated service '%v'", svcName) logrus.Debugf("allocated service '%v'", svcName)
frontendUrl := self.proxyUrl(svcName) frontendUrl := h.proxyUrl(svcName)
sid, err := str.CreateService(envId, &store.Service{ sid, err := str.CreateService(envId, &store.Service{
ZId: svcZId, ZId: svcZId,
Name: svcName, Name: svcName,
@ -115,7 +115,7 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
}) })
} }
func (self *tunnelHandler) createConfig(envZId, svcName string, params tunnel.TunnelParams, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) { func (h *tunnelHandler) createConfig(envZId, svcName string, params tunnel.TunnelParams, 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
@ -133,7 +133,7 @@ func (self *tunnelHandler) createConfig(envZId, svcName string, params tunnel.Tu
ConfigTypeID: &zrokProxyConfigId, ConfigTypeID: &zrokProxyConfigId,
Data: cfg, Data: cfg,
Name: &svcName, Name: &svcName,
Tags: self.zrokTags(svcName), Tags: h.zrokTags(svcName),
} }
cfgReq := &config.CreateConfigParams{ cfgReq := &config.CreateConfigParams{
Config: cfgCrt, Config: cfgCrt,
@ -148,14 +148,14 @@ func (self *tunnelHandler) createConfig(envZId, svcName string, params tunnel.Tu
return cfgResp.Payload.Data.ID, nil return cfgResp.Payload.Data.ID, nil
} }
func (self *tunnelHandler) createService(envZId, svcName, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) { func (h *tunnelHandler) 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: self.zrokTags(svcName), Tags: h.zrokTags(svcName),
} }
req := &service.CreateServiceParams{ req := &service.CreateServiceParams{
Service: svc, Service: svc,
@ -170,11 +170,11 @@ func (self *tunnelHandler) createService(envZId, svcName, cfgId string, edge *re
return resp.Payload.Data.ID, nil return resp.Payload.Data.ID, nil
} }
func (self *tunnelHandler) createServicePolicyBind(envZId, svcName, svcZId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (h *tunnelHandler) 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)
postureCheckRoles := []string{} var postureCheckRoles []string
serviceRoles := []string{fmt.Sprintf("@%v", svcZId)} serviceRoles := []string{fmt.Sprintf("@%v", svcZId)}
dialBind := rest_model.DialBindBind dialBind := rest_model.DialBindBind
svcp := &rest_model.ServicePolicyCreate{ svcp := &rest_model.ServicePolicyCreate{
@ -184,7 +184,7 @@ func (self *tunnelHandler) createServicePolicyBind(envZId, svcName, svcZId, envI
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Type: &dialBind, Type: &dialBind,
Tags: self.zrokTags(svcName), Tags: h.zrokTags(svcName),
} }
req := &service_policy.CreateServicePolicyParams{ req := &service_policy.CreateServicePolicyParams{
Policy: svcp, Policy: svcp,
@ -199,14 +199,14 @@ func (self *tunnelHandler) createServicePolicyBind(envZId, svcName, svcZId, envI
return nil return nil
} }
func (self *tunnelHandler) createServicePolicyDial(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (h *tunnelHandler) 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)
logrus.Infof("added proxy identity role '%v'", proxyIdentity) logrus.Infof("added proxy identity role '%v'", proxyIdentity)
} }
name := fmt.Sprintf("%v-dial", svcName) name := fmt.Sprintf("%v-dial", svcName)
postureCheckRoles := []string{} var postureCheckRoles []string
semantic := rest_model.SemanticAllOf semantic := rest_model.SemanticAllOf
serviceRoles := []string{fmt.Sprintf("@%v", svcZId)} serviceRoles := []string{fmt.Sprintf("@%v", svcZId)}
dialBind := rest_model.DialBindDial dialBind := rest_model.DialBindDial
@ -217,7 +217,7 @@ func (self *tunnelHandler) createServicePolicyDial(envZId, svcName, svcZId strin
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Type: &dialBind, Type: &dialBind,
Tags: self.zrokTags(svcName), Tags: h.zrokTags(svcName),
} }
req := &service_policy.CreateServicePolicyParams{ req := &service_policy.CreateServicePolicyParams{
Policy: svcp, Policy: svcp,
@ -232,7 +232,7 @@ func (self *tunnelHandler) createServicePolicyDial(envZId, svcName, svcZId strin
return nil return nil
} }
func (self *tunnelHandler) createServiceEdgeRouterPolicy(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error { func (h *tunnelHandler) 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)}
@ -241,7 +241,7 @@ func (self *tunnelHandler) createServiceEdgeRouterPolicy(envZId, svcName, svcZId
Name: &svcName, Name: &svcName,
Semantic: &semantic, Semantic: &semantic,
ServiceRoles: serviceRoles, ServiceRoles: serviceRoles,
Tags: self.zrokTags(svcName), Tags: h.zrokTags(svcName),
} }
serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{ serpParams := &service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{
Policy: serp, Policy: serp,
@ -256,11 +256,11 @@ func (self *tunnelHandler) createServiceEdgeRouterPolicy(envZId, svcName, svcZId
return nil return nil
} }
func (self *tunnelHandler) proxyUrl(svcName string) string { func (h *tunnelHandler) proxyUrl(svcName string) string {
return strings.Replace(cfg.Proxy.UrlTemplate, "{svcName}", svcName, -1) return strings.Replace(cfg.Proxy.UrlTemplate, "{svcName}", svcName, -1)
} }
func (self *tunnelHandler) zrokTags(svcName string) *rest_model.Tags { func (h *tunnelHandler) 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

@ -21,7 +21,7 @@ func newUntunnelHandler() *untunnelHandler {
return &untunnelHandler{} return &untunnelHandler{}
} }
func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *rest_model_zrok.Principal) middleware.Responder { func (h *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *rest_model_zrok.Principal) middleware.Responder {
tx, err := str.Begin() tx, err := str.Begin()
if err != nil { if err != nil {
logrus.Errorf("error starting transaction: %v", err) logrus.Errorf("error starting transaction: %v", err)
@ -35,7 +35,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
return tunnel.NewUntunnelInternalServerError() return tunnel.NewUntunnelInternalServerError()
} }
svcName := params.Body.SvcName svcName := params.Body.SvcName
svcZId, err := self.findServiceZId(svcName, edge) svcZId, err := h.findServiceZId(svcName, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewUntunnelInternalServerError() return tunnel.NewUntunnelInternalServerError()
@ -111,7 +111,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
return tunnel.NewUntunnelOK() return tunnel.NewUntunnelOK()
} }
func (_ *untunnelHandler) findServiceZId(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) { func (h *untunnelHandler) findServiceZId(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
filter := fmt.Sprintf("name=\"%v\"", svcName) filter := fmt.Sprintf("name=\"%v\"", svcName)
limit := int64(1) limit := int64(1)
offset := int64(0) offset := int64(0)