Skip to content

Commit

Permalink
Merge pull request #2219 from terraform-providers/lint/package
Browse files Browse the repository at this point in the history
Linting: include sub packages
  • Loading branch information
katbyte authored Nov 7, 2018
2 parents cd04fe3 + 38af491 commit da529be
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 99 deletions.
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ fmtcheck:

goimport:
@echo "==> Fixing imports code with goimports..."
goimports -w azurerm/
goimports -w $(PKG_NAME)/

lint:
@echo "==> Checking source code against linters..."
@gometalinter ./$(PKG_NAME)
@gometalinter ./...

tools:
@echo "==> installing required tooling..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestServicePrincipalClientCertAuth_populateConfig(t *testing.T) {
t.Fatalf("Error populating config: %s", err)
}

if config.AuthenticatedAsAServicePrincipal != true {
if !config.AuthenticatedAsAServicePrincipal {
t.Fatalf("Expected `AuthenticatedAsAServicePrincipal` to be true but it wasn't")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestServicePrincipalClientSecretAuth_populateConfig(t *testing.T) {
t.Fatalf("Error populating config: %s", err)
}

if config.AuthenticatedAsAServicePrincipal != true {
if !config.AuthenticatedAsAServicePrincipal {
t.Fatalf("Expected `AuthenticatedAsAServicePrincipal` to be true but it wasn't")
}
}
Expand Down
6 changes: 3 additions & 3 deletions azurerm/helpers/authentication/azure_cli_access_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestAzureFindValidAccessTokenForTenant_ExpiringIn(t *testing.T) {
t.Fatalf("Expected the Client ID to be %q for minute %d but got %q", expectedToken.ClientID, minute, token.ClientID)
}

if token.IsCloudShell != false {
if token.IsCloudShell {
t.Fatalf("Expected `IsCloudShell` to be false for minute %d but got true", minute)
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAzureFindValidAccessTokenForTenant_ValidFromCloudShell(t *testing.T) {
t.Fatalf("Expected the Client ID to be %q but got %q", expectedToken.ClientID, token.ClientID)
}

if token.IsCloudShell != true {
if !token.IsCloudShell {
t.Fatalf("Expected `IsCloudShell` to be true but got false")
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestAzureFindValidAccessTokenForTenant_ValidFromAzureCLI(t *testing.T) {
t.Fatalf("Expected the Client ID to be %q but got %q", expectedToken.ClientID, token.ClientID)
}

if token.IsCloudShell != false {
if token.IsCloudShell {
t.Fatalf("Expected `IsCloudShell` to be false but got true")
}
}
Expand Down
7 changes: 1 addition & 6 deletions azurerm/helpers/authentication/azure_cli_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,5 @@ func (a *azureCLIProfile) populateFields() error {
}

// always pull the environment from the Azure CLI, since the Access Token's associated with it
err = a.populateEnvironment()
if err != nil {
return err
}

return nil
return a.populateEnvironment()
}
18 changes: 8 additions & 10 deletions azurerm/helpers/azure/app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,8 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
}

documents := make([]string, 0)
if input.DefaultDocuments != nil {
for _, document := range *input.DefaultDocuments {
documents = append(documents, document)
}
if s := input.DefaultDocuments; s != nil {
documents = *s
}
result["default_documents"] = documents

Expand Down Expand Up @@ -381,22 +379,22 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} {
restrictions := make([]interface{}, 0)
if vs := input.IPSecurityRestrictions; vs != nil {
for _, v := range *vs {
result := make(map[string]interface{})
block := make(map[string]interface{})
if ip := v.IPAddress; ip != nil {
// the 2018-02-01 API uses CIDR format (a.b.c.d/x), so translate that back to IP and mask
if strings.Contains(*ip, "/") {
ipAddr, ipNet, _ := net.ParseCIDR(*ip)
result["ip_address"] = ipAddr.String()
block["ip_address"] = ipAddr.String()
mask := net.IP(ipNet.Mask)
result["subnet_mask"] = mask.String()
block["subnet_mask"] = mask.String()
} else {
result["ip_address"] = *ip
block["ip_address"] = *ip
}
}
if subnet := v.SubnetMask; subnet != nil {
result["subnet_mask"] = *subnet
block["subnet_mask"] = *subnet
}
restrictions = append(restrictions, result)
restrictions = append(restrictions, block)
}
}
result["ip_restriction"] = restrictions
Expand Down
4 changes: 2 additions & 2 deletions azurerm/helpers/azure/eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ExpandEventHubAuthorizationRuleRights(d *schema.ResourceData) *[]eventhub.A
return &rights
}

func FlattenEventHubAuthorizationRuleRights(rights *[]eventhub.AccessRights) (listen bool, send bool, manage bool) {
func FlattenEventHubAuthorizationRuleRights(rights *[]eventhub.AccessRights) (listen, send, manage bool) {
//zero (initial) value for a bool in go is false

if rights != nil {
Expand All @@ -77,7 +77,7 @@ func FlattenEventHubAuthorizationRuleRights(rights *[]eventhub.AccessRights) (li
}
}

return
return listen, send, manage
}

func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema {
Expand Down
30 changes: 3 additions & 27 deletions azurerm/helpers/azure/resourceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@ func ParseAzureResourceID(id string) (*ResourceID, error) {

path := idURL.Path

path = strings.TrimSpace(path)
if strings.HasPrefix(path, "/") {
path = path[1:]
}

if strings.HasSuffix(path, "/") {
path = path[:len(path)-1]
}
path = strings.TrimPrefix(path, "/")
path = strings.TrimSuffix(path, "/")

components := strings.Split(path, "/")

Expand Down Expand Up @@ -132,23 +126,5 @@ func composeAzureResourceID(idObj *ResourceID) (id string, err error) {
}
}

return
}

func ParseNetworkSecurityGroupName(networkSecurityGroupId string) (string, error) {
id, err := ParseAzureResourceID(networkSecurityGroupId)
if err != nil {
return "", fmt.Errorf("[ERROR] Unable to Parse Network Security Group ID '%s': %+v", networkSecurityGroupId, err)
}

return id.Path["networkSecurityGroups"], nil
}

func ParseRouteTableName(routeTableId string) (string, error) {
id, err := ParseAzureResourceID(routeTableId)
if err != nil {
return "", fmt.Errorf("[ERROR] Unable to parse Route Table ID '%s': %+v", routeTableId, err)
}

return id.Path["routeTables"], nil
return id, err
}
2 changes: 1 addition & 1 deletion azurerm/helpers/azure/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func withRequestLogging() autorest.SendDecorator {
resp, err := s.Do(r)
if resp != nil {
// dump response to wire format
if dump, err := httputil.DumpResponse(resp, true); err == nil {
if dump, err2 := httputil.DumpResponse(resp, true); err2 == nil {
log.Printf("[DEBUG] AzureRM Response for %s: \n%s\n", r.URL, dump)
} else {
// fallback to basic message
Expand Down
4 changes: 2 additions & 2 deletions azurerm/helpers/azure/servicebus.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func ExpandServiceBusAuthorizationRuleRights(d *schema.ResourceData) *[]serviceb
return &rights
}

func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights) (listen bool, send bool, manage bool) {
func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights) (listen, send, manage bool) {
//zero (initial) value for a bool in go is false

if rights != nil {
Expand All @@ -83,7 +83,7 @@ func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights)
}
}

return
return listen, send, manage
}

//shared schema
Expand Down
4 changes: 2 additions & 2 deletions azurerm/helpers/azure/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
)

func ValidateResourceID(i interface{}, k string) (_ []string, errors []error) {
func ValidateResourceID(i interface{}, k string) (ws []string, errors []error) {
v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected type of %q to be string", k))
Expand All @@ -15,7 +15,7 @@ func ValidateResourceID(i interface{}, k string) (_ []string, errors []error) {
errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err))
}

return
return ws, errors
}

//true for a resource ID or an empty string
Expand Down
18 changes: 9 additions & 9 deletions azurerm/helpers/kubernetes/kube_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kubernetes
import (
"fmt"

yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
)

type clusterItem struct {
Expand Down Expand Up @@ -54,20 +54,20 @@ func ParseKubeConfig(config string) (*KubeConfig, error) {
}

var kubeConfig KubeConfig
err := yaml.Unmarshal([]byte(config), &kubeConfig)
if err != nil {

if err := yaml.Unmarshal([]byte(config), &kubeConfig); err != nil {
return nil, fmt.Errorf("Failed to unmarshal YAML config with error %+v", err)
}
if len(kubeConfig.Clusters) <= 0 || len(kubeConfig.Users) <= 0 {
return nil, fmt.Errorf("Config %+v contains no valid clusters or users", kubeConfig)
}
user := kubeConfig.Users[0].User
if user.Token == "" && (user.ClientCertificteData == "" || user.ClientKeyData == "") {
return nil, fmt.Errorf("Config requires either token or certificate auth for user %+v", user)
u := kubeConfig.Users[0].User
if u.Token == "" && (u.ClientCertificteData == "" || u.ClientKeyData == "") {
return nil, fmt.Errorf("Config requires either token or certificate auth for user %+v", u)
}
cluster := kubeConfig.Clusters[0].Cluster
if cluster.Server == "" {
return nil, fmt.Errorf("Config has invalid or non existent server for cluster %+v", cluster)
c := kubeConfig.Clusters[0].Cluster
if c.Server == "" {
return nil, fmt.Errorf("Config has invalid or non existent server for cluster %+v", c)
}

return &kubeConfig, nil
Expand Down
6 changes: 3 additions & 3 deletions azurerm/helpers/validate/api_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func ApiManagementServiceName(v interface{}, k string) (ws []string, es []error)
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 50 characters in length", k))
}

return
return ws, es
}

func ApiManagementServicePublisherName(v interface{}, k string) (ws []string, es []error) {
Expand All @@ -22,7 +22,7 @@ func ApiManagementServicePublisherName(v interface{}, k string) (ws []string, es
es = append(es, fmt.Errorf("%q may only be up to 100 characters in length", k))
}

return
return ws, es
}

func ApiManagementServicePublisherEmail(v interface{}, k string) (ws []string, es []error) {
Expand All @@ -32,5 +32,5 @@ func ApiManagementServicePublisherEmail(v interface{}, k string) (ws []string, e
es = append(es, fmt.Errorf("%q may only be up to 100 characters in length", k))
}

return
return ws, es
}
12 changes: 6 additions & 6 deletions azurerm/helpers/validate/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func SharedImageGalleryName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)
// Image gallery name accepts only alphanumeric, dots and underscores in the name (no dashes)
r, _ := regexp.Compile("^[A-Za-z0-9._]+$")
r, _ := regexp.Compile(`^[A-Za-z0-9._]+$`)
if !r.MatchString(value) {
es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops and underscores. Got %q.", k, value))
}
Expand All @@ -18,14 +18,14 @@ func SharedImageGalleryName(v interface{}, k string) (ws []string, es []error) {
es = append(es, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length))
}

return
return ws, es
}

func SharedImageName(v interface{}, k string) (ws []string, es []error) {
// different from the shared image gallery name
value := v.(string)

r, _ := regexp.Compile("^[A-Za-z0-9._-]+$")
r, _ := regexp.Compile(`^[A-Za-z0-9._-]+$`)
if !r.MatchString(value) {
es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops, dashes and underscores. Got %q.", k, value))
}
Expand All @@ -35,16 +35,16 @@ func SharedImageName(v interface{}, k string) (ws []string, es []error) {
es = append(es, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length))
}

return
return ws, es
}

func SharedImageVersionName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)

r, _ := regexp.Compile("^([0-9]\\.[0-9]\\.[0-9])$")
r, _ := regexp.Compile(`^([0-9]\.[0-9]\.[0-9])$`)
if !r.MatchString(value) {
es = append(es, fmt.Errorf("Expected %s to be in the format `1.2.3` but got %q.", k, value))
}

return
return ws, es
}
4 changes: 2 additions & 2 deletions azurerm/helpers/validate/iothub.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func IoTHubName(v interface{}, k string) (ws []string, es []error) {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k))
}

return
return ws, es
}

func IoTHubConsumerGroupName(v interface{}, k string) (ws []string, es []error) {
Expand All @@ -24,5 +24,5 @@ func IoTHubConsumerGroupName(v interface{}, k string) (ws []string, es []error)
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes, periods and underscores", k))
}

return
return ws, es
}
Loading

0 comments on commit da529be

Please sign in to comment.