From fd7c8b74a6cc60f45a209d97c57f2a5db2a59d62 Mon Sep 17 00:00:00 2001 From: Jens Alm Date: Wed, 8 Jan 2025 16:46:13 -0500 Subject: [PATCH] Fixed lint issue and general cleanup. --- ziti/cmd/ascode/exporter/exporter.go | 108 ++++++++-------- .../ascode/exporter/exporter_auth_policies.go | 30 ++--- .../exporter_certificate_authorities.go | 14 +-- .../ascode/exporter/exporter_config_types.go | 14 +-- ziti/cmd/ascode/exporter/exporter_configs.go | 18 +-- .../exporter/exporter_edgerouter_policies.go | 14 +-- .../ascode/exporter/exporter_edgerouters.go | 16 +-- .../exporter/exporter_external_jwt_signers.go | 14 +-- .../ascode/exporter/exporter_identities.go | 20 +-- .../exporter/exporter_posture_checks.go | 14 +-- .../exporter_service_edgerouter_policies.go | 14 +-- .../exporter/exporter_service_policies.go | 14 +-- ziti/cmd/ascode/exporter/exporter_services.go | 20 +-- ziti/cmd/ascode/importer/importer.go | 119 +++++++++--------- .../ascode/importer/importer_auth_policies.go | 24 ++-- .../importer_certificate_authorities.go | 16 +-- .../ascode/importer/importer_config_types.go | 18 +-- ziti/cmd/ascode/importer/importer_configs.go | 24 ++-- .../importer/importer_edgerouter_policies.go | 20 +-- .../ascode/importer/importer_edgerouters.go | 22 ++-- .../importer/importer_external_jwt_signers.go | 18 +-- .../ascode/importer/importer_identities.go | 26 ++-- .../ascode/importer/importer_posture_check.go | 18 +-- .../importer_service_edgerouter_policies.go | 20 +-- .../importer/importer_service_policies.go | 20 +-- ziti/cmd/ascode/importer/importer_services.go | 26 ++-- 26 files changed, 340 insertions(+), 341 deletions(-) diff --git a/ziti/cmd/ascode/exporter/exporter.go b/ziti/cmd/ascode/exporter/exporter.go index 7d0fb7979..8ac66c229 100644 --- a/ziti/cmd/ascode/exporter/exporter.go +++ b/ziti/cmd/ascode/exporter/exporter.go @@ -54,8 +54,8 @@ var output Output func NewExportCmd(out io.Writer, errOut io.Writer) *cobra.Command { - d := &Exporter{} - d.loginOpts = edge.LoginOptions{} + exporter := &Exporter{} + exporter.loginOpts = edge.LoginOptions{} cmd := &cobra.Command{ Use: "export [entity]", @@ -64,13 +64,13 @@ func NewExportCmd(out io.Writer, errOut io.Writer) *cobra.Command { "Valid entities are: [all|ca/certificate-authority|identity|edge-router|service|config|config-type|service-policy|edge-router-policy|service-edge-router-policy|external-jwt-signer|auth-policy|posture-check] (default all)", Args: cobra.MinimumNArgs(0), PersistentPreRun: func(cmd *cobra.Command, args []string) { - err := d.Init(out) + err := exporter.Init(out) if err != nil { panic(err) } }, Run: func(cmd *cobra.Command, args []string) { - err := d.Execute(args) + err := exporter.Execute(args) if err != nil { panic(err) } @@ -93,23 +93,23 @@ func NewExportCmd(out io.Writer, errOut io.Writer) *cobra.Command { v.AutomaticEnv() cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVar(&d.ofJson, "json", true, "Output in JSON") - cmd.Flags().BoolVar(&d.ofYaml, "yaml", false, "Output in YAML") + cmd.Flags().BoolVar(&exporter.ofJson, "json", true, "Output in JSON") + cmd.Flags().BoolVar(&exporter.ofYaml, "yaml", false, "Output in YAML") cmd.MarkFlagsMutuallyExclusive("json", "yaml") - cmd.Flags().StringVarP(&d.filename, "output-file", "o", "", "Write output to local file") + cmd.Flags().StringVarP(&exporter.filename, "output-file", "o", "", "Write output to local file") - edge.AddLoginFlags(cmd, &d.loginOpts) - d.loginOpts.Out = out - d.loginOpts.Err = errOut + edge.AddLoginFlags(cmd, &exporter.loginOpts) + exporter.loginOpts.Out = out + exporter.loginOpts.Err = errOut return cmd } -func (d *Exporter) Init(out io.Writer) error { +func (exporter *Exporter) Init(out io.Writer) error { logLvl := logrus.InfoLevel - if d.loginOpts.Verbose { + if exporter.loginOpts.Verbose { logLvl = logrus.DebugLevel } @@ -118,7 +118,7 @@ func (d *Exporter) Init(out io.Writer) error { client, err := mgmt.NewClient() if err != nil { - loginErr := d.loginOpts.Run() + loginErr := exporter.loginOpts.Run() if loginErr != nil { log.Fatal(err) } @@ -127,16 +127,16 @@ func (d *Exporter) Init(out io.Writer) error { log.Fatal(err) } } - d.client = client + exporter.client = client - if d.filename != "" { - o, err := NewOutputToFile(d.loginOpts.Verbose, d.ofJson, d.ofYaml, d.filename, d.loginOpts.Err) + if exporter.filename != "" { + o, err := NewOutputToFile(exporter.loginOpts.Verbose, exporter.ofJson, exporter.ofYaml, exporter.filename, exporter.loginOpts.Err) if err != nil { return err } output = *o } else { - o, err := NewOutputToWriter(d.loginOpts.Verbose, d.ofJson, d.ofYaml, out, d.loginOpts.Err) + o, err := NewOutputToWriter(exporter.loginOpts.Verbose, exporter.ofJson, exporter.ofYaml, out, exporter.loginOpts.Err) if err != nil { return err } @@ -146,109 +146,109 @@ func (d *Exporter) Init(out io.Writer) error { return nil } -func (d *Exporter) Execute(input []string) error { +func (exporter *Exporter) Execute(input []string) error { args := arrayutils.Map(input, strings.ToLower) - d.authPolicyCache = map[string]any{} - d.configCache = map[string]any{} - d.configTypeCache = map[string]any{} - d.externalJwtCache = map[string]any{} + exporter.authPolicyCache = map[string]any{} + exporter.configCache = map[string]any{} + exporter.configTypeCache = map[string]any{} + exporter.externalJwtCache = map[string]any{} result := map[string]interface{}{} - if d.IsCertificateAuthorityExportRequired(args) { + if exporter.IsCertificateAuthorityExportRequired(args) { log.Debug("Processing Certificate Authorities") - cas, err := d.GetCertificateAuthorities() + cas, err := exporter.GetCertificateAuthorities() if err != nil { return err } result["certificateAuthorities"] = cas } - if d.IsIdentityExportRequired(args) { + if exporter.IsIdentityExportRequired(args) { log.Debug("Processing Identities") - identities, err := d.GetIdentities() + identities, err := exporter.GetIdentities() if err != nil { return err } result["identities"] = identities } - if d.IsEdgeRouterExportRequired(args) { + if exporter.IsEdgeRouterExportRequired(args) { log.Debug("Processing Edge Routers") - routers, err := d.GetEdgeRouters() + routers, err := exporter.GetEdgeRouters() if err != nil { return err } result["edgeRouters"] = routers } - if d.IsServiceExportRequired(args) { + if exporter.IsServiceExportRequired(args) { log.Debug("Processing Services") - services, err := d.GetServices() + services, err := exporter.GetServices() if err != nil { return err } result["services"] = services } - if d.IsConfigExportRequired(args) { + if exporter.IsConfigExportRequired(args) { log.Debug("Processing Configs") - configs, err := d.GetConfigs() + configs, err := exporter.GetConfigs() if err != nil { return err } result["configs"] = configs } - if d.IsConfigTypeExportRequired(args) { + if exporter.IsConfigTypeExportRequired(args) { log.Debug("Processing Config Types") - configTypes, err := d.GetConfigTypes() + configTypes, err := exporter.GetConfigTypes() if err != nil { return err } result["configTypes"] = configTypes } - if d.IsServicePolicyExportRequired(args) { + if exporter.IsServicePolicyExportRequired(args) { log.Debug("Processing Service Policies") - servicePolicies, err := d.GetServicePolicies() + servicePolicies, err := exporter.GetServicePolicies() if err != nil { return err } result["servicePolicies"] = servicePolicies } - if d.IsEdgeRouterExportRequired(args) { + if exporter.IsEdgeRouterExportRequired(args) { log.Debug("Processing Edge Router Policies") - routerPolicies, err := d.GetEdgeRouterPolicies() + routerPolicies, err := exporter.GetEdgeRouterPolicies() if err != nil { return err } result["edgeRouterPolicies"] = routerPolicies } - if d.IsServiceEdgeRouterPolicyExportRequired(args) { + if exporter.IsServiceEdgeRouterPolicyExportRequired(args) { log.Debug("Processing Service Edge Router Policies") - serviceRouterPolicies, err := d.GetServiceEdgeRouterPolicies() + serviceRouterPolicies, err := exporter.GetServiceEdgeRouterPolicies() if err != nil { return err } result["serviceEdgeRouterPolicies"] = serviceRouterPolicies } - if d.IsExtJwtSignerExportRequired(args) { + if exporter.IsExtJwtSignerExportRequired(args) { log.Debug("Processing External JWT Signers") - externalJwtSigners, err := d.GetExternalJwtSigners() + externalJwtSigners, err := exporter.GetExternalJwtSigners() if err != nil { return err } result["externalJwtSigners"] = externalJwtSigners } - if d.IsAuthPolicyExportRequired(args) { + if exporter.IsAuthPolicyExportRequired(args) { log.Debug("Processing Auth Policies") - authPolicies, err := d.GetAuthPolicies() + authPolicies, err := exporter.GetAuthPolicies() if err != nil { return err } result["authPolicies"] = authPolicies } - if d.IsPostureCheckExportRequired(args) { + if exporter.IsPostureCheckExportRequired(args) { log.Debug("Processing Posture Checks") - postureChecks, err := d.GetPostureChecks() + postureChecks, err := exporter.GetPostureChecks() if err != nil { return err } @@ -261,8 +261,8 @@ func (d *Exporter) Execute(input []string) error { if err != nil { return err } - if d.file != nil { - err := d.file.Close() + if exporter.file != nil { + err := exporter.file.Close() if err != nil { return err } @@ -275,7 +275,7 @@ type ClientCount func() (int64, error) type ClientList func(offset *int64, limit *int64) ([]interface{}, error) type EntityProcessor func(item interface{}) (map[string]interface{}, error) -func (d *Exporter) getEntities(entityName string, count ClientCount, list ClientList, processor EntityProcessor) ([]map[string]interface{}, error) { +func (exporter *Exporter) getEntities(entityName string, count ClientCount, list ClientList, processor EntityProcessor) ([]map[string]interface{}, error) { totalCount, countErr := count() if countErr != nil { @@ -289,7 +289,7 @@ func (d *Exporter) getEntities(entityName string, count ClientCount, list Client more := true for more { resp, err := list(&offset, &limit) - _, _ = internal.FPrintfReusingLine(d.loginOpts.Err, "Reading %d/%d %s", offset, totalCount, entityName) + _, _ = internal.FPrintfReusingLine(exporter.loginOpts.Err, "Reading %d/%d %s", offset, totalCount, entityName) if err != nil { return nil, errors.Join(errors.New("error reading "+entityName), err) } @@ -308,13 +308,13 @@ func (d *Exporter) getEntities(entityName string, count ClientCount, list Client offset += limit } - _, _ = internal.FPrintflnReusingLine(d.loginOpts.Err, "Read %d %s", len(result), entityName) + _, _ = internal.FPrintflnReusingLine(exporter.loginOpts.Err, "Read %d %s", len(result), entityName) return result, nil } -func (d *Exporter) ToMap(input interface{}) map[string]interface{} { +func (exporter *Exporter) ToMap(input interface{}) map[string]interface{} { jsonData, _ := json.MarshalIndent(input, "", "") m := map[string]interface{}{} err := json.Unmarshal(jsonData, &m) @@ -325,13 +325,13 @@ func (d *Exporter) ToMap(input interface{}) map[string]interface{} { return m } -func (d *Exporter) defaultRoleAttributes(m map[string]interface{}) { +func (exporter *Exporter) defaultRoleAttributes(m map[string]interface{}) { if m["roleAttributes"] == nil { m["roleAttributes"] = []string{} } } -func (d *Exporter) Filter(m map[string]interface{}, properties []string) { +func (exporter *Exporter) Filter(m map[string]interface{}, properties []string) { // remove any properties that are not requested for k := range m { diff --git a/ziti/cmd/ascode/exporter/exporter_auth_policies.go b/ziti/cmd/ascode/exporter/exporter_auth_policies.go index ee658168c..e7ac040bd 100644 --- a/ziti/cmd/ascode/exporter/exporter_auth_policies.go +++ b/ziti/cmd/ascode/exporter/exporter_auth_policies.go @@ -24,18 +24,18 @@ import ( "slices" ) -func (d Exporter) IsAuthPolicyExportRequired(args []string) bool { +func (exporter Exporter) IsAuthPolicyExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "auth-policy") } -func (d Exporter) GetAuthPolicies() ([]map[string]interface{}, error) { +func (exporter Exporter) GetAuthPolicies() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "AuthPolicies", func() (int64, error) { limit := int64(1) - resp, err := d.client.AuthPolicy.ListAuthPolicies( + resp, err := exporter.client.AuthPolicy.ListAuthPolicies( &auth_policy.ListAuthPoliciesParams{Limit: &limit}, nil) if err != nil { return -1, err @@ -44,7 +44,7 @@ func (d Exporter) GetAuthPolicies() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.AuthPolicy.ListAuthPolicies( + resp, err := exporter.client.AuthPolicy.ListAuthPolicies( &auth_policy.ListAuthPoliciesParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err @@ -61,25 +61,25 @@ func (d Exporter) GetAuthPolicies() ([]map[string]interface{}, error) { if *item.Name != "Default" { // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) // deleting Primary so we can reconstruct it delete(m, "primary") - primary := d.ToMap(item.Primary) + primary := exporter.ToMap(item.Primary) m["primary"] = primary // deleting ExtJwt so we can reconstruct it delete(primary, "extJwt") - extJwt := d.ToMap(item.Primary.ExtJWT) + extJwt := exporter.ToMap(item.Primary.ExtJWT) primary["extJwt"] = extJwt // deleting AllowedSigners because it needs to use a reference to the name instead of the ID delete(extJwt, "allowedSigners") signers := []string{} for _, signer := range item.Primary.ExtJWT.AllowedSigners { - extJwtSigner, lookupErr := ascode.GetItemFromCache(d.externalJwtCache, signer, func(id string) (interface{}, error) { - return d.client.ExternalJWTSigner.DetailExternalJWTSigner( + extJwtSigner, lookupErr := ascode.GetItemFromCache(exporter.externalJwtCache, signer, func(id string) (interface{}, error) { + return exporter.client.ExternalJWTSigner.DetailExternalJWTSigner( &external_jwt_signer.DetailExternalJWTSignerParams{ID: id}, nil) }) if lookupErr != nil { @@ -93,14 +93,14 @@ func (d Exporter) GetAuthPolicies() ([]map[string]interface{}, error) { if item.Secondary.RequireExtJWTSigner != nil { // deleting Secondary so we can reconstruct it delete(m, "secondary") - secondary := d.ToMap(item.Secondary) + secondary := exporter.ToMap(item.Secondary) m["secondary"] = secondary // deleting RequiredExtJwtSigner because it needs to use a reference to the name instead of the ID delete(secondary, "requiredExtJwtSigner") - requiredExtJwtSigner := d.ToMap(item.Secondary.RequireExtJWTSigner) - extJwtSigner, lookupErr := ascode.GetItemFromCache(d.externalJwtCache, *item.Secondary.RequireExtJWTSigner, func(id string) (interface{}, error) { - return d.client.ExternalJWTSigner.DetailExternalJWTSigner(&external_jwt_signer.DetailExternalJWTSignerParams{ID: id}, nil) + requiredExtJwtSigner := exporter.ToMap(item.Secondary.RequireExtJWTSigner) + extJwtSigner, lookupErr := ascode.GetItemFromCache(exporter.externalJwtCache, *item.Secondary.RequireExtJWTSigner, func(id string) (interface{}, error) { + return exporter.client.ExternalJWTSigner.DetailExternalJWTSigner(&external_jwt_signer.DetailExternalJWTSignerParams{ID: id}, nil) }) if lookupErr != nil { return nil, lookupErr diff --git a/ziti/cmd/ascode/exporter/exporter_certificate_authorities.go b/ziti/cmd/ascode/exporter/exporter_certificate_authorities.go index 11c63495d..d15645ea4 100644 --- a/ziti/cmd/ascode/exporter/exporter_certificate_authorities.go +++ b/ziti/cmd/ascode/exporter/exporter_certificate_authorities.go @@ -22,20 +22,20 @@ import ( "slices" ) -func (d Exporter) IsCertificateAuthorityExportRequired(args []string) bool { +func (exporter Exporter) IsCertificateAuthorityExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "ca") || slices.Contains(args, "certificate-authority") } -func (d Exporter) GetCertificateAuthorities() ([]map[string]interface{}, error) { +func (exporter Exporter) GetCertificateAuthorities() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "CertificateAuthorities", func() (int64, error) { limit := int64(1) - resp, err := d.client.CertificateAuthority.ListCas(&certificate_authority.ListCasParams{Limit: &limit}, nil) + resp, err := exporter.client.CertificateAuthority.ListCas(&certificate_authority.ListCasParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -43,7 +43,7 @@ func (d Exporter) GetCertificateAuthorities() ([]map[string]interface{}, error) }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.CertificateAuthority.ListCas(&certificate_authority.ListCasParams{Offset: offset, Limit: limit}, nil) + resp, err := exporter.client.CertificateAuthority.ListCas(&certificate_authority.ListCasParams{Offset: offset, Limit: limit}, nil) if err != nil { return nil, err } @@ -59,10 +59,10 @@ func (d Exporter) GetCertificateAuthorities() ([]map[string]interface{}, error) item := entity.(*rest_model.CaDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) return m, nil }) diff --git a/ziti/cmd/ascode/exporter/exporter_config_types.go b/ziti/cmd/ascode/exporter/exporter_config_types.go index 0dffd5556..94e6bd8f9 100644 --- a/ziti/cmd/ascode/exporter/exporter_config_types.go +++ b/ziti/cmd/ascode/exporter/exporter_config_types.go @@ -22,19 +22,19 @@ import ( "slices" ) -func (d Exporter) IsConfigTypeExportRequired(args []string) bool { +func (exporter Exporter) IsConfigTypeExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "config-type") } -func (d Exporter) GetConfigTypes() ([]map[string]interface{}, error) { +func (exporter Exporter) GetConfigTypes() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "ConfigTypes", func() (int64, error) { limit := int64(1) - resp, err := d.client.Config.ListConfigTypes(&config.ListConfigTypesParams{Limit: &limit}, nil) + resp, err := exporter.client.Config.ListConfigTypes(&config.ListConfigTypesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -42,7 +42,7 @@ func (d Exporter) GetConfigTypes() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, _ := d.client.Config.ListConfigTypes(&config.ListConfigTypesParams{Limit: limit, Offset: offset}, nil) + resp, _ := exporter.client.Config.ListConfigTypes(&config.ListConfigTypesParams{Limit: limit, Offset: offset}, nil) entities := make([]interface{}, len(resp.GetPayload().Data)) for i, c := range resp.GetPayload().Data { entities[i] = interface{}(c) @@ -61,8 +61,8 @@ func (d Exporter) GetConfigTypes() ([]map[string]interface{}, error) { } // convert to a map of values - m := d.ToMap(item) - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) + m := exporter.ToMap(item) + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) return m, nil }) diff --git a/ziti/cmd/ascode/exporter/exporter_configs.go b/ziti/cmd/ascode/exporter/exporter_configs.go index 47e6decc8..ed2dfe0e1 100644 --- a/ziti/cmd/ascode/exporter/exporter_configs.go +++ b/ziti/cmd/ascode/exporter/exporter_configs.go @@ -24,19 +24,19 @@ import ( "slices" ) -func (d Exporter) IsConfigExportRequired(args []string) bool { +func (exporter Exporter) IsConfigExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "config") } -func (d Exporter) GetConfigs() ([]map[string]interface{}, error) { +func (exporter Exporter) GetConfigs() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "Configs", func() (int64, error) { limit := int64(1) - resp, err := d.client.Config.ListConfigs(&config.ListConfigsParams{Limit: &limit}, nil) + resp, err := exporter.client.Config.ListConfigs(&config.ListConfigsParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -44,7 +44,7 @@ func (d Exporter) GetConfigs() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, _ := d.client.Config.ListConfigs(&config.ListConfigsParams{Limit: limit, Offset: offset}, nil) + resp, _ := exporter.client.Config.ListConfigs(&config.ListConfigsParams{Limit: limit, Offset: offset}, nil) entities := make([]interface{}, len(resp.GetPayload().Data)) for i, c := range resp.GetPayload().Data { entities[i] = interface{}(c) @@ -57,16 +57,16 @@ func (d Exporter) GetConfigs() ([]map[string]interface{}, error) { item := entity.(*rest_model.ConfigDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) // translate ids to names delete(m, "configType") delete(m, "configTypeId") - configType, lookupErr := ascode.GetItemFromCache(d.configTypeCache, *item.ConfigTypeID, func(id string) (interface{}, error) { - return d.client.Config.DetailConfigType(&config.DetailConfigTypeParams{ID: id}, nil) + configType, lookupErr := ascode.GetItemFromCache(exporter.configTypeCache, *item.ConfigTypeID, func(id string) (interface{}, error) { + return exporter.client.Config.DetailConfigType(&config.DetailConfigTypeParams{ID: id}, nil) }) if lookupErr != nil { return nil, errors.Join(errors.New("error reading Auth Policy: "+*item.ConfigTypeID), lookupErr) diff --git a/ziti/cmd/ascode/exporter/exporter_edgerouter_policies.go b/ziti/cmd/ascode/exporter/exporter_edgerouter_policies.go index 57f9d3e03..4087082b3 100644 --- a/ziti/cmd/ascode/exporter/exporter_edgerouter_policies.go +++ b/ziti/cmd/ascode/exporter/exporter_edgerouter_policies.go @@ -22,19 +22,19 @@ import ( "slices" ) -func (d Exporter) IsEdgeRouterPolicyExportRequired(args []string) bool { +func (exporter Exporter) IsEdgeRouterPolicyExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "edge-router-policy") } -func (d Exporter) GetEdgeRouterPolicies() ([]map[string]interface{}, error) { +func (exporter Exporter) GetEdgeRouterPolicies() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "EdgeRouterPolicies", func() (int64, error) { limit := int64(1) - resp, err := d.client.EdgeRouterPolicy.ListEdgeRouterPolicies(&edge_router_policy.ListEdgeRouterPoliciesParams{Limit: &limit}, nil) + resp, err := exporter.client.EdgeRouterPolicy.ListEdgeRouterPolicies(&edge_router_policy.ListEdgeRouterPoliciesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -42,7 +42,7 @@ func (d Exporter) GetEdgeRouterPolicies() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.EdgeRouterPolicy.ListEdgeRouterPolicies(&edge_router_policy.ListEdgeRouterPoliciesParams{Limit: limit, Offset: offset}, nil) + resp, err := exporter.client.EdgeRouterPolicy.ListEdgeRouterPolicies(&edge_router_policy.ListEdgeRouterPoliciesParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (d Exporter) GetEdgeRouterPolicies() ([]map[string]interface{}, error) { item := entity.(*rest_model.EdgeRouterPolicyDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // translate attributes so they don't reference ids identityRoles := []string{} @@ -73,7 +73,7 @@ func (d Exporter) GetEdgeRouterPolicies() ([]map[string]interface{}, error) { m["edgeRouterRoles"] = edgeRouterRoles // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "edgeRouterRolesDisplay", "identityRolesDisplay", "isSystem"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_edgerouters.go b/ziti/cmd/ascode/exporter/exporter_edgerouters.go index 1b0313c0c..386d80a37 100644 --- a/ziti/cmd/ascode/exporter/exporter_edgerouters.go +++ b/ziti/cmd/ascode/exporter/exporter_edgerouters.go @@ -22,19 +22,19 @@ import ( "slices" ) -func (d Exporter) IsEdgeRouterExportRequired(args []string) bool { +func (exporter Exporter) IsEdgeRouterExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "edge-router") || slices.Contains(args, "er") } -func (d Exporter) GetEdgeRouters() ([]map[string]interface{}, error) { +func (exporter Exporter) GetEdgeRouters() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "EdgeRouters", func() (int64, error) { limit := int64(1) - resp, err := d.client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: &limit}, nil) + resp, err := exporter.client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -42,7 +42,7 @@ func (d Exporter) GetEdgeRouters() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: limit, Offset: offset}, nil) + resp, err := exporter.client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err } @@ -58,11 +58,11 @@ func (d Exporter) GetEdgeRouters() ([]map[string]interface{}, error) { item := entity.(*rest_model.EdgeRouterDetail) // convert to a map of values - m := d.ToMap(item) - d.defaultRoleAttributes(m) + m := exporter.ToMap(item) + exporter.defaultRoleAttributes(m) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "cost", "fingerprint", "isVerified", "isOnline", "enrollmentJwt", "enrollmentCreatedAt", "enrollmentExpiresAt", "syncStatus", "versionInfo", "certPem", "supportedProtocols"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_external_jwt_signers.go b/ziti/cmd/ascode/exporter/exporter_external_jwt_signers.go index 5be4eb154..3163dcfa2 100644 --- a/ziti/cmd/ascode/exporter/exporter_external_jwt_signers.go +++ b/ziti/cmd/ascode/exporter/exporter_external_jwt_signers.go @@ -22,20 +22,20 @@ import ( "slices" ) -func (d Exporter) IsExtJwtSignerExportRequired(args []string) bool { +func (exporter Exporter) IsExtJwtSignerExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "ext-jwt-signer") || slices.Contains(args, "external-jwt-signer") } -func (d Exporter) GetExternalJwtSigners() ([]map[string]interface{}, error) { +func (exporter Exporter) GetExternalJwtSigners() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "ExtJWTSigners", func() (int64, error) { limit := int64(1) - resp, err := d.client.ExternalJWTSigner.ListExternalJWTSigners(&external_jwt_signer.ListExternalJWTSignersParams{Limit: &limit}, nil) + resp, err := exporter.client.ExternalJWTSigner.ListExternalJWTSigners(&external_jwt_signer.ListExternalJWTSignersParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -43,7 +43,7 @@ func (d Exporter) GetExternalJwtSigners() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.ExternalJWTSigner.ListExternalJWTSigners( + resp, err := exporter.client.ExternalJWTSigner.ListExternalJWTSigners( &external_jwt_signer.ListExternalJWTSignersParams{Offset: offset, Limit: limit}, nil) if err != nil { return nil, err @@ -60,10 +60,10 @@ func (d Exporter) GetExternalJwtSigners() ([]map[string]interface{}, error) { item := entity.(*rest_model.ExternalJWTSignerDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "notBefore", "notAfter", "commonName"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_identities.go b/ziti/cmd/ascode/exporter/exporter_identities.go index e99451f63..3de50051f 100644 --- a/ziti/cmd/ascode/exporter/exporter_identities.go +++ b/ziti/cmd/ascode/exporter/exporter_identities.go @@ -25,19 +25,19 @@ import ( "slices" ) -func (d Exporter) IsIdentityExportRequired(args []string) bool { +func (exporter Exporter) IsIdentityExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "identity") } -func (d Exporter) GetIdentities() ([]map[string]interface{}, error) { +func (exporter Exporter) GetIdentities() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "Identities", func() (int64, error) { limit := int64(1) - resp, err := d.client.Identity.ListIdentities(&identity.ListIdentitiesParams{Limit: &limit}, nil) + resp, err := exporter.client.Identity.ListIdentities(&identity.ListIdentitiesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -45,7 +45,7 @@ func (d Exporter) GetIdentities() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.Identity.ListIdentities(&identity.ListIdentitiesParams{Offset: offset, Limit: limit}, nil) + resp, err := exporter.client.Identity.ListIdentities(&identity.ListIdentitiesParams{Offset: offset, Limit: limit}, nil) if err != nil { return nil, err } @@ -64,11 +64,11 @@ func (d Exporter) GetIdentities() ([]map[string]interface{}, error) { if *item.TypeID != "Router" && !*item.IsDefaultAdmin { // convert to a map of values - m := d.ToMap(item) - d.defaultRoleAttributes(m) + m := exporter.ToMap(item) + exporter.defaultRoleAttributes(m) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "defaultHostingCost", "defaultHostingPrecedence", "hasApiSession", "serviceHostingPrecedences", "enrollment", "appData", "sdkInfo", "disabledAt", "disabledUntil", "serviceHostingCosts", "envInfo", "authenticators", "type", "authPolicyId", "hasRouterConnection", "hasEdgeRouterConnection"}) @@ -78,8 +78,8 @@ func (d Exporter) GetIdentities() ([]map[string]interface{}, error) { } // translate ids to names - authPolicy, lookupErr := ascode.GetItemFromCache(d.authPolicyCache, *item.AuthPolicyID, func(id string) (interface{}, error) { - return d.client.AuthPolicy.DetailAuthPolicy(&auth_policy.DetailAuthPolicyParams{ID: id}, nil) + authPolicy, lookupErr := ascode.GetItemFromCache(exporter.authPolicyCache, *item.AuthPolicyID, func(id string) (interface{}, error) { + return exporter.client.AuthPolicy.DetailAuthPolicy(&auth_policy.DetailAuthPolicyParams{ID: id}, nil) }) if lookupErr != nil { return nil, errors.Join(errors.New("error reading Auth Policy: "+*item.AuthPolicyID), lookupErr) diff --git a/ziti/cmd/ascode/exporter/exporter_posture_checks.go b/ziti/cmd/ascode/exporter/exporter_posture_checks.go index c96c9cf4d..ebf2f8c0f 100644 --- a/ziti/cmd/ascode/exporter/exporter_posture_checks.go +++ b/ziti/cmd/ascode/exporter/exporter_posture_checks.go @@ -21,19 +21,19 @@ import ( "golang.org/x/exp/slices" ) -func (d Exporter) IsPostureCheckExportRequired(args []string) bool { +func (exporter Exporter) IsPostureCheckExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "posture-check") } -func (d Exporter) GetPostureChecks() ([]map[string]interface{}, error) { +func (exporter Exporter) GetPostureChecks() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "PostureChecks", func() (int64, error) { limit := int64(1) - resp, err := d.client.PostureChecks.ListPostureChecks(&posture_checks.ListPostureChecksParams{Limit: &limit}, nil) + resp, err := exporter.client.PostureChecks.ListPostureChecks(&posture_checks.ListPostureChecksParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -41,7 +41,7 @@ func (d Exporter) GetPostureChecks() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, _ := d.client.PostureChecks.ListPostureChecks(&posture_checks.ListPostureChecksParams{Limit: limit, Offset: offset}, nil) + resp, _ := exporter.client.PostureChecks.ListPostureChecks(&posture_checks.ListPostureChecksParams{Limit: limit, Offset: offset}, nil) entities := make([]interface{}, len(resp.GetPayload().Data())) for i, c := range resp.GetPayload().Data() { entities[i] = interface{}(c) @@ -52,10 +52,10 @@ func (d Exporter) GetPostureChecks() ([]map[string]interface{}, error) { func(entity interface{}) (map[string]interface{}, error) { // convert to a map of values - m := d.ToMap(entity) + m := exporter.ToMap(entity) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "version"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_service_edgerouter_policies.go b/ziti/cmd/ascode/exporter/exporter_service_edgerouter_policies.go index 82e1bb014..a069a813a 100644 --- a/ziti/cmd/ascode/exporter/exporter_service_edgerouter_policies.go +++ b/ziti/cmd/ascode/exporter/exporter_service_edgerouter_policies.go @@ -22,19 +22,19 @@ import ( "slices" ) -func (d Exporter) IsServiceEdgeRouterPolicyExportRequired(args []string) bool { +func (exporter Exporter) IsServiceEdgeRouterPolicyExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service-edge-router-policy") } -func (d Exporter) GetServiceEdgeRouterPolicies() ([]map[string]interface{}, error) { +func (exporter Exporter) GetServiceEdgeRouterPolicies() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "ServiceEdgeRouterPolicies", func() (int64, error) { limit := int64(1) - resp, err := d.client.ServiceEdgeRouterPolicy.ListServiceEdgeRouterPolicies(&service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{Limit: &limit}, nil) + resp, err := exporter.client.ServiceEdgeRouterPolicy.ListServiceEdgeRouterPolicies(&service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -42,7 +42,7 @@ func (d Exporter) GetServiceEdgeRouterPolicies() ([]map[string]interface{}, erro }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.ServiceEdgeRouterPolicy.ListServiceEdgeRouterPolicies(&service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{Limit: limit, Offset: offset}, nil) + resp, err := exporter.client.ServiceEdgeRouterPolicy.ListServiceEdgeRouterPolicies(&service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (d Exporter) GetServiceEdgeRouterPolicies() ([]map[string]interface{}, erro item := entity.(*rest_model.ServiceEdgeRouterPolicyDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // translate attributes so they don't reference ids serviceRoles := []string{} @@ -73,7 +73,7 @@ func (d Exporter) GetServiceEdgeRouterPolicies() ([]map[string]interface{}, erro m["edgeRouterRoles"] = edgeRouterRoles // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "edgeRouterRolesDisplay", "serviceRolesDisplay", "isSystem"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_service_policies.go b/ziti/cmd/ascode/exporter/exporter_service_policies.go index 723c73da7..5f39e5734 100644 --- a/ziti/cmd/ascode/exporter/exporter_service_policies.go +++ b/ziti/cmd/ascode/exporter/exporter_service_policies.go @@ -22,19 +22,19 @@ import ( "slices" ) -func (d Exporter) IsServicePolicyExportRequired(args []string) bool { +func (exporter Exporter) IsServicePolicyExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service-policy") } -func (d Exporter) GetServicePolicies() ([]map[string]interface{}, error) { +func (exporter Exporter) GetServicePolicies() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "ServicePolicies", func() (int64, error) { limit := int64(1) - resp, err := d.client.ServicePolicy.ListServicePolicies(&service_policy.ListServicePoliciesParams{Limit: &limit}, nil) + resp, err := exporter.client.ServicePolicy.ListServicePolicies(&service_policy.ListServicePoliciesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -42,7 +42,7 @@ func (d Exporter) GetServicePolicies() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.ServicePolicy.ListServicePolicies(&service_policy.ListServicePoliciesParams{Limit: limit, Offset: offset}, nil) + resp, err := exporter.client.ServicePolicy.ListServicePolicies(&service_policy.ListServicePoliciesParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func (d Exporter) GetServicePolicies() ([]map[string]interface{}, error) { item := entity.(*rest_model.ServicePolicyDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) // translate attributes so they don't reference ids identityRoles := []string{} @@ -78,7 +78,7 @@ func (d Exporter) GetServicePolicies() ([]map[string]interface{}, error) { m["postureCheckRoles"] = postureCheckRoles // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "serviceRolesDisplay", "identityRolesDisplay", "postureCheckRolesDisplay", "isSystem"}) return m, nil diff --git a/ziti/cmd/ascode/exporter/exporter_services.go b/ziti/cmd/ascode/exporter/exporter_services.go index 60e39ddb0..2ccdc3804 100644 --- a/ziti/cmd/ascode/exporter/exporter_services.go +++ b/ziti/cmd/ascode/exporter/exporter_services.go @@ -25,19 +25,19 @@ import ( "slices" ) -func (d Exporter) IsServiceExportRequired(args []string) bool { +func (exporter Exporter) IsServiceExportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service") } -func (d Exporter) GetServices() ([]map[string]interface{}, error) { +func (exporter Exporter) GetServices() ([]map[string]interface{}, error) { - return d.getEntities( + return exporter.getEntities( "Services", func() (int64, error) { limit := int64(1) - resp, err := d.client.Service.ListServices(&service.ListServicesParams{Limit: &limit}, nil) + resp, err := exporter.client.Service.ListServices(&service.ListServicesParams{Limit: &limit}, nil) if err != nil { return -1, err } @@ -45,7 +45,7 @@ func (d Exporter) GetServices() ([]map[string]interface{}, error) { }, func(offset *int64, limit *int64) ([]interface{}, error) { - resp, err := d.client.Service.ListServices(&service.ListServicesParams{Limit: limit, Offset: offset}, nil) + resp, err := exporter.client.Service.ListServices(&service.ListServicesParams{Limit: limit, Offset: offset}, nil) if err != nil { return nil, err } @@ -61,19 +61,19 @@ func (d Exporter) GetServices() ([]map[string]interface{}, error) { item := entity.(*rest_model.ServiceDetail) // convert to a map of values - m := d.ToMap(item) + m := exporter.ToMap(item) - d.defaultRoleAttributes(m) + exporter.defaultRoleAttributes(m) // filter unwanted properties - d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", + exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", "configs", "config", "data", "postureQueries", "permissions", "maxIdleTimeMillis"}) // translate ids to names var configNames []string for _, c := range item.Configs { - configDetail, lookupErr := ascode.GetItemFromCache(d.configCache, c, func(id string) (interface{}, error) { - return d.client.Config.DetailConfig(&config.DetailConfigParams{ID: id}, nil) + configDetail, lookupErr := ascode.GetItemFromCache(exporter.configCache, c, func(id string) (interface{}, error) { + return exporter.client.Config.DetailConfig(&config.DetailConfigParams{ID: id}, nil) }) if lookupErr != nil { return nil, errors.Join(errors.New("error reading Config: "+c), lookupErr) diff --git a/ziti/cmd/ascode/importer/importer.go b/ziti/cmd/ascode/importer/importer.go index e8cdf49bd..64818278e 100644 --- a/ziti/cmd/ascode/importer/importer.go +++ b/ziti/cmd/ascode/importer/importer.go @@ -53,8 +53,8 @@ type Importer struct { func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command { - u := &Importer{} - u.loginOpts = edge.LoginOptions{} + importer := &Importer{} + importer.loginOpts = edge.LoginOptions{} cmd := &cobra.Command{ Use: "import filename [entity]", @@ -63,16 +63,16 @@ func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command { "Valid entities are: [all|ca/certificate-authority|identity|edge-router|service|config|config-type|service-policy|edge-router-policy|service-edge-router-policy|external-jwt-signer|auth-policy|posture-check] (default all)", Args: cobra.MinimumNArgs(1), PersistentPreRun: func(cmd *cobra.Command, args []string) { - u.Init() + importer.Init() }, Run: func(cmd *cobra.Command, args []string) { - data, err := u.reader.read(args[0]) + data, err := importer.reader.read(args[0]) if err != nil { panic(errors.Join(errors.New("unable to read input"), err)) } m := map[string][]interface{}{} - if u.ofYaml { + if importer.ofYaml { err = yaml.Unmarshal(data, &m) if err != nil { panic(errors.Join(errors.New("unable to parse input data as yaml"), err)) @@ -84,7 +84,7 @@ func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command { } } - result, executeErr := u.Execute(m, args[1:]) + result, executeErr := importer.Execute(m, args[1:]) if executeErr != nil { panic(executeErr) } @@ -100,22 +100,21 @@ func NewImportCmd(out io.Writer, errOut io.Writer) *cobra.Command { v.AutomaticEnv() cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVar(&u.ofJson, "json", true, "Input parsed as JSON") - cmd.Flags().BoolVar(&u.ofYaml, "yaml", false, "Input parsed as YAML") + cmd.Flags().BoolVar(&importer.ofJson, "json", true, "Input parsed as JSON") + cmd.Flags().BoolVar(&importer.ofYaml, "yaml", false, "Input parsed as YAML") cmd.MarkFlagsMutuallyExclusive("json", "yaml") - edge.AddLoginFlags(cmd, &u.loginOpts) - u.loginOpts.Out = out - u.loginOpts.Err = errOut + edge.AddLoginFlags(cmd, &importer.loginOpts) + importer.loginOpts.Out = out + importer.loginOpts.Err = errOut return cmd } -func (u *Importer) Init() { - u.loginOpts.Verbose = u.loginOpts.Verbose +func (importer *Importer) Init() { logLvl := logrus.InfoLevel - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { logLvl = logrus.DebugLevel } @@ -124,7 +123,7 @@ func (u *Importer) Init() { client, err := mgmt.NewClient() if err != nil { - loginErr := u.loginOpts.Run() + loginErr := importer.loginOpts.Run() if loginErr != nil { log.Fatal(err) } @@ -133,28 +132,28 @@ func (u *Importer) Init() { log.Fatal(err) } } - u.client = client - u.reader = FileReader{} + importer.client = client + importer.reader = FileReader{} } -func (u *Importer) Execute(data map[string][]interface{}, inputArgs []string) (map[string]any, error) { +func (importer *Importer) Execute(data map[string][]interface{}, inputArgs []string) (map[string]any, error) { args := arrayutils.Map(inputArgs, strings.ToLower) - u.configCache = map[string]any{} - u.serviceCache = map[string]any{} - u.edgeRouterCache = map[string]any{} - u.authPolicyCache = map[string]any{} - u.extJwtSignersCache = map[string]any{} - u.identityCache = map[string]any{} + importer.configCache = map[string]any{} + importer.serviceCache = map[string]any{} + importer.edgeRouterCache = map[string]any{} + importer.authPolicyCache = map[string]any{} + importer.extJwtSignersCache = map[string]any{} + importer.identityCache = map[string]any{} result := map[string]any{} cas := map[string]string{} - if u.IsCertificateAuthorityImportRequired(args) { + if importer.IsCertificateAuthorityImportRequired(args) { log.Debug("Processing CertificateAuthorities") var err error - cas, err = u.ProcessCertificateAuthorities(data) + cas, err = importer.ProcessCertificateAuthorities(data) if err != nil { return nil, err } @@ -163,149 +162,149 @@ func (u *Importer) Execute(data map[string][]interface{}, inputArgs []string) (m Debug("CertificateAuthorities created") } result["certificateAuthorities"] = cas - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d CertificateAuthorities\r\n", len(cas)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d CertificateAuthorities\r\n", len(cas)) externalJwtSigners := map[string]string{} - if u.IsExtJwtSignerImportRequired(args) { + if importer.IsExtJwtSignerImportRequired(args) { log.Debug("Processing ExtJWTSigners") var err error - externalJwtSigners, err = u.ProcessExternalJwtSigners(data) + externalJwtSigners, err = importer.ProcessExternalJwtSigners(data) if err != nil { return nil, err } log.WithField("externalJwtSigners", externalJwtSigners).Debug("ExtJWTSigners created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d ExtJWTSigners\r\n", len(externalJwtSigners)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d ExtJWTSigners\r\n", len(externalJwtSigners)) result["externalJwtSigners"] = externalJwtSigners authPolicies := map[string]string{} - if u.IsAuthPolicyImportRequired(args) { + if importer.IsAuthPolicyImportRequired(args) { log.Debug("Processing AuthPolicies") var err error - authPolicies, err = u.ProcessAuthPolicies(data) + authPolicies, err = importer.ProcessAuthPolicies(data) if err != nil { return nil, err } log.WithField("authPolicies", authPolicies).Debug("AuthPolicies created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d AuthPolicies\r\n", len(authPolicies)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d AuthPolicies\r\n", len(authPolicies)) result["authPolicies"] = authPolicies identities := map[string]string{} - if u.IsIdentityImportRequired(args) { + if importer.IsIdentityImportRequired(args) { log.Debug("Processing Identities") var err error - identities, err = u.ProcessIdentities(data) + identities, err = importer.ProcessIdentities(data) if err != nil { return nil, err } log.WithField("identities", identities).Debug("Identities created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d Identities\r\n", len(identities)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d Identities\r\n", len(identities)) result["identities"] = identities configTypes := map[string]string{} - if u.IsConfigTypeImportRequired(args) { + if importer.IsConfigTypeImportRequired(args) { log.Debug("Processing ConfigTypes") var err error - configTypes, err = u.ProcessConfigTypes(data) + configTypes, err = importer.ProcessConfigTypes(data) if err != nil { return nil, err } log.WithField("configTypes", configTypes).Debug("ConfigTypes created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d ConfigTypes\r\n", len(configTypes)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d ConfigTypes\r\n", len(configTypes)) result["configTypes"] = configTypes configs := map[string]string{} - if u.IsConfigImportRequired(args) { + if importer.IsConfigImportRequired(args) { log.Debug("Processing Configs") var err error - configs, err = u.ProcessConfigs(data) + configs, err = importer.ProcessConfigs(data) if err != nil { return nil, err } log.WithField("configs", configs).Debug("Configs created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d Configs\r\n", len(configs)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d Configs\r\n", len(configs)) result["configs"] = configs services := map[string]string{} - if u.IsServiceImportRequired(args) { + if importer.IsServiceImportRequired(args) { log.Debug("Processing Services") var err error - services, err = u.ProcessServices(data) + services, err = importer.ProcessServices(data) if err != nil { return nil, err } log.WithField("services", services).Debug("Services created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d Services\r\n", len(services)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d Services\r\n", len(services)) result["services"] = services postureChecks := map[string]string{} - if u.IsPostureCheckImportRequired(args) { + if importer.IsPostureCheckImportRequired(args) { log.Debug("Processing PostureChecks") var err error - postureChecks, err = u.ProcessPostureChecks(data) + postureChecks, err = importer.ProcessPostureChecks(data) if err != nil { return nil, err } log.WithField("postureChecks", postureChecks).Debug("PostureChecks created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d PostureChecks\r\n", len(postureChecks)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d PostureChecks\r\n", len(postureChecks)) result["postureChecks"] = postureChecks routers := map[string]string{} - if u.IsEdgeRouterImportRequired(args) { + if importer.IsEdgeRouterImportRequired(args) { log.Debug("Processing EdgeRouters") var err error - routers, err = u.ProcessEdgeRouters(data) + routers, err = importer.ProcessEdgeRouters(data) if err != nil { return nil, err } log.WithField("edgeRouters", routers).Debug("EdgeRouters created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d EdgeRouters\r\n", len(routers)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d EdgeRouters\r\n", len(routers)) result["edgeRouters"] = routers serviceEdgeRouterPolicies := map[string]string{} - if u.IsServiceEdgeRouterPolicyImportRequired(args) { + if importer.IsServiceEdgeRouterPolicyImportRequired(args) { log.Debug("Processing ServiceEdgeRouterPolicies") var err error - serviceEdgeRouterPolicies, err = u.ProcessServiceEdgeRouterPolicies(data) + serviceEdgeRouterPolicies, err = importer.ProcessServiceEdgeRouterPolicies(data) if err != nil { return nil, err } log.WithField("serviceEdgeRouterPolicies", serviceEdgeRouterPolicies).Debug("ServiceEdgeRouterPolicies created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d ServiceEdgeRouterPolicies\r\n", len(serviceEdgeRouterPolicies)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d ServiceEdgeRouterPolicies\r\n", len(serviceEdgeRouterPolicies)) result["serviceEdgeRouterPolicies"] = serviceEdgeRouterPolicies servicePolicies := map[string]string{} - if u.IsServicePolicyImportRequired(args) { + if importer.IsServicePolicyImportRequired(args) { log.Debug("Processing ServicePolicies") var err error - servicePolicies, err = u.ProcessServicePolicies(data) + servicePolicies, err = importer.ProcessServicePolicies(data) if err != nil { return nil, err } log.WithField("servicePolicies", servicePolicies).Debug("ServicePolicies created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d ServicePolicies\r\n", len(servicePolicies)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d ServicePolicies\r\n", len(servicePolicies)) result["servicePolicies"] = servicePolicies routerPolicies := map[string]string{} - if u.IsEdgeRouterPolicyImportRequired(args) { + if importer.IsEdgeRouterPolicyImportRequired(args) { log.Debug("Processing EdgeRouterPolicies") var err error - routerPolicies, err = u.ProcessEdgeRouterPolicies(data) + routerPolicies, err = importer.ProcessEdgeRouterPolicies(data) if err != nil { return nil, err } log.WithField("routerPolicies", routerPolicies).Debug("EdgeRouterPolicies created") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Created %d EdgeRouterPolicies\r\n", len(routerPolicies)) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Created %d EdgeRouterPolicies\r\n", len(routerPolicies)) result["edgeRouterPolicies"] = routerPolicies log.Info("Upload complete") diff --git a/ziti/cmd/ascode/importer/importer_auth_policies.go b/ziti/cmd/ascode/importer/importer_auth_policies.go index e1aa2e4d7..b1faab7ef 100644 --- a/ziti/cmd/ascode/importer/importer_auth_policies.go +++ b/ziti/cmd/ascode/importer/importer_auth_policies.go @@ -28,15 +28,15 @@ import ( "slices" ) -func (u *Importer) IsAuthPolicyImportRequired(args []string) bool { +func (importer *Importer) IsAuthPolicyImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "auth-policy") || slices.Contains(args, "identity") } -func (u *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[string]string, error) { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.Debug("Listing all AuthPolicies") } @@ -46,15 +46,15 @@ func (u *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[stri create := FromMap(data, rest_model.AuthPolicyCreate{}) // see if the auth policy already exists - existing := mgmt.AuthPolicyFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.AuthPolicyFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "authPolicyId": *existing.ID, }).Info("Found existing Auth Policy, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping AuthPolicy %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping AuthPolicy %s\r", *create.Name) continue } @@ -71,8 +71,8 @@ func (u *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[stri allowedSignerIds := []string{} for _, signer := range allowedSigners.Children() { value := signer.Data().(string)[1:] - extJwtSigner, err := ascode.GetItemFromCache(u.extJwtSignersCache, value, func(name string) (interface{}, error) { - return mgmt.ExternalJWTSignerFromFilter(u.client, mgmt.NameFilter(name)), nil + extJwtSigner, err := ascode.GetItemFromCache(importer.extJwtSignersCache, value, func(name string) (interface{}, error) { + return mgmt.ExternalJWTSignerFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if err != nil { log.WithField("name", *create.Name).Warn("Unable to read ExtJwtSigner") @@ -83,12 +83,12 @@ func (u *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[stri create.Primary.ExtJWT.AllowedSigners = allowedSignerIds // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating AuthPolicy %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating AuthPolicy %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name). Debug("Creating AuthPolicy") } - created, createErr := u.client.AuthPolicy.CreateAuthPolicy(&auth_policy.CreateAuthPolicyParams{AuthPolicy: create}, nil) + created, createErr := importer.client.AuthPolicy.CreateAuthPolicy(&auth_policy.CreateAuthPolicyParams{AuthPolicy: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -103,7 +103,7 @@ func (u *Importer) ProcessAuthPolicies(input map[string][]interface{}) (map[stri } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "authPolicyId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_certificate_authorities.go b/ziti/cmd/ascode/importer/importer_certificate_authorities.go index 9c22b9354..5a9e46746 100644 --- a/ziti/cmd/ascode/importer/importer_certificate_authorities.go +++ b/ziti/cmd/ascode/importer/importer_certificate_authorities.go @@ -25,35 +25,35 @@ import ( "slices" ) -func (u *Importer) IsCertificateAuthorityImportRequired(args []string) bool { +func (importer *Importer) IsCertificateAuthorityImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "ca") || slices.Contains(args, "certificate-authority") } -func (u *Importer) ProcessCertificateAuthorities(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessCertificateAuthorities(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["certificateAuthorities"] { create := FromMap(data, rest_model.CaCreate{}) // see if the CA already exists - existing := mgmt.CertificateAuthorityFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.CertificateAuthorityFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "certificateAuthorityId": *existing.ID, }). Info("Found existing CertificateAuthority, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping CertificateAuthority %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping CertificateAuthority %s\r", *create.Name) continue } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating CertificateAuthority %s\r", *create.Name) - created, createErr := u.client.CertificateAuthority.CreateCa(&certificate_authority.CreateCaParams{Ca: create}, nil) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating CertificateAuthority %s\r", *create.Name) + created, createErr := importer.client.CertificateAuthority.CreateCa(&certificate_authority.CreateCaParams{Ca: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log. @@ -69,7 +69,7 @@ func (u *Importer) ProcessCertificateAuthorities(input map[string][]interface{}) return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "certificateAuthorityId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_config_types.go b/ziti/cmd/ascode/importer/importer_config_types.go index 0c905aa14..0c76d4c0f 100644 --- a/ziti/cmd/ascode/importer/importer_config_types.go +++ b/ziti/cmd/ascode/importer/importer_config_types.go @@ -25,40 +25,40 @@ import ( "slices" ) -func (u *Importer) IsConfigTypeImportRequired(args []string) bool { +func (importer *Importer) IsConfigTypeImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "config-type") || slices.Contains(args, "config") || slices.Contains(args, "service") } -func (u *Importer) ProcessConfigTypes(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessConfigTypes(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["configTypes"] { create := FromMap(data, rest_model.ConfigTypeCreate{}) // see if the config type already exists - existing := mgmt.ConfigTypeFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ConfigTypeFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "configTypeId": *existing.ID, }). Info("Found existing ConfigType, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping ConfigType %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping ConfigType %s\r", *create.Name) continue } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating ConfigType %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating ConfigType %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name). Debug("Creating ConfigType") } - created, createErr := u.client.Config.CreateConfigType(&config.CreateConfigTypeParams{ConfigType: create}, nil) + created, createErr := importer.client.Config.CreateConfigType(&config.CreateConfigTypeParams{ConfigType: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -73,7 +73,7 @@ func (u *Importer) ProcessConfigTypes(input map[string][]interface{}) (map[strin return nil, createErr } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "configTypeId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_configs.go b/ziti/cmd/ascode/importer/importer_configs.go index ce9e95c0a..69f391d98 100644 --- a/ziti/cmd/ascode/importer/importer_configs.go +++ b/ziti/cmd/ascode/importer/importer_configs.go @@ -29,22 +29,22 @@ import ( "slices" ) -func (u *Importer) IsConfigImportRequired(args []string) bool { +func (importer *Importer) IsConfigImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "config") || slices.Contains(args, "service") } -func (u *Importer) ProcessConfigs(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessConfigs(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["configs"] { create := FromMap(data, rest_model.ConfigCreate{}) // see if the config already exists - existing := mgmt.ConfigFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ConfigFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log. WithFields(map[string]interface{}{ "name": *create.Name, @@ -52,7 +52,7 @@ func (u *Importer) ProcessConfigs(input map[string][]interface{}) (map[string]st }). Info("Found existing Config, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping Config %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping Config %s\r", *create.Name) continue } @@ -66,20 +66,20 @@ func (u *Importer) ProcessConfigs(input map[string][]interface{}) (map[string]st // look up the config type id from the name and add to the create value := doc.Path("configType").Data().(string)[1:] - configType, _ := ascode.GetItemFromCache(u.configCache, value, func(name string) (interface{}, error) { - return mgmt.ConfigTypeFromFilter(u.client, mgmt.NameFilter(name)), nil + configType, _ := ascode.GetItemFromCache(importer.configCache, value, func(name string) (interface{}, error) { + return mgmt.ConfigTypeFromFilter(importer.client, mgmt.NameFilter(name)), nil }) - if u.configCache == nil { + if importer.configCache == nil { return nil, errors.New("error reading ConfigType: " + value) } create.ConfigTypeID = configType.(*rest_model.ConfigTypeDetail).ID // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating Config %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating Config %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating Config") } - created, createErr := u.client.Config.CreateConfig(&config.CreateConfigParams{Config: create}, nil) + created, createErr := importer.client.Config.CreateConfig(&config.CreateConfigParams{Config: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -92,7 +92,7 @@ func (u *Importer) ProcessConfigs(input map[string][]interface{}) (map[string]st return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "configId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_edgerouter_policies.go b/ziti/cmd/ascode/importer/importer_edgerouter_policies.go index 485b53eff..e0d63ee26 100644 --- a/ziti/cmd/ascode/importer/importer_edgerouter_policies.go +++ b/ziti/cmd/ascode/importer/importer_edgerouter_policies.go @@ -25,49 +25,49 @@ import ( "slices" ) -func (u *Importer) IsEdgeRouterPolicyImportRequired(args []string) bool { +func (importer *Importer) IsEdgeRouterPolicyImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "edge-router-policy") } -func (u *Importer) ProcessEdgeRouterPolicies(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessEdgeRouterPolicies(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["edgeRouterPolicies"] { create := FromMap(data, rest_model.EdgeRouterPolicyCreate{}) // see if the router already exists - existing := mgmt.EdgeRouterPolicyFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.EdgeRouterPolicyFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { log.WithFields(map[string]interface{}{ "name": *create.Name, "edgeRouterPolicyId": *existing.ID, }). Info("Found existing EdgeRouterPolicy, skipping create") - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping EdgeRouterPolicy %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping EdgeRouterPolicy %s\r", *create.Name) continue } // look up the edgeRouter ids from the name and add to the create - edgeRouterRoles, err := u.lookupEdgeRouters(create.EdgeRouterRoles) + edgeRouterRoles, err := importer.lookupEdgeRouters(create.EdgeRouterRoles) if err != nil { return nil, err } create.EdgeRouterRoles = edgeRouterRoles // look up the identity ids from the name and add to the create - identityRoles, err := u.lookupIdentities(create.IdentityRoles) + identityRoles, err := importer.lookupIdentities(create.IdentityRoles) if err != nil { return nil, err } create.IdentityRoles = identityRoles // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating EdgeRouterPolicy %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating EdgeRouterPolicy %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating EdgeRouterPolicy") } - created, createErr := u.client.EdgeRouterPolicy.CreateEdgeRouterPolicy(&edge_router_policy.CreateEdgeRouterPolicyParams{Policy: create}, nil) + created, createErr := importer.client.EdgeRouterPolicy.CreateEdgeRouterPolicy(&edge_router_policy.CreateEdgeRouterPolicyParams{Policy: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -81,7 +81,7 @@ func (u *Importer) ProcessEdgeRouterPolicies(input map[string][]interface{}) (ma return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "routerPolicyId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_edgerouters.go b/ziti/cmd/ascode/importer/importer_edgerouters.go index e01e814c8..36ec78301 100644 --- a/ziti/cmd/ascode/importer/importer_edgerouters.go +++ b/ziti/cmd/ascode/importer/importer_edgerouters.go @@ -27,36 +27,36 @@ import ( "slices" ) -func (u *Importer) IsEdgeRouterImportRequired(args []string) bool { +func (importer *Importer) IsEdgeRouterImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "edge-router") || slices.Contains(args, "er") } -func (u *Importer) ProcessEdgeRouters(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessEdgeRouters(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["edgeRouters"] { create := FromMap(data, rest_model.EdgeRouterCreate{}) // see if the router already exists - existing := mgmt.EdgeRouterFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.EdgeRouterFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { log.WithFields(map[string]interface{}{ "name": *create.Name, "edgeRouterId": *existing.ID, }). Info("Found existing EdgeRouter, skipping create") - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping EdgeRouter %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping EdgeRouter %s\r", *create.Name) continue } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating EdgeRouterPolicy %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating EdgeRouterPolicy %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating EdgeRouter") } - created, createErr := u.client.EdgeRouter.CreateEdgeRouter(&edge_router.CreateEdgeRouterParams{EdgeRouter: create}, nil) + created, createErr := importer.client.EdgeRouter.CreateEdgeRouter(&edge_router.CreateEdgeRouterParams{EdgeRouter: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -68,7 +68,7 @@ func (u *Importer) ProcessEdgeRouters(input map[string][]interface{}) (map[strin return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "edgeRouterId": created.Payload.Data.ID, @@ -82,13 +82,13 @@ func (u *Importer) ProcessEdgeRouters(input map[string][]interface{}) (map[strin return result, nil } -func (u *Importer) lookupEdgeRouters(roles []string) ([]string, error) { +func (importer *Importer) lookupEdgeRouters(roles []string) ([]string, error) { edgeRouterRoles := []string{} for _, role := range roles { if role[0:1] == "@" { value := role[1:] - edgeRouter, _ := ascode.GetItemFromCache(u.edgeRouterCache, value, func(name string) (interface{}, error) { - return mgmt.EdgeRouterFromFilter(u.client, mgmt.NameFilter(name)), nil + edgeRouter, _ := ascode.GetItemFromCache(importer.edgeRouterCache, value, func(name string) (interface{}, error) { + return mgmt.EdgeRouterFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if edgeRouter == nil { return nil, errors.New("error reading EdgeRouter: " + value) diff --git a/ziti/cmd/ascode/importer/importer_external_jwt_signers.go b/ziti/cmd/ascode/importer/importer_external_jwt_signers.go index 848347235..6abdf40b1 100644 --- a/ziti/cmd/ascode/importer/importer_external_jwt_signers.go +++ b/ziti/cmd/ascode/importer/importer_external_jwt_signers.go @@ -25,7 +25,7 @@ import ( "slices" ) -func (u *Importer) IsExtJwtSignerImportRequired(args []string) bool { +func (importer *Importer) IsExtJwtSignerImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "ext-jwt-signer") || slices.Contains(args, "external-jwt-signer") || @@ -33,32 +33,32 @@ func (u *Importer) IsExtJwtSignerImportRequired(args []string) bool { slices.Contains(args, "identity") } -func (u *Importer) ProcessExternalJwtSigners(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessExternalJwtSigners(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["externalJwtSigners"] { create := FromMap(data, rest_model.ExternalJWTSignerCreate{}) // see if the signer already exists - existing := mgmt.ExternalJWTSignerFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ExternalJWTSignerFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "externalJwtSignerId": *existing.ID, }). Info("Found existing ExtJWTSigner, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping ExtJWTSigner %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping ExtJWTSigner %s\r", *create.Name) continue } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating ExtJWTSigner %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating ExtJWTSigner %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating ExtJWTSigner") } - created, createErr := u.client.ExternalJWTSigner.CreateExternalJWTSigner(&external_jwt_signer.CreateExternalJWTSignerParams{ExternalJWTSigner: create}, nil) + created, createErr := importer.client.ExternalJWTSigner.CreateExternalJWTSigner(&external_jwt_signer.CreateExternalJWTSignerParams{ExternalJWTSigner: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -73,7 +73,7 @@ func (u *Importer) ProcessExternalJwtSigners(input map[string][]interface{}) (ma return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "externalJwtSignerId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_identities.go b/ziti/cmd/ascode/importer/importer_identities.go index 0ea27fa2b..af7acd980 100644 --- a/ziti/cmd/ascode/importer/importer_identities.go +++ b/ziti/cmd/ascode/importer/importer_identities.go @@ -29,28 +29,28 @@ import ( "slices" ) -func (u *Importer) IsIdentityImportRequired(args []string) bool { +func (importer *Importer) IsIdentityImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "identity") } -func (u *Importer) ProcessIdentities(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessIdentities(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["identities"] { create := FromMap(data, rest_model.IdentityCreate{}) - existing := mgmt.IdentityFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.IdentityFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "identityId": *existing.ID, }). Info("Found existing Identity, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping Identity %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping Identity %s\r", *create.Name) continue } @@ -68,8 +68,8 @@ func (u *Importer) ProcessIdentities(input map[string][]interface{}) (map[string policyName := doc.Path("authPolicy").Data().(string)[1:] // look up the auth policy id from the name and add to the create, omit if it's the "Default" policy - policy, _ := ascode.GetItemFromCache(u.authPolicyCache, policyName, func(name string) (interface{}, error) { - return mgmt.AuthPolicyFromFilter(u.client, mgmt.NameFilter(name)), nil + policy, _ := ascode.GetItemFromCache(importer.authPolicyCache, policyName, func(name string) (interface{}, error) { + return mgmt.AuthPolicyFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if policy == nil { return nil, errors.New("error reading Auth Policy: " + policyName) @@ -79,8 +79,8 @@ func (u *Importer) ProcessIdentities(input map[string][]interface{}) (map[string } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating Identity %s\r", *create.Name) - created, createErr := u.client.Identity.CreateIdentity(&identity.CreateIdentityParams{Identity: create}, nil) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating Identity %s\r", *create.Name) + created, createErr := importer.client.Identity.CreateIdentity(&identity.CreateIdentityParams{Identity: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -94,7 +94,7 @@ func (u *Importer) ProcessIdentities(input map[string][]interface{}) (map[string return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "identityId": created.Payload.Data.ID, @@ -108,13 +108,13 @@ func (u *Importer) ProcessIdentities(input map[string][]interface{}) (map[string return result, nil } -func (u *Importer) lookupIdentities(roles []string) ([]string, error) { +func (importer *Importer) lookupIdentities(roles []string) ([]string, error) { identityRoles := []string{} for _, role := range roles { if role[0:1] == "@" { roleName := role[1:] - value, lookupErr := ascode.GetItemFromCache(u.identityCache, roleName, func(name string) (interface{}, error) { - return mgmt.IdentityFromFilter(u.client, mgmt.NameFilter(name)), nil + value, lookupErr := ascode.GetItemFromCache(importer.identityCache, roleName, func(name string) (interface{}, error) { + return mgmt.IdentityFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if lookupErr != nil { return nil, lookupErr diff --git a/ziti/cmd/ascode/importer/importer_posture_check.go b/ziti/cmd/ascode/importer/importer_posture_check.go index 20e35c71f..9e9472d0d 100644 --- a/ziti/cmd/ascode/importer/importer_posture_check.go +++ b/ziti/cmd/ascode/importer/importer_posture_check.go @@ -28,12 +28,12 @@ import ( "strings" ) -func (u *Importer) IsPostureCheckImportRequired(args []string) bool { +func (importer *Importer) IsPostureCheckImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "posture-check") } -func (u *Importer) ProcessPostureChecks(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessPostureChecks(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["postureChecks"] { @@ -70,9 +70,9 @@ func (u *Importer) ProcessPostureChecks(input map[string][]interface{}) (map[str } // see if the posture check already exists - existing := mgmt.PostureCheckFromFilter(u.client, mgmt.NameFilter(*create.Name())) + existing := mgmt.PostureCheckFromFilter(importer.client, mgmt.NameFilter(*create.Name())) if existing != nil { - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name(), "postureCheckId": (*existing).ID(), @@ -80,20 +80,20 @@ func (u *Importer) ProcessPostureChecks(input map[string][]interface{}) (map[str }). Info("Found existing PostureCheck, skipping create") } - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping PostureCheck %s\r", *create.Name()) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping PostureCheck %s\r", *create.Name()) continue } // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating PostureCheck %s\r", *create.Name()) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating PostureCheck %s\r", *create.Name()) + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name(), "typeId": create.TypeID(), }). Debug("Creating PostureCheck") } - created, createErr := u.client.PostureChecks.CreatePostureCheck(&posture_checks.CreatePostureCheckParams{PostureCheck: create}, nil) + created, createErr := importer.client.PostureChecks.CreatePostureCheck(&posture_checks.CreatePostureCheckParams{PostureCheck: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -106,7 +106,7 @@ func (u *Importer) ProcessPostureChecks(input map[string][]interface{}) (map[str return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name(), "postureCheckId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_service_edgerouter_policies.go b/ziti/cmd/ascode/importer/importer_service_edgerouter_policies.go index c85afb659..fa8293ee5 100644 --- a/ziti/cmd/ascode/importer/importer_service_edgerouter_policies.go +++ b/ziti/cmd/ascode/importer/importer_service_edgerouter_policies.go @@ -25,50 +25,50 @@ import ( "slices" ) -func (u *Importer) IsServiceEdgeRouterPolicyImportRequired(args []string) bool { +func (importer *Importer) IsServiceEdgeRouterPolicyImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service-edge-router-policy") } -func (u *Importer) ProcessServiceEdgeRouterPolicies(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessServiceEdgeRouterPolicies(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["serviceEdgeRouterPolicies"] { create := FromMap(data, rest_model.ServiceEdgeRouterPolicyCreate{}) // see if the service router policy already exists - existing := mgmt.ServiceEdgeRouterPolicyFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ServiceEdgeRouterPolicyFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { log.WithFields(map[string]interface{}{ "name": *create.Name, "serviceRouterPolicyId": *existing.ID, }). Info("Found existing ServiceEdgeRouterPolicy, skipping create") - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping ServiceEdgeRouterPolicy %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping ServiceEdgeRouterPolicy %s\r", *create.Name) continue } // look up the service ids from the name and add to the create - serviceRoles, err := u.lookupServices(create.ServiceRoles) + serviceRoles, err := importer.lookupServices(create.ServiceRoles) if err != nil { return nil, err } create.ServiceRoles = serviceRoles // look up the edgeRouter ids from the name and add to the create - edgeRouterRoles, err := u.lookupEdgeRouters(create.EdgeRouterRoles) + edgeRouterRoles, err := importer.lookupEdgeRouters(create.EdgeRouterRoles) if err != nil { return nil, err } create.EdgeRouterRoles = edgeRouterRoles // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating ServiceEdgeRouterPolicy %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating ServiceEdgeRouterPolicy %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name). Debug("Creating ServiceEdgeRouterPolicy") } - created, createErr := u.client.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(&service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{Policy: create}, nil) + created, createErr := importer.client.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(&service_edge_router_policy.CreateServiceEdgeRouterPolicyParams{Policy: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -82,7 +82,7 @@ func (u *Importer) ProcessServiceEdgeRouterPolicies(input map[string][]interface return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "serviceEdgeRouterPolicyId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_service_policies.go b/ziti/cmd/ascode/importer/importer_service_policies.go index e97db09a7..dd2458a31 100644 --- a/ziti/cmd/ascode/importer/importer_service_policies.go +++ b/ziti/cmd/ascode/importer/importer_service_policies.go @@ -26,49 +26,49 @@ import ( "slices" ) -func (u *Importer) IsServicePolicyImportRequired(args []string) bool { +func (importer *Importer) IsServicePolicyImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service-policy") } -func (u *Importer) ProcessServicePolicies(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessServicePolicies(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} for _, data := range input["servicePolicies"] { create := FromMap(data, rest_model.ServicePolicyCreate{}) // see if the service policy already exists - existing := mgmt.ServicePolicyFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ServicePolicyFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { log.WithFields(map[string]interface{}{ "name": *create.Name, "servicePolicyId": *existing.ID, }). Info("Found existing ServicePolicy, skipping create") - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping ServicePolicy %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping ServicePolicy %s\r", *create.Name) continue } // look up the service ids from the name and add to the create - serviceRoles, err := u.lookupServices(create.ServiceRoles) + serviceRoles, err := importer.lookupServices(create.ServiceRoles) if err != nil { return nil, err } create.ServiceRoles = serviceRoles // look up the identity ids from the name and add to the create - identityRoles, err := u.lookupIdentities(create.IdentityRoles) + identityRoles, err := importer.lookupIdentities(create.IdentityRoles) if err != nil { return nil, errors.Join(errors.New("Unable to read all identities from ServicePolicy"), err) } create.IdentityRoles = identityRoles // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping ServicePolicy %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping ServicePolicy %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating ServicePolicy") } - created, createErr := u.client.ServicePolicy.CreateServicePolicy(&service_policy.CreateServicePolicyParams{Policy: create}, nil) + created, createErr := importer.client.ServicePolicy.CreateServicePolicy(&service_policy.CreateServicePolicyParams{Policy: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -81,7 +81,7 @@ func (u *Importer) ProcessServicePolicies(input map[string][]interface{}) (map[s return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "servicePolicyId": created.Payload.Data.ID, diff --git a/ziti/cmd/ascode/importer/importer_services.go b/ziti/cmd/ascode/importer/importer_services.go index b1596b3a7..b00b76103 100644 --- a/ziti/cmd/ascode/importer/importer_services.go +++ b/ziti/cmd/ascode/importer/importer_services.go @@ -29,12 +29,12 @@ import ( "slices" ) -func (u *Importer) IsServiceImportRequired(args []string) bool { +func (importer *Importer) IsServiceImportRequired(args []string) bool { return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified slices.Contains(args, "service") } -func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]string, error) { +func (importer *Importer) ProcessServices(input map[string][]interface{}) (map[string]string, error) { var result = map[string]string{} @@ -42,14 +42,14 @@ func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]s create := FromMap(data, rest_model.ServiceCreate{}) // see if the service already exists - existing := mgmt.ServiceFromFilter(u.client, mgmt.NameFilter(*create.Name)) + existing := mgmt.ServiceFromFilter(importer.client, mgmt.NameFilter(*create.Name)) if existing != nil { log.WithFields(map[string]interface{}{ "name": *create.Name, "serviceId": *existing.ID, }). Info("Found existing Service, skipping create") - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Skipping Service %s\r", *create.Name) + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Skipping Service %s\r", *create.Name) continue } @@ -66,8 +66,8 @@ func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]s configIds := []string{} for _, configName := range configsNode.Children() { value := configName.Data().(string)[1:] - config, _ := ascode.GetItemFromCache(u.configCache, value, func(name string) (interface{}, error) { - return mgmt.ConfigFromFilter(u.client, mgmt.NameFilter(name)), nil + config, _ := ascode.GetItemFromCache(importer.configCache, value, func(name string) (interface{}, error) { + return mgmt.ConfigFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if config == nil { return nil, errors.New("error reading Config: " + value) @@ -77,11 +77,11 @@ func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]s create.Configs = configIds // do the actual create since it doesn't exist - _, _ = internal.FPrintfReusingLine(u.loginOpts.Err, "Creating Service %s\r", *create.Name) - if u.loginOpts.Verbose { + _, _ = internal.FPrintfReusingLine(importer.loginOpts.Err, "Creating Service %s\r", *create.Name) + if importer.loginOpts.Verbose { log.WithField("name", *create.Name).Debug("Creating Service") } - created, createErr := u.client.Service.CreateService(&service.CreateServiceParams{Service: create}, nil) + created, createErr := importer.client.Service.CreateService(&service.CreateServiceParams{Service: create}, nil) if createErr != nil { if payloadErr, ok := createErr.(rest_util.ApiErrorPayload); ok { log.WithFields(map[string]interface{}{ @@ -94,7 +94,7 @@ func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]s return nil, createErr } } - if u.loginOpts.Verbose { + if importer.loginOpts.Verbose { log.WithFields(map[string]interface{}{ "name": *create.Name, "serviceId": created.Payload.Data.ID, @@ -108,13 +108,13 @@ func (u *Importer) ProcessServices(input map[string][]interface{}) (map[string]s return result, nil } -func (u *Importer) lookupServices(roles []string) ([]string, error) { +func (importer *Importer) lookupServices(roles []string) ([]string, error) { serviceRoles := []string{} for _, role := range roles { if role[0:1] == "@" { value := role[1:] - service, _ := ascode.GetItemFromCache(u.serviceCache, value, func(name string) (interface{}, error) { - return mgmt.ServiceFromFilter(u.client, mgmt.NameFilter(name)), nil + service, _ := ascode.GetItemFromCache(importer.serviceCache, value, func(name string) (interface{}, error) { + return mgmt.ServiceFromFilter(importer.client, mgmt.NameFilter(name)), nil }) if service == nil { return nil, errors.New("error reading Service: " + value)