Skip to content

Commit

Permalink
Fix various golanci-lint errors (#1385)
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
  • Loading branch information
MrFreezeex committed Jun 21, 2022
1 parent 1e91d48 commit 9575669
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 59 deletions.
2 changes: 1 addition & 1 deletion openstack/compute_instance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func getInstanceAddresses(addresses map[string]interface{}) []InstanceAddresses
}

for _, networkName := range networkNames {
v, _ := addresses[networkName]
v := addresses[networkName]
instanceAddresses := InstanceAddresses{
NetworkName: networkName,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccBlockStorageV3AvailabilityZonesV3_basic(t *testing.T) {
{
Config: testAccBlockStorageV3AvailabilityZonesConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.openstack_blockstorage_availability_zones_v3.zones", "names.#", regexp.MustCompile("[1-9]\\d*")),
resource.TestMatchResourceAttr("data.openstack_blockstorage_availability_zones_v3.zones", "names.#", regexp.MustCompile(`[1-9]\d*`)),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccOpenStackAvailabilityZonesV2_basic(t *testing.T) {
{
Config: testAccOpenStackAvailabilityZonesConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.openstack_compute_availability_zones_v2.zones", "names.#", regexp.MustCompile("[1-9]\\d*")),
resource.TestMatchResourceAttr("data.openstack_compute_availability_zones_v2.zones", "names.#", regexp.MustCompile(`[1-9]\d*`)),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion openstack/data_source_openstack_keymanager_secret_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func dataSourceKeyManagerSecretV1Read(ctx context.Context, d *schema.ResourceDat
d.Set("content_types", secret.ContentTypes)

// don't fail, if the default key doesn't exist
payloadContentType, _ := secret.ContentTypes["default"]
payloadContentType := secret.ContentTypes["default"]
d.Set("payload_content_type", payloadContentType)

d.Set("payload", keyManagerSecretV1GetPayload(kmClient, d.Id()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccSFSV2AvailabilityZonesV2_basic(t *testing.T) {
{
Config: testAccSFSV2AvailabilityZonesConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.openstack_sharedfilesystem_availability_zones_v2.zones", "names.#", regexp.MustCompile("[1-9]\\d*")),
resource.TestMatchResourceAttr("data.openstack_sharedfilesystem_availability_zones_v2.zones", "names.#", regexp.MustCompile(`[1-9]\d*`)),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion openstack/db_configuration_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func expandDatabaseConfigurationV1Values(rawValues []interface{}) map[string]int
for _, rawValue := range rawValues {
v := rawValue.(map[string]interface{})
name := v["name"].(string)
value := v["value"].(interface{})
value := v["value"]

// check if value can be converted into int
if valueInt, err := strconv.Atoi(value.(string)); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion openstack/images_image_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func resourceImagesImageV2RefreshFunc(client *gophercloud.ServiceClient, id stri
}
log.Printf("[DEBUG] OpenStack image status is: %s", img.Status)

return img, fmt.Sprintf("%s", img.Status), nil
return img, string(img.Status), nil
}
}

Expand Down
10 changes: 2 additions & 8 deletions openstack/resource_openstack_blockstorage_volume_attach_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ func resourceBlockStorageVolumeAttachV2Create(ctx context.Context, d *schema.Res

if v, ok := d.GetOk("wwpns"); ok {
var wwpns []string
for _, i := range v.([]string) {
wwpns = append(wwpns, i)
}

wwpns = append(wwpns, v.([]string)...)
connOpts.Wwpns = wwpns
}

Expand Down Expand Up @@ -355,10 +352,7 @@ func resourceBlockStorageVolumeAttachV2Delete(ctx context.Context, d *schema.Res

if v, ok := d.GetOk("wwpns"); ok {
var wwpns []string
for _, i := range v.([]string) {
wwpns = append(wwpns, i)
}

wwpns = append(wwpns, v.([]string)...)
termOpts.Wwpns = wwpns
}

Expand Down
9 changes: 2 additions & 7 deletions openstack/resource_openstack_blockstorage_volume_attach_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ func resourceBlockStorageVolumeAttachV3Create(ctx context.Context, d *schema.Res

if v, ok := d.GetOk("wwpns"); ok {
var wwpns []string
for _, i := range v.([]string) {
wwpns = append(wwpns, i)
}
wwpns = append(wwpns, v.([]string)...)

connOpts.Wwpns = wwpns
}
Expand Down Expand Up @@ -348,10 +346,7 @@ func resourceBlockStorageVolumeAttachV3Delete(ctx context.Context, d *schema.Res

if v, ok := d.GetOk("wwpns"); ok {
var wwpns []string
for _, i := range v.([]string) {
wwpns = append(wwpns, i)
}

wwpns = append(wwpns, v.([]string)...)
termOpts.Wwpns = wwpns
}

Expand Down
8 changes: 4 additions & 4 deletions openstack/resource_openstack_compute_instance_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func resourceComputeInstanceV2() *schema.Resource {
ForceNew: true,
// just stash the hash for state & diff comparisons
StateFunc: func(v interface{}) string {
switch v.(type) {
switch v := v.(type) {
case string:
hash := sha1.Sum([]byte(v.(string)))
hash := sha1.Sum([]byte(v))
return hex.EncodeToString(hash[:])
default:
return ""
Expand Down Expand Up @@ -596,7 +596,7 @@ func resourceComputeInstanceV2Create(ctx context.Context, d *schema.ResourceData
MinTimeout: 3 * time.Second,
}

err = resource.Retry(stateConf.Timeout, func() *resource.RetryError {
err = resource.RetryContext(ctx, stateConf.Timeout, func() *resource.RetryError {
_, err = stateConf.WaitForStateContext(ctx)
if err != nil {
log.Printf("[DEBUG] Retrying after error: %s", err)
Expand Down Expand Up @@ -794,7 +794,7 @@ func resourceComputeInstanceV2Update(ctx context.Context, d *schema.ResourceData
}

log.Printf("[DEBUG] Waiting for instance (%s) to shelve", d.Id())
_, err = shelveStateConf.WaitForState()
_, err = shelveStateConf.WaitForStateContext(ctx)
if err != nil {
return diag.Errorf("Error waiting for instance (%s) to become shelve: %s", d.Id(), err)
}
Expand Down
9 changes: 4 additions & 5 deletions openstack/resource_openstack_compute_instance_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,23 +1485,22 @@ resource "openstack_compute_instance_v2" "instance_1" {
}

func testAccComputeV2InstanceNetworkModeAuto() string {
return fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
return `resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
network_mode = "auto"
}
`)
`
}

func testAccComputeV2InstanceNetworkModeNone() string {
return fmt.Sprintf(`
return `
resource "openstack_compute_instance_v2" "instance_1" {
name = "test-instance-1"
network_mode = "none"
}
`)
`
}

func testAccComputeV2InstanceNetworkNameToID() string {
Expand Down
2 changes: 1 addition & 1 deletion openstack/resource_openstack_dns_zone_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func resourceDNSZoneV2Create(ctx context.Context, d *schema.ResourceData, meta i
MinTimeout: 3 * time.Second,
}

err = resource.Retry(stateConf.Timeout, func() *resource.RetryError {
err = resource.RetryContext(ctx, stateConf.Timeout, func() *resource.RetryError {
_, err = stateConf.WaitForState()
if err != nil {
log.Printf("[DEBUG] Retrying after error: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestAccIdentityV3ApplicationCredential_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"openstack_identity_application_credential_v3.app_cred_1", "expires_at", ""),
resource.TestMatchResourceAttr(
"openstack_identity_application_credential_v3.app_cred_1", "roles.#", regexp.MustCompile("^[2-9]\\d*")),
"openstack_identity_application_credential_v3.app_cred_1", "roles.#", regexp.MustCompile(`^[2-9]\d*`)),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func testAccCheckIdentityV3RoleAssignmentExists(n string, role *roles.Role, user
return fmt.Errorf("Error determining openstack_identity_role_assignment_v3 ID: %s", err)
}

var opts roles.ListAssignmentsOpts
opts = roles.ListAssignmentsOpts{
var opts = roles.ListAssignmentsOpts{
GroupID: groupID,
ScopeDomainID: domainID,
ScopeProjectID: projectID,
Expand Down
10 changes: 3 additions & 7 deletions openstack/resource_openstack_keymanager_secret_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ func resourceKeyManagerSecretV1() *schema.Resource {
ForceNew: true,
Computed: true,
DiffSuppressFunc: func(k, o, n string, d *schema.ResourceData) bool {
if strings.TrimSpace(o) == strings.TrimSpace(n) {
return true
}
return false
return strings.TrimSpace(o) == strings.TrimSpace(n)
},
},

Expand Down Expand Up @@ -262,8 +259,7 @@ func resourceKeyManagerSecretV1Create(ctx context.Context, d *schema.ResourceDat
}

// set the metadata
var metadataCreateOpts secrets.MetadataOpts
metadataCreateOpts = flattenKeyManagerSecretV1Metadata(d)
var metadataCreateOpts secrets.MetadataOpts = flattenKeyManagerSecretV1Metadata(d)

log.Printf("[DEBUG] Metadata Create Options for resource_keymanager_secret_metadata_v1 %s: %#v", uuid, metadataCreateOpts)

Expand Down Expand Up @@ -321,7 +317,7 @@ func resourceKeyManagerSecretV1Read(ctx context.Context, d *schema.ResourceData,
d.Set("content_types", secret.ContentTypes)

// don't fail, if the default key doesn't exist
payloadContentType, _ := secret.ContentTypes["default"]
payloadContentType := secret.ContentTypes["default"]
d.Set("payload_content_type", payloadContentType)

d.Set("payload", keyManagerSecretV1GetPayload(kmClient, d.Id()))
Expand Down
2 changes: 1 addition & 1 deletion openstack/resource_openstack_lb_l7policy_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func resourceL7PolicyV2Create(ctx context.Context, d *schema.ResourceData, meta

log.Printf("[DEBUG] Attempting to create L7 Policy")
var l7Policy *l7policies.L7Policy
err = resource.Retry(timeout, func() *resource.RetryError {
err = resource.RetryContext(ctx, timeout, func() *resource.RetryError {
l7Policy, err = l7policies.Create(lbClient, createOpts).Extract()
if err != nil {
return checkForRetryableError(err)
Expand Down
2 changes: 1 addition & 1 deletion openstack/resource_openstack_lb_vip_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func resourceLBVipV1Delete(ctx context.Context, d *schema.ResourceData, meta int
}

func resourceVipPersistenceV1(d *schema.ResourceData) *vips.SessionPersistence {
rawP := d.Get("persistence").(interface{})
rawP := d.Get("persistence")
rawMap := rawP.(map[string]interface{})
if len(rawMap) != 0 {
p := vips.SessionPersistence{}
Expand Down
4 changes: 1 addition & 3 deletions openstack/resource_openstack_sharedfilesystem_share_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,7 @@ func resourceSharedFilesystemShareV2Update(ctx context.Context, d *schema.Resour

// Remove already removed metadata from the update list
for oldKey := range metadataToDelete {
if _, ok := metadataToUpdate[oldKey]; ok {
delete(metadataToUpdate, oldKey)
}
delete(metadataToUpdate, oldKey)
}

log.Printf("[DEBUG] Updating the following items in metadata for openstack_sharedfilesystem_share_v2 %s: %v", d.Id(), metadataToUpdate)
Expand Down
3 changes: 1 addition & 2 deletions openstack/resource_openstack_vpnaas_endpoint_group_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func resourceEndpointGroupV2Update(ctx context.Context, d *schema.ResourceData,
hasChange = true
}

var updateOpts endpointgroups.UpdateOptsBuilder
updateOpts = opts
var updateOpts endpointgroups.UpdateOptsBuilder = opts

log.Printf("[DEBUG] Updating endpoint group with id %s: %#v", d.Id(), updateOpts)

Expand Down
3 changes: 1 addition & 2 deletions openstack/resource_openstack_vpnaas_ike_policy_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ func resourceIKEPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta i
d.Set("region", GetRegion(d, config))

// Set the lifetime
var lifetimeMap map[string]interface{}
lifetimeMap = make(map[string]interface{})
var lifetimeMap = make(map[string]interface{})
lifetimeMap["units"] = policy.Lifetime.Units
lifetimeMap["value"] = policy.Lifetime.Value
var lifetime []map[string]interface{}
Expand Down
3 changes: 1 addition & 2 deletions openstack/resource_openstack_vpnaas_ipsec_policy_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ func resourceIPSecPolicyV2Read(ctx context.Context, d *schema.ResourceData, meta
d.Set("region", GetRegion(d, config))

// Set the lifetime
var lifetimeMap map[string]interface{}
lifetimeMap = make(map[string]interface{})
var lifetimeMap = make(map[string]interface{})
lifetimeMap["units"] = policy.Lifetime.Units
lifetimeMap["value"] = policy.Lifetime.Value
var lifetime []map[string]interface{}
Expand Down
3 changes: 1 addition & 2 deletions openstack/resource_openstack_vpnaas_service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ func resourceServiceV2Update(ctx context.Context, d *schema.ResourceData, meta i
hasChange = true
}

var updateOpts services.UpdateOptsBuilder
updateOpts = opts
var updateOpts services.UpdateOptsBuilder = opts

log.Printf("[DEBUG] Updating service with id %s: %#v", d.Id(), updateOpts)

Expand Down
6 changes: 2 additions & 4 deletions openstack/resource_openstack_vpnaas_site_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ func resourceSiteConnectionV2Read(ctx context.Context, d *schema.ResourceData, m
d.Set("peer_cidrs", conn.PeerCIDRs)

// Set the dpd
var dpdMap map[string]interface{}
dpdMap = make(map[string]interface{})
var dpdMap = make(map[string]interface{})
dpdMap["action"] = conn.DPD.Action
dpdMap["interval"] = conn.DPD.Interval
dpdMap["timeout"] = conn.DPD.Timeout
Expand Down Expand Up @@ -344,8 +343,7 @@ func resourceSiteConnectionV2Update(ctx context.Context, d *schema.ResourceData,
hasChange = true
}

var updateOpts siteconnections.UpdateOptsBuilder
updateOpts = opts
var updateOpts siteconnections.UpdateOptsBuilder = opts

log.Printf("[DEBUG] Updating site connection with id %s: %#v", d.Id(), updateOpts)

Expand Down

0 comments on commit 9575669

Please sign in to comment.