Skip to content

Commit

Permalink
refactor: Fix/ignore linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adeatcu-ionos committed Jan 29, 2025
1 parent 4210c7f commit da4bcd6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
5 changes: 3 additions & 2 deletions ionoscloud/data_source_container_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/data_source_container_registry_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion services/containerregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
48 changes: 23 additions & 25 deletions services/containerregistry/registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Expand Down Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion utils/constant/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit da4bcd6

Please sign in to comment.