Skip to content

Commit

Permalink
Fix intial linting warnings: gofmt, vet, errcheck, interfacer, struct…
Browse files Browse the repository at this point in the history
…check
  • Loading branch information
katbyte committed Oct 19, 2018
1 parent 2d4d75b commit 8cf9f80
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ install:
# packages that live there.
# See: https://github.com/golang/go/issues/12933
- bash scripts/gogetcookie.sh
make tools
- make tools

script:
make lint
- make lint
- make test
- make vendor-status
- make website-test
Expand Down
3 changes: 1 addition & 2 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ type ArmClient struct {
secGroupClient network.SecurityGroupsClient
secRuleClient network.SecurityRulesClient
subnetClient network.SubnetsClient
netUsageClient network.UsagesClient
vnetGatewayConnectionsClient network.VirtualNetworkGatewayConnectionsClient
vnetGatewayClient network.VirtualNetworkGatewaysClient
vnetClient network.VirtualNetworksClient
Expand Down Expand Up @@ -978,7 +977,7 @@ func (c *ArmClient) registerNetworkingClients(endpoint, subscriptionId string, a
c.watcherClient = watchersClient
}

func (c *ArmClient) registerNotificationHubsClient(endpoint, subscriptionId string, auth *autorest.BearerAuthorizer, sender autorest.Sender) {
func (c *ArmClient) registerNotificationHubsClient(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
namespacesClient := notificationhubs.NewNamespacesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&namespacesClient.Client, auth)
c.notificationNamespacesClient = namespacesClient
Expand Down
4 changes: 2 additions & 2 deletions azurerm/logic_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func testCheckAzureRMLogicAppActionExists(name string) resource.TestCheckFunc {
actions := definition["actions"].(map[string]interface{})

exists := false
for k, _ := range actions {
for k := range actions {
if strings.EqualFold(k, actionName) {
exists = true
break
Expand Down Expand Up @@ -90,7 +90,7 @@ func testCheckAzureRMLogicAppTriggerExists(name string) resource.TestCheckFunc {
triggers := definition["triggers"].(map[string]interface{})

exists := false
for k, _ := range triggers {
for k := range triggers {
if strings.EqualFold(k, triggerName) {
exists = true
break
Expand Down
4 changes: 3 additions & 1 deletion azurerm/resource_arm_automation_dsc_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func resourceArmAutomationDscConfigurationRead(d *schema.ResourceData, meta inte
}

buf := new(bytes.Buffer)
buf.ReadFrom(contentresp.Body)
if _, err := buf.ReadFrom(contentresp.Body); err != nil {
return fmt.Errorf("Error reading from AzureRM Automation Dsc Configuration buffer %q: %+v", name, err)
}
content := buf.String()

d.Set("content_embedded", content)
Expand Down
4 changes: 3 additions & 1 deletion azurerm/resource_arm_automation_runbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ func resourceArmAutomationRunbookRead(d *schema.ResourceData, meta interface{})
if v := response.Value; v != nil {
if contentBytes := *response.Value; contentBytes != nil {
buf := new(bytes.Buffer)
buf.ReadFrom(contentBytes)
if _, err := buf.ReadFrom(contentBytes); err != nil {
return fmt.Errorf("Error reading from Automation Runbook buffer %q: %+v", name, err)
}
content := buf.String()
d.Set("content", content)
}
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_container_registry_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func migrateAzureRMContainerRegistryStateV1toV2(is *terraform.InstanceState, met
// Basic's been renamed Classic to allow for "ManagedBasic" ¯\_(ツ)_/¯
is.Attributes["sku"] = "Classic"

updateV1ToV2StorageAccountName(is, meta)
err := updateV1ToV2StorageAccountName(is, meta)

// we have to look this up, since we don't have the resource group name

log.Printf("[DEBUG] ARM Container Registry Attributes after State Migration: %#v", is.Attributes)

return is, nil
return is, err
}

func updateV1ToV2StorageAccountName(is *terraform.InstanceState, meta interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_data_lake_store_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func resourceArmDataLakeStoreFileCreate(d *schema.ResourceData, meta interface{}
if err != nil {
return fmt.Errorf("error opening file %q: %+v", localFilePath, err)
}
defer file.Close()
defer utils.IoCloseAndLogError(file, fmt.Sprintf("Error closing Data Lake Store File %q", localFilePath))

// Read the file contents
fileContents, err := ioutil.ReadAll(file)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func testCheckAzureRMFunctionAppHasContentShare(name string) resource.TestCheckF
return fmt.Errorf("Error making Read request on AzureRM Function App AppSettings %q: %+v", functionAppName, err)
}

for k, _ := range appSettingsResp.Properties {
for k := range appSettingsResp.Properties {
if strings.EqualFold("WEBSITE_CONTENTSHARE", k) {
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion azurerm/resource_arm_notification_hub_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func resourceArmNotificationHubNamespace() *schema.Resource {
Read: resourceArmNotificationHubNamespaceRead,
Update: resourceArmNotificationHubNamespaceCreateUpdate,
Delete: resourceArmNotificationHubNamespaceDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -235,7 +236,10 @@ func notificationHubNamespaceStateRefreshFunc(ctx context.Context, client notifi
// Note: this exists as the Delete API only seems to work some of the time
// in this case we're going to try triggering the Deletion again, in-case it didn't work prior to this attepmpt
// Upstream Bug: https://github.com/Azure/azure-sdk-for-go/issues/2254
client.Delete(ctx, resourceGroupName, name)

if _, err := client.Delete(ctx, resourceGroupName, name); err != nil {
log.Printf(fmt.Sprintf("Error reissuing Notification Hub Namespace %q delete request (Resource Group %q): %+v", name, resourceGroupName, err))
}

return res, strconv.Itoa(res.StatusCode), nil
}
Expand Down
5 changes: 3 additions & 2 deletions azurerm/resource_arm_storage_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
"io"
"log"
"net/url"
Expand Down Expand Up @@ -234,7 +235,7 @@ func resourceArmStorageBlobPageUploadFromSource(container, name, source, content
if err != nil {
return fmt.Errorf("Error opening source file for upload %q: %s", source, err)
}
defer file.Close()
defer utils.IoCloseAndLogError(file, fmt.Sprintf("Error closing Storage Blob `%s` file `%s` after upload", name, source))

blobSize, pageList, err := resourceArmStorageBlobPageSplit(file)
if err != nil {
Expand Down Expand Up @@ -412,7 +413,7 @@ func resourceArmStorageBlobBlockUploadFromSource(container, name, source, conten
if err != nil {
return fmt.Errorf("Error opening source file for upload %q: %s", source, err)
}
defer file.Close()
defer utils.IoCloseAndLogError(file, fmt.Sprintf("Error closing Storage Blob `%s` file `%s` after upload", name, source))

blockList, parts, err := resourceArmStorageBlobBlockSplit(file)
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions azurerm/resource_arm_storage_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ func resourceArmStorageShareCreate(d *schema.ResourceData, meta interface{}) err

log.Printf("[INFO] Setting share %q metadata in storage account %q", name, storageAccountName)
reference.Metadata = metaData
reference.SetMetadata(options)
if err := reference.SetMetadata(options); err != nil {
return fmt.Errorf("Error setting metadata on Storage Share %q: %+v", name, err)
}

log.Printf("[INFO] Setting share %q properties in storage account %q", name, storageAccountName)
reference.Properties = storage.ShareProperties{
Quota: d.Get("quota").(int),
}
reference.SetProperties(options)
if err := reference.SetProperties(options); err != nil {
return fmt.Errorf("Error setting properties on Storage Share %q: %+v", name, err)
}

d.SetId(fmt.Sprintf("%s/%s/%s", name, resourceGroupName, storageAccountName))
return resourceArmStorageShareRead(d, meta)
Expand Down Expand Up @@ -130,7 +134,9 @@ func resourceArmStorageShareRead(d *schema.ResourceData, meta interface{}) error
d.Set("storage_account_name", storageAccountName)
d.Set("url", url)

reference.FetchAttributes(nil)
if err := reference.FetchAttributes(nil); err != nil {
return fmt.Errorf("Error fetching properties on Storage Share %q: %+v", name, err)
}
d.Set("quota", reference.Properties.Quota)

return nil
Expand Down Expand Up @@ -164,7 +170,9 @@ func resourceArmStorageShareUpdate(d *schema.ResourceData, meta interface{}) err
reference.Properties = storage.ShareProperties{
Quota: d.Get("quota").(int),
}
reference.SetProperties(options)
if err := reference.SetProperties(options); err != nil {
return fmt.Errorf("Error setting properties on Storage Share %q: %+v", name, err)
}

return resourceArmStorageShareRead(d, meta)
}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ func flattenAzureRmVirtualMachineIdentity(identity *compute.VirtualMachineIdenti
}
}
*/
for key, _ := range identity.UserAssignedIdentities {
for key := range identity.UserAssignedIdentities {
identityIds = append(identityIds, key)
}
}
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ func flattenAzureRmVirtualMachineScaleSetIdentity(identity *compute.VirtualMachi

identityIds := make([]string, 0)
if identity.UserAssignedIdentities != nil {
for key, _ := range identity.UserAssignedIdentities {
for key := range identity.UserAssignedIdentities {
identityIds = append(identityIds, key)
}
}
Expand Down
12 changes: 12 additions & 0 deletions azurerm/utils/io.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import (
"io"
"log"
)

func IoCloseAndLogError(c io.Closer, message string) {
if err := c.Close(); err != nil {
log.Printf("%s: %v", message, err)
}
}

0 comments on commit 8cf9f80

Please sign in to comment.