Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Dec 9, 2024
1 parent 5738ab2 commit 6881987
Show file tree
Hide file tree
Showing 37 changed files with 313 additions and 341 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ linters:
- unused
- staticcheck
- deadcode
- ifElseChain

issues:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func Provider() *schema.Provider {
"nutanix_volume_group_v2": volumesv2.ResourceNutanixVolumeGroupV2(),
"nutanix_volume_group_disk_v2": volumesv2.ResourceNutanixVolumeGroupDiskV2(),
"nutanix_volume_group_iscsi_client_v2": volumesv2.ResourceNutanixVolumeGroupIscsiClientV2(),
"nutanix_volume_group_vm_v2": volumesv2.ResourceNutanixVolumeAttachVmToVolumeGroupV2(),
"nutanix_volume_group_vm_v2": volumesv2.ResourceNutanixVolumeAttachVMToVolumeGroupV2(),
"nutanix_recovery_points_v2": dataprotectionv2.ResourceNutanixRecoveryPointsV2(),
"nutanix_recovery_point_replicate_v2": dataprotectionv2.ResourceNutanixRecoveryPointReplicateV2(),
"nutanix_recovery_point_restore_v2": dataprotectionv2.ResourceNutanixRecoveryPointRestoreV2(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,13 +897,10 @@ func flattenProxyTypes(proxyTypes []import1.HttpProxyType) []interface{} {
switch v {
case HTTP:
types[k] = "HTTP"
break
case HTTPS:
types[k] = "HTTPS"
break
case SOCKS:
types[k] = "SOCKS"
break
default:
types[k] = "UNKNOWN"
}
Expand Down Expand Up @@ -1015,13 +1012,10 @@ func flattenSMTPServerRef(pr *import1.SmtpServerRef) []map[string]interface{} {
switch *pr.Type {
case PLAIN:
s["type"] = "PLAIN"
break
case STARTTLS:
s["type"] = "STARTTLS"
break
case SSL:
s["type"] = "SSL"
break
default:
s["type"] = "UNKNOWN"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,13 +1023,13 @@ func expandDetails(pr interface{}) *config.UserInfo {

func expandHypervisorType(hypervisorType interface{}) *config.HypervisorType {
if hypervisorType != nil && hypervisorType != "" {

const two, three, four, five, six = 2, 3, 4, 5, 6
subMap := map[string]interface{}{
"AHV": 2,
"ESX": 3,
"HYPERV": 4,
"XEN": 5,
"NATIVEHOST": 6,
"AHV": two,
"ESX": three,
"HYPERV": four,
"XEN": five,
"NATIVEHOST": six,
}
pVal := subMap[hypervisorType.(string)]
if pVal == nil {
Expand Down
71 changes: 42 additions & 29 deletions nutanix/services/clustersv2/resource_nutanix_cluster_entity_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)

const (
CANCELED = "CANCELLED"
)

func ResourceNutanixClusterV2() *schema.Resource {
return &schema.Resource{
CreateContext: ResourceNutanixClusterV2Create,
Expand Down Expand Up @@ -980,6 +984,9 @@ func ResourceNutanixClusterV2Update(ctx context.Context, d *schema.ResourceData,
}

resourceUUID, err := taskconn.TaskRefAPI.GetTaskById(taskUUID, nil)
if err != nil {
return diag.Errorf("error while updating clusters : %v", err)
}

if _, errWaitTask := stateConf.WaitForStateContext(ctx); errWaitTask != nil {
return diag.Errorf("error waiting for cluster (%s) to update: %s", utils.StringValue(taskUUID), errWaitTask)
Expand Down Expand Up @@ -1166,7 +1173,7 @@ func expandUpgradeStatus(upgradeStatus interface{}) *config.UpgradeStatus {
"UPGRADING": six,
"SUCCEEDED": seven,
"FAILED": eight,
"CANCELLED": nine,
CANCELED: nine,
"SCHEDULED": ten,
}
if subMap[upgradeStatus.(string)] != nil {
Expand Down Expand Up @@ -1406,9 +1413,10 @@ func expandClusterConfigReference(pr interface{}, d *schema.ResourceData) *confi
clsConf.RedundancyFactor = utils.Int64Ptr(int64(redundancyFactor.(int)))
}
if clusterArch, ok := val["cluster_arch"]; ok && d.HasChange("config.0.cluster_arch") {
const two, three = 2, 3
subMap := map[string]interface{}{
"X86_64": 2,
"PPC64LE": 3,
"X86_64": two,
"PPC64LE": three,
}
if subMap[clusterArch.(string)] != nil {
pVal := subMap[clusterArch.(string)]
Expand All @@ -1420,12 +1428,13 @@ func expandClusterConfigReference(pr interface{}, d *schema.ResourceData) *confi
clsConf.FaultToleranceState = expandFaultToleranceState(faultToleranceState)
}
if operationMode, ok := val["operation_mode"]; ok && d.HasChange("config.0.operation_mode") {
const two, three, four, five, six = 2, 3, 4, 5, 6
subMap := map[string]interface{}{
"NORMAL": 2,
"READ_ONLY": 3,
"STAND_ALONE": 4,
"SWITCH_TO_TWO_NODE": 5,
"OVERRIDE": 6,
"NORMAL": two,
"READ_ONLY": three,
"STAND_ALONE": four,
"SWITCH_TO_TWO_NODE": five,
"OVERRIDE": six,
}
if subMap[operationMode.(string)] != nil {
pVal := subMap[operationMode.(string)]
Expand All @@ -1434,9 +1443,10 @@ func expandClusterConfigReference(pr interface{}, d *schema.ResourceData) *confi
}
}
if encryptionInTransitStatus, ok := val["encryption_in_transit_status"]; ok && d.HasChange("config.0.encryption_in_transit_status") {
const two, three = 2, 3
subMap := map[string]interface{}{
"ENABLED": 2,
"DISABLED": 3,
"ENABLED": two,
"DISABLED": three,
}

if subMap[encryptionInTransitStatus.(string)] != nil {
Expand Down Expand Up @@ -1595,10 +1605,11 @@ func expandSMTPServerRef(pr interface{}) *config.SmtpServerRef {
smtp.Server = expandSMTPNetwork(server.([]interface{}))
}
if smtpType, ok := val["type"]; ok {
const two, three, four = 2, 3, 4
subMap := map[string]interface{}{
"PLAIN": 2,
"STARTTLS": 3,
"SSL": 4,
"PLAIN": two,
"STARTTLS": three,
"SSL": four,
}
if subMap[smtpType.(string)] != nil {
pVal := subMap[smtpType.(string)]
Expand Down Expand Up @@ -1647,16 +1658,16 @@ func expandManagementServerRef(pr interface{}) *config.ManagementServerRef {
val := prI[0].(map[string]interface{})

if ip, ok := val["ip"]; ok {
log.Printf("[DEBUG] managment server ip")
log.Printf("[DEBUG] management server ip")
mgm.Ip = expandIPAddress(ip.([]interface{}))
}
if mgmType, ok := val["type"]; ok {
const two = 2
switch mgmType.(string) {
case "VCENTER":
p := config.ManagementServerType(2)
p := config.ManagementServerType(two)
mgm.Type = &p
log.Printf("[DEBUG] mgmType : VCENTER case")
break
default:
log.Printf("[DEBUG] mgmType : default case")
mgm.Type = nil
Expand Down Expand Up @@ -1776,11 +1787,12 @@ func expandFaultToleranceState(pr interface{}) *config.FaultToleranceState {
val := prI[0].(map[string]interface{})

if domainAwarenessLevel, ok := val["domain_awareness_level"]; ok {
const two, three, four, five = 2, 3, 4, 5
subMap := map[string]interface{}{
"NODE": 2,
"BLOCK": 3,
"RACK": 4,
"DISK": 5,
"NODE": two,
"BLOCK": three,
"RACK": four,
"DISK": five,
}
if subMap[domainAwarenessLevel.(string)] != nil {
pVal := subMap[domainAwarenessLevel.(string)]
Expand All @@ -1790,11 +1802,12 @@ func expandFaultToleranceState(pr interface{}) *config.FaultToleranceState {
}

if currentClusterFaultTolerance, ok := val["current_cluster_fault_tolerance"]; ok {
const two, three, four, five = 2, 3, 4, 5
subMap := map[string]interface{}{
"CFT_0N_AND_0D": 2,
"CFT_1N_OR_1D": 3,
"CFT_2N_OR_2D": 4,
"CFT_1N_AND_1D": 5,
"CFT_0N_AND_0D": two,
"CFT_1N_OR_1D": three,
"CFT_2N_OR_2D": four,
"CFT_1N_AND_1D": five,
}
if subMap[currentClusterFaultTolerance.(string)] != nil {
pVal := subMap[currentClusterFaultTolerance.(string)]
Expand All @@ -1804,12 +1817,12 @@ func expandFaultToleranceState(pr interface{}) *config.FaultToleranceState {

}
if desiredClusterFaultTolerance, ok := val["desired_cluster_fault_tolerance"]; ok {

const two, three, four, five = 2, 3, 4, 5
subMap := map[string]interface{}{
"CFT_0N_AND_0D": 2,
"CFT_1N_OR_1D": 3,
"CFT_2N_OR_2D": 4,
"CFT_1N_AND_1D": 5,
"CFT_0N_AND_0D": two,
"CFT_1N_OR_1D": three,
"CFT_2N_OR_2D": four,
"CFT_1N_AND_1D": five,
}
if subMap[desiredClusterFaultTolerance.(string)] != nil {
pVal := subMap[desiredClusterFaultTolerance.(string)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func ResourceNutanixClusterPCRegistrationV2Create(ctx context.Context, d *schema
rUUID := resourceUUID.Data.GetValue().(prismConfig.Task)

aJson, _ = json.Marshal(rUUID)
log.Printf("[DEBUG] PC Regestration Task Details: %s", string(aJson))
log.Printf("[DEBUG] PC Registration Task Details: %s", string(aJson))

d.SetId(pcExtID)
return ResourceNutanixClusterPCRegistrationV2Read(ctx, d, meta)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

const resourceNameRecoveryPointReplicate = "nutanix_recovery_point_replicate_v2.test"
const resourceNameCluster = "nutanix_cluster_v2.test"

func TestAccNutanixRecoveryPointReplicateV2Resource_basic(t *testing.T) {
r := acctest.RandInt()
Expand Down
7 changes: 4 additions & 3 deletions nutanix/services/iamv2/data_source_nutanix_operation_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ func DatasourceNutanixOperationV4Read(ctx context.Context, d *schema.ResourceDat

func flattenOperationType(pr *import1.OperationType) string {
if pr != nil {
if *pr == import1.OperationType(2) {
const two, three, four = 2, 3, 4
if *pr == import1.OperationType(two) {
return "INTERNAL"
}
if *pr == import1.OperationType(3) {
if *pr == import1.OperationType(three) {
return "SYSTEM_DEFINED_ONLY"
}
if *pr == import1.OperationType(4) {
if *pr == import1.OperationType(four) {
return "EXTERNAL"
}
}
Expand Down
15 changes: 6 additions & 9 deletions nutanix/services/iamv2/data_source_nutanix_roles_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ func DatasourceNutanixRolesV2() *schema.Resource {
Optional: true,
},
"filter": {
Description: "A URL query parameter that allows clients to filter a collection of resources. The expression specified with $filter is evaluated for each resource in the collection, and only items where the expression evaluates to true are included in the response. Expression specified with the $filter must conform to the OData V4.01 URL conventions. For example, filter '$filter=name eq 'karbon-ntnx-1.0' would filter the result on cluster name 'karbon-ntnx1.0', filter '$filter=startswith(name, 'C')' would filter on cluster name starting with 'C'. The filter can be applied to the following fields: clientName, createdBy, createdTime, displayName, extId, isSystemDefined, lastUpdatedTime",
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
},
"order_by": {
Description: "A URL query parameter that allows clients to specify the sort criteria for the returned list of objects. Resources can be sorted in ascending order using asc or descending order using desc. If asc or desc are not specified, the resources will be sorted in ascending order by default. For example, '$orderby=templateName desc' would get all templates sorted by templateName in descending order. The orderby can be applied to the following fields: clientName, displayName, extId, lastUpdatedTime",
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
},
"select": {
Description: "A URL query parameter that allows clients to request a specific set of properties for each entity or complex type. Expression specified with the $select must conform to the OData V4.01 URL conventions. If a $select expression consists of a single select item that is an asterisk (i.e., *), then all properties on the matching resource will be returned. The select can be applied to the following fields: accessibleClients, accessibleEntityTypes, assignedUserGroupsCount, assignedUsersCount, clientName, createdBy, createdTime, description, displayName, extId, isSystemDefined, lastUpdatedTime, links, operations, tenantId",
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
},
"roles": {
Type: schema.TypeList,
Expand Down
5 changes: 3 additions & 2 deletions nutanix/services/iamv2/data_source_nutanix_user_group_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ func DatasourceNutanixUserGroupV4Read(ctx context.Context, d *schema.ResourceDat

func flattenGroupType(pr *import1.GroupType) string {
if pr != nil {
if *pr == import1.GroupType(2) {
const two, three = 2, 3
if *pr == import1.GroupType(two) {
return "SAML"
}
if *pr == import1.GroupType(3) {
if *pr == import1.GroupType(three) {
return "LDAP"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ func DatasourceNutanixStorageStatsInfoV2Read(ctx context.Context, d *schema.Reso
return diag.Errorf("sampling_interval should be greater than 0")
}

const seven = 7
const two, three, four, five, six, seven = 2, 3, 4, 5, 6, 7
statType := clsstats.DownSamplingOperator(seven) // Default value is LAST, Aggregation containing only the last recorded value.

subMap := map[string]interface{}{
"SUM": 2,
"MIN": 3,
"MAX": 4,
"AVG": 5,
"COUNT": 6,
"LAST": 7,
"SUM": two,
"MIN": three,
"MAX": four,
"AVG": five,
"COUNT": six,
"LAST": seven,
}
pVal := subMap[d.Get("stat_type").(string)]
if pVal != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func ResourceNutanixStorageContainersV2Create(ctx context.Context, d *schema.Res
body.IsInlineEcEnabled = utils.BoolPtr(bool(isInlineEcEnabled.(bool)))
}
if hasHigherEcFaultDomainPreference, ok := d.GetOk("has_higher_ec_fault_domain_preference"); ok {
body.HasHigherEcFaultDomainPreference = utils.BoolPtr(bool(hasHigherEcFaultDomainPreference.(bool)))
body.HasHigherEcFaultDomainPreference = utils.BoolPtr(hasHigherEcFaultDomainPreference.(bool))
}
if erasureCodeDelaySecs, ok := d.GetOk("erasure_code_delay_secs"); ok {
body.ErasureCodeDelaySecs = utils.IntPtr(int(erasureCodeDelaySecs.(int)))
Expand All @@ -264,7 +264,7 @@ func ResourceNutanixStorageContainersV2Create(ctx context.Context, d *schema.Res
body.OnDiskDedup = &p
}
if isCompressionEnabled, ok := d.GetOk("is_compression_enabled"); ok {
body.IsCompressionEnabled = utils.BoolPtr(bool(isCompressionEnabled.(bool)))
body.IsCompressionEnabled = utils.BoolPtr(isCompressionEnabled.(bool))
}
if compressionDelaySecs, ok := d.GetOk("compression_delay_secs"); ok {
body.CompressionDelaySecs = utils.IntPtr(int(compressionDelaySecs.(int)))
Expand All @@ -273,7 +273,7 @@ func ResourceNutanixStorageContainersV2Create(ctx context.Context, d *schema.Res
body.IsInternal = utils.BoolPtr(bool(isInternal.(bool)))
}
if isSoftwareEncryptionEnabled, ok := d.GetOk("is_software_encryption_enabled"); ok {
body.IsSoftwareEncryptionEnabled = utils.BoolPtr(bool(isSoftwareEncryptionEnabled.(bool)))
body.IsSoftwareEncryptionEnabled = utils.BoolPtr(isSoftwareEncryptionEnabled.(bool))
}
if affinityHostExtId, ok := d.GetOk("affinity_host_ext_id"); ok {
body.AffinityHostExtId = utils.StringPtr(affinityHostExtId.(string))
Expand Down Expand Up @@ -665,20 +665,21 @@ func taskStateRefreshPrismTaskGroupFunc(ctx context.Context, client *prism.Clien
}

func getTaskStatus(pr *prismConfig.TaskStatus) string {
const two, three, five, six, seven = 2, 3, 5, 6, 7
if pr != nil {
if *pr == prismConfig.TaskStatus(6) {
if *pr == prismConfig.TaskStatus(six) {
return "FAILED"
}
if *pr == prismConfig.TaskStatus(7) {
if *pr == prismConfig.TaskStatus(seven) {
return "CANCELED"
}
if *pr == prismConfig.TaskStatus(2) {
if *pr == prismConfig.TaskStatus(two) {
return "QUEUED"
}
if *pr == prismConfig.TaskStatus(3) {
if *pr == prismConfig.TaskStatus(three) {
return "RUNNING"
}
if *pr == prismConfig.TaskStatus(5) {
if *pr == prismConfig.TaskStatus(five) {
return "SUCCEEDED"
}
}
Expand Down
4 changes: 2 additions & 2 deletions nutanix/services/vmmv2/data_source_nutanix_image_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func flattenOneOfImageSource(pr *import5.OneOfImageSource) []map[string]interfac
urlSrcObj["url"] = urlSrc.Url
}
if urlSrc.BasicAuth != nil {
urlSrcObj["basic_auth"] = flattenUrlBasicAuth(urlSrc.BasicAuth)
urlSrcObj["basic_auth"] = flattenURLBasicAuth(urlSrc.BasicAuth)
}
if urlSrc.ShouldAllowInsecureUrl != nil {
urlSrcObj["should_allow_insecure_url"] = urlSrc.ShouldAllowInsecureUrl
Expand Down Expand Up @@ -353,7 +353,7 @@ func flattenOneOfImageSource(pr *import5.OneOfImageSource) []map[string]interfac
return nil
}

func flattenUrlBasicAuth(pr *import5.UrlBasicAuth) []map[string]interface{} {
func flattenURLBasicAuth(pr *import5.UrlBasicAuth) []map[string]interface{} {
if pr != nil {
auths := make([]map[string]interface{}, 0)

Expand Down
Loading

0 comments on commit 6881987

Please sign in to comment.