From da4bcd64eb3a65bd6b7056ce8e10fafd2ad28b2e Mon Sep 17 00:00:00 2001 From: adeatcu-ionos Date: Tue, 28 Jan 2025 17:40:53 +0200 Subject: [PATCH] refactor: Fix/ignore linter errors --- ionoscloud/data_source_container_registry.go | 5 +- .../data_source_container_registry_token.go | 2 +- services/containerregistry/client.go | 2 +- services/containerregistry/registries.go | 48 +++++++++---------- utils/constant/constants.go | 2 +- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/ionoscloud/data_source_container_registry.go b/ionoscloud/data_source_container_registry.go index 587f230f3..d11888279 100644 --- a/ionoscloud/data_source_container_registry.go +++ b/ionoscloud/data_source_container_registry.go @@ -120,6 +120,7 @@ func dataSourceContainerRegistry() *schema.Resource { } } +//nolint:gocyclo func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(services.SdkBundle).ContainerClient @@ -173,7 +174,7 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData registriesByName = append(registriesByName, registryItem) } } - if registriesByName != nil && len(registriesByName) > 0 { + if len(registriesByName) > 0 { results = registriesByName } else { return diag.FromErr(fmt.Errorf("no registry found with the specified criteria: name = %v", name)) @@ -188,7 +189,7 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData registriesByLocation = append(registriesByLocation, registryItem) } } - if registriesByLocation != nil && len(registriesByLocation) > 0 { + if len(registriesByLocation) > 0 { results = registriesByLocation } else { return diag.FromErr(fmt.Errorf("no registry found with the specified criteria: location = %v", location)) diff --git a/ionoscloud/data_source_container_registry_token.go b/ionoscloud/data_source_container_registry_token.go index 033eef8fe..666959365 100644 --- a/ionoscloud/data_source_container_registry_token.go +++ b/ionoscloud/data_source_container_registry_token.go @@ -138,7 +138,7 @@ func dataSourceContainerRegistryTokenRead(ctx context.Context, d *schema.Resourc } } - if results == nil || len(results) == 0 { + if len(results) == 0 { return diag.FromErr(fmt.Errorf("no token found with the specified name = %s", name)) } else if len(results) > 1 { return diag.FromErr(fmt.Errorf("more than one token found with the specified criteria: name = %s", name)) diff --git a/services/containerregistry/client.go b/services/containerregistry/client.go index e085d977d..de0793bd7 100644 --- a/services/containerregistry/client.go +++ b/services/containerregistry/client.go @@ -25,7 +25,7 @@ func NewClient(username, password, token, url, version, terraformVersion string, newConfigRegistry.MaxWaitTime = constant.MaxWaitTime newConfigRegistry.UserAgent = fmt.Sprintf( "terraform-provider/%s_ionos-cloud-sdk-go-container-cr/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s", - version, cr.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) + version, cr.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) //nolint:staticcheck client := &Client{ sdkClient: *cr.NewAPIClient(newConfigRegistry), } diff --git a/services/containerregistry/registries.go b/services/containerregistry/registries.go index 4b6cbf362..bfb7a1e6d 100644 --- a/services/containerregistry/registries.go +++ b/services/containerregistry/registries.go @@ -364,35 +364,33 @@ func GetScopes(d *schema.ResourceData) []cr.Scope { if scopeValue, ok := d.GetOk("scopes"); ok { scopeValue := scopeValue.([]interface{}) - if scopeValue != nil { - for _, item := range scopeValue { - - scopeContent := item.(map[string]interface{}) - connection := cr.Scope{} - - if actions, ok := scopeContent["actions"]; ok { - actions := actions.([]interface{}) - var actionsToAdd []string - if actions != nil && len(actions) > 0 { - for _, action := range actions { - actionsToAdd = append(actionsToAdd, action.(string)) - } - } - connection.Actions = actionsToAdd - } + for _, item := range scopeValue { - if name, ok := scopeContent["name"]; ok { - name := name.(string) - connection.Name = name - } + scopeContent := item.(map[string]interface{}) + connection := cr.Scope{} - if scopeType, ok := scopeContent["type"]; ok { - scopeType := scopeType.(string) - connection.Type = scopeType + if actions, ok := scopeContent["actions"]; ok { + actions := actions.([]interface{}) + var actionsToAdd []string + if len(actions) > 0 { + for _, action := range actions { + actionsToAdd = append(actionsToAdd, action.(string)) + } } + connection.Actions = actionsToAdd + } + + if name, ok := scopeContent["name"]; ok { + name := name.(string) + connection.Name = name + } - scopes = append(scopes, connection) + if scopeType, ok := scopeContent["type"]; ok { + scopeType := scopeType.(string) + connection.Type = scopeType } + + scopes = append(scopes, connection) } } @@ -451,7 +449,7 @@ func SetCredentials(credentials cr.Credentials) map[string]interface{} { //nolint:golint func SetScopes(scopes []cr.Scope) []interface{} { - var tokenScopes []interface{} + var tokenScopes []interface{} //nolint:prealloc for _, scope := range scopes { scopeEntry := make(map[string]interface{}) diff --git a/utils/constant/constants.go b/utils/constant/constants.go index 720089f88..3a73d09dd 100644 --- a/utils/constant/constants.go +++ b/utils/constant/constants.go @@ -334,7 +334,7 @@ const ( DataplatformNodePoolsTestDataSource = "test_dataplatform_node_pools" DataplatformVersionsTestDataSource = "test_dataplatform_versions" // DataPlatformVersion lowest 'available' version is now 24.3 - DataPlatformVersion = "24.3" + DataPlatformVersion = "24.11" DataPlatformNameRegexConstraint = "^[A-Za-z0-9][-A-Za-z0-9_.]*[A-Za-z0-9]$" DataPlatformRegexNameError = "name should match " + DataPlatformNameRegexConstraint )