From 47fc6c7c92ca92f3b418c3f9ea073e802213ff4e Mon Sep 17 00:00:00 2001 From: Philipp Trulson Date: Wed, 2 Aug 2023 11:40:11 +0200 Subject: [PATCH] Add formatting check to GitHub Actions (#1063) * Add formatting check to GitHub Actions * Fix pre-existing formatting issues --- .github/workflows/ci.yaml | 7 ++ resources/batch-computeenvironments.go | 2 +- resources/batch-computeenvironmentstates.go | 4 +- resources/billing-costandusagereports.go | 10 +-- .../cloudfront-origin-access-identities.go | 76 +++++++++---------- resources/codestar-connections.go | 17 ++--- .../configservice-configurationrecorders.go | 2 +- resources/dax-subnetgroups.go | 2 +- resources/dynamodb-tables.go | 19 +++-- resources/ec2-vpn-connections.go | 8 +- resources/iam-policies.go | 2 +- resources/rds-clusters.go | 24 +++--- resources/rds-dbclusterparametergroups.go | 10 +-- resources/rds-subnets.go | 22 +++--- resources/redshift-subnetgroups.go | 2 +- resources/route53-resource-records.go | 2 +- .../wafregional-byte-match-set-tuples.go | 2 +- resources/wafregional-ip-set-ips.go | 2 +- .../wafregional-rate-based-rule-predicates.go | 2 +- resources/wafregional-regex-match-tuples.go | 2 +- resources/wafregional-regex-pattern-tuples.go | 2 +- resources/wafregional-rule-predicates.go | 2 +- tools/tools.go | 2 +- 23 files changed, 114 insertions(+), 109 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6d3a80cb..345cd2f9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,6 +22,13 @@ jobs: go install golang.org/x/lint/golint@latest - name: Checkout code uses: actions/checkout@v3 + - name: Check Formatting + run: | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + echo "### Go formatting is off, please execute 'gofmt -w -s .' - see following diff: ###" + gofmt -s -d . + exit 1 + fi - name: Test Project run: | make test diff --git a/resources/batch-computeenvironments.go b/resources/batch-computeenvironments.go index b9908d3e..166574c2 100644 --- a/resources/batch-computeenvironments.go +++ b/resources/batch-computeenvironments.go @@ -31,7 +31,7 @@ func ListBatchComputeEnvironments(sess *session.Session) ([]Resource, error) { for _, computeEnvironment := range output.ComputeEnvironments { resources = append(resources, &BatchComputeEnvironment{ - svc: svc, + svc: svc, computeEnvironmentName: computeEnvironment.ComputeEnvironmentName, }) } diff --git a/resources/batch-computeenvironmentstates.go b/resources/batch-computeenvironmentstates.go index cf867b16..866092e7 100644 --- a/resources/batch-computeenvironmentstates.go +++ b/resources/batch-computeenvironmentstates.go @@ -35,9 +35,9 @@ func ListBatchComputeEnvironmentStates(sess *session.Session) ([]Resource, error for _, computeEnvironment := range output.ComputeEnvironments { resources = append(resources, &BatchComputeEnvironmentState{ - svc: svc, + svc: svc, computeEnvironmentName: computeEnvironment.ComputeEnvironmentName, - state: computeEnvironment.State, + state: computeEnvironment.State, }) } diff --git a/resources/billing-costandusagereports.go b/resources/billing-costandusagereports.go index b0148cbd..2a81fe26 100644 --- a/resources/billing-costandusagereports.go +++ b/resources/billing-costandusagereports.go @@ -39,11 +39,11 @@ func ListBillingCostandUsageReports(sess *session.Session) ([]Resource, error) { resources := []Resource{} for _, report := range reports { resources = append(resources, &BillingCostandUsageReport{ - svc: svc, - reportName: report.ReportName, - s3Bucket: report.S3Bucket, - s3Prefix: report.S3Prefix, - s3Region: report.S3Region, + svc: svc, + reportName: report.ReportName, + s3Bucket: report.S3Bucket, + s3Prefix: report.S3Prefix, + s3Region: report.S3Region, }) } diff --git a/resources/cloudfront-origin-access-identities.go b/resources/cloudfront-origin-access-identities.go index 375121f6..943886ad 100644 --- a/resources/cloudfront-origin-access-identities.go +++ b/resources/cloudfront-origin-access-identities.go @@ -1,58 +1,58 @@ package resources import ( - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/cloudfront" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/cloudfront" "github.com/rebuy-de/aws-nuke/v2/pkg/types" ) type CloudFrontOriginAccessIdentity struct { - svc *cloudfront.CloudFront - ID *string + svc *cloudfront.CloudFront + ID *string } func init() { - register("CloudFrontOriginAccessIdentity", ListCloudFrontOriginAccessIdentities) + register("CloudFrontOriginAccessIdentity", ListCloudFrontOriginAccessIdentities) } func ListCloudFrontOriginAccessIdentities(sess *session.Session) ([]Resource, error) { - svc := cloudfront.New(sess) - resources := []Resource{} - - for { - resp, err := svc.ListCloudFrontOriginAccessIdentities(nil) - if err != nil { - return nil, err - } - - for _, item := range resp.CloudFrontOriginAccessIdentityList.Items { - resources = append(resources,&CloudFrontOriginAccessIdentity{ - svc: svc, - ID: item.Id, - }) - } - return resources, nil - } + svc := cloudfront.New(sess) + resources := []Resource{} + + for { + resp, err := svc.ListCloudFrontOriginAccessIdentities(nil) + if err != nil { + return nil, err + } + + for _, item := range resp.CloudFrontOriginAccessIdentityList.Items { + resources = append(resources, &CloudFrontOriginAccessIdentity{ + svc: svc, + ID: item.Id, + }) + } + return resources, nil + } } func (f *CloudFrontOriginAccessIdentity) Remove() error { - resp, err := f.svc.GetCloudFrontOriginAccessIdentity(&cloudfront.GetCloudFrontOriginAccessIdentityInput{ - Id: f.ID, - }) - if err != nil { - return err - } - - _, err = f.svc.DeleteCloudFrontOriginAccessIdentity(&cloudfront.DeleteCloudFrontOriginAccessIdentityInput{ - Id: f.ID, - IfMatch: resp.ETag, - }) - - return err + resp, err := f.svc.GetCloudFrontOriginAccessIdentity(&cloudfront.GetCloudFrontOriginAccessIdentityInput{ + Id: f.ID, + }) + if err != nil { + return err + } + + _, err = f.svc.DeleteCloudFrontOriginAccessIdentity(&cloudfront.DeleteCloudFrontOriginAccessIdentityInput{ + Id: f.ID, + IfMatch: resp.ETag, + }) + + return err } func (f *CloudFrontOriginAccessIdentity) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("ID", f.ID) - return properties + properties := types.NewProperties() + properties.Set("ID", f.ID) + return properties } diff --git a/resources/codestar-connections.go b/resources/codestar-connections.go index 1d49201c..b3d454d1 100644 --- a/resources/codestar-connections.go +++ b/resources/codestar-connections.go @@ -8,10 +8,10 @@ import ( ) type CodeStarConnection struct { - svc *codestarconnections.CodeStarConnections - connectionARN *string - connectionName *string - providerType *string + svc *codestarconnections.CodeStarConnections + connectionARN *string + connectionName *string + providerType *string } func init() { @@ -34,10 +34,10 @@ func ListCodeStarConnections(sess *session.Session) ([]Resource, error) { for _, connection := range output.Connections { resources = append(resources, &CodeStarConnection{ - svc: svc, - connectionARN: connection.ConnectionArn, - connectionName: connection.ConnectionName, - providerType: connection.ProviderType, + svc: svc, + connectionARN: connection.ConnectionArn, + connectionName: connection.ConnectionName, + providerType: connection.ProviderType, }) } @@ -68,7 +68,6 @@ func (f *CodeStarConnection) Properties() types.Properties { return properties } - func (f *CodeStarConnection) String() string { return *f.connectionName } diff --git a/resources/configservice-configurationrecorders.go b/resources/configservice-configurationrecorders.go index 669bbfe3..c0d95809 100644 --- a/resources/configservice-configurationrecorders.go +++ b/resources/configservice-configurationrecorders.go @@ -26,7 +26,7 @@ func ListConfigServiceConfigurationRecorders(sess *session.Session) ([]Resource, resources := make([]Resource, 0) for _, configurationRecorder := range resp.ConfigurationRecorders { resources = append(resources, &ConfigServiceConfigurationRecorder{ - svc: svc, + svc: svc, configurationRecorderName: configurationRecorder.Name, }) } diff --git a/resources/dax-subnetgroups.go b/resources/dax-subnetgroups.go index c451f6e8..81fc63c5 100644 --- a/resources/dax-subnetgroups.go +++ b/resources/dax-subnetgroups.go @@ -1,10 +1,10 @@ package resources import ( + "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dax" - "fmt" ) type DAXSubnetGroup struct { diff --git a/resources/dynamodb-tables.go b/resources/dynamodb-tables.go index 04a57fa1..cb191e61 100644 --- a/resources/dynamodb-tables.go +++ b/resources/dynamodb-tables.go @@ -34,8 +34,8 @@ func ListDynamoDBTables(sess *session.Session) ([]Resource, error) { } resources = append(resources, &DynamoDBTable{ - svc: svc, - id: *tableName, + svc: svc, + id: *tableName, tags: tags, }) } @@ -65,7 +65,7 @@ func GetTableTags(svc *dynamodb.DynamoDB, tableName *string) ([]*dynamodb.Tag, e return make([]*dynamodb.Tag, 0), err } - tags, err := svc.ListTagsOfResource(&dynamodb.ListTagsOfResourceInput{ + tags, err := svc.ListTagsOfResource(&dynamodb.ListTagsOfResourceInput{ ResourceArn: result.Table.TableArn, }) @@ -77,17 +77,16 @@ func GetTableTags(svc *dynamodb.DynamoDB, tableName *string) ([]*dynamodb.Tag, e } func (i *DynamoDBTable) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("Identifier", i.id) + properties := types.NewProperties() + properties.Set("Identifier", i.id) - for _, tag := range i.tags { - properties.SetTag(tag.Key, tag.Value) - } + for _, tag := range i.tags { + properties.SetTag(tag.Key, tag.Value) + } - return properties + return properties } - func (i *DynamoDBTable) String() string { return i.id } diff --git a/resources/ec2-vpn-connections.go b/resources/ec2-vpn-connections.go index be78228b..2ca1054b 100644 --- a/resources/ec2-vpn-connections.go +++ b/resources/ec2-vpn-connections.go @@ -9,8 +9,8 @@ import ( ) type EC2VPNConnection struct { - svc *ec2.EC2 - conn *ec2.VpnConnection + svc *ec2.EC2 + conn *ec2.VpnConnection } func init() { @@ -29,8 +29,8 @@ func ListEC2VPNConnections(sess *session.Session) ([]Resource, error) { resources := make([]Resource, 0) for _, out := range resp.VpnConnections { resources = append(resources, &EC2VPNConnection{ - svc: svc, - conn: out, + svc: svc, + conn: out, }) } diff --git a/resources/iam-policies.go b/resources/iam-policies.go index d4db7bec..ece41af3 100644 --- a/resources/iam-policies.go +++ b/resources/iam-policies.go @@ -1,11 +1,11 @@ package resources import ( - "github.com/sirupsen/logrus" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/v2/pkg/types" + "github.com/sirupsen/logrus" ) type IAMPolicy struct { diff --git a/resources/rds-clusters.go b/resources/rds-clusters.go index 88271251..686a7961 100644 --- a/resources/rds-clusters.go +++ b/resources/rds-clusters.go @@ -30,12 +30,12 @@ func ListRDSClusters(sess *session.Session) ([]Resource, error) { resources := make([]Resource, 0) for _, instance := range resp.DBClusters { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ - ResourceName: instance.DBClusterArn, - }) + ResourceName: instance.DBClusterArn, + }) - if err != nil { - continue - } + if err != nil { + continue + } resources = append(resources, &RDSDBCluster{ svc: svc, @@ -49,7 +49,7 @@ func ListRDSClusters(sess *session.Session) ([]Resource, error) { } func (i *RDSDBCluster) Remove() error { - if (i.deletionProtection) { + if i.deletionProtection { modifyParams := &rds.ModifyDBClusterInput{ DBClusterIdentifier: &i.id, DeletionProtection: aws.Bool(false), @@ -78,13 +78,13 @@ func (i *RDSDBCluster) String() string { } func (i *RDSDBCluster) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("Identifier", i.id) + properties := types.NewProperties() + properties.Set("Identifier", i.id) properties.Set("Deletion Protection", i.deletionProtection) - for _, tag := range i.tags { - properties.SetTag(tag.Key, tag.Value) - } + for _, tag := range i.tags { + properties.SetTag(tag.Key, tag.Value) + } - return properties + return properties } diff --git a/resources/rds-dbclusterparametergroups.go b/resources/rds-dbclusterparametergroups.go index 9466d8c5..04a53af3 100644 --- a/resources/rds-dbclusterparametergroups.go +++ b/resources/rds-dbclusterparametergroups.go @@ -31,12 +31,12 @@ func ListRDSClusterParameterGroups(sess *session.Session) ([]Resource, error) { var resources []Resource for _, parametergroup := range resp.DBClusterParameterGroups { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ - ResourceName: parametergroup.DBClusterParameterGroupArn, - }) + ResourceName: parametergroup.DBClusterParameterGroupArn, + }) - if err != nil { - continue - } + if err != nil { + continue + } resources = append(resources, &RDSDBClusterParameterGroup{ svc: svc, diff --git a/resources/rds-subnets.go b/resources/rds-subnets.go index 17978a19..017a2c29 100644 --- a/resources/rds-subnets.go +++ b/resources/rds-subnets.go @@ -28,12 +28,12 @@ func ListRDSSubnetGroups(sess *session.Session) ([]Resource, error) { var resources []Resource for _, subnetGroup := range resp.DBSubnetGroups { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ - ResourceName: subnetGroup.DBSubnetGroupArn, - }) + ResourceName: subnetGroup.DBSubnetGroupArn, + }) - if err != nil { - continue - } + if err != nil { + continue + } resources = append(resources, &RDSDBSubnetGroup{ svc: svc, @@ -64,12 +64,12 @@ func (i *RDSDBSubnetGroup) String() string { } func (i *RDSDBSubnetGroup) Properties() types.Properties { - properties := types.NewProperties() - properties.Set("Name", i.name) + properties := types.NewProperties() + properties.Set("Name", i.name) - for _, tag := range i.tags { - properties.SetTag(tag.Key, tag.Value) - } + for _, tag := range i.tags { + properties.SetTag(tag.Key, tag.Value) + } - return properties + return properties } diff --git a/resources/redshift-subnetgroups.go b/resources/redshift-subnetgroups.go index a94600c1..767eb0f6 100644 --- a/resources/redshift-subnetgroups.go +++ b/resources/redshift-subnetgroups.go @@ -31,7 +31,7 @@ func ListRedshiftSubnetGroups(sess *session.Session) ([]Resource, error) { for _, subnetGroup := range output.ClusterSubnetGroups { resources = append(resources, &RedshiftSubnetGroup{ - svc: svc, + svc: svc, clusterSubnetGroupName: subnetGroup.ClusterSubnetGroupName, }) } diff --git a/resources/route53-resource-records.go b/resources/route53-resource-records.go index 35f3bc79..c21cfd3f 100644 --- a/resources/route53-resource-records.go +++ b/resources/route53-resource-records.go @@ -95,7 +95,7 @@ func (r *Route53ResourceRecordSet) Remove() error { HostedZoneId: r.hostedZoneId, ChangeBatch: &route53.ChangeBatch{ Changes: []*route53.Change{ - &route53.Change{ + { Action: aws.String("DELETE"), ResourceRecordSet: r.data, }, diff --git a/resources/wafregional-byte-match-set-tuples.go b/resources/wafregional-byte-match-set-tuples.go index ddf7966f..45ba6225 100644 --- a/resources/wafregional-byte-match-set-tuples.go +++ b/resources/wafregional-byte-match-set-tuples.go @@ -70,7 +70,7 @@ func (r *WAFRegionalByteMatchSetIP) Remove() error { ChangeToken: tokenOutput.ChangeToken, ByteMatchSetId: r.matchSetid, Updates: []*waf.ByteMatchSetUpdate{ - &waf.ByteMatchSetUpdate{ + { Action: aws.String("DELETE"), ByteMatchTuple: r.tuple, }, diff --git a/resources/wafregional-ip-set-ips.go b/resources/wafregional-ip-set-ips.go index 6ad754cc..875668a2 100644 --- a/resources/wafregional-ip-set-ips.go +++ b/resources/wafregional-ip-set-ips.go @@ -70,7 +70,7 @@ func (r *WAFRegionalIPSetIP) Remove() error { ChangeToken: tokenOutput.ChangeToken, IPSetId: r.ipSetid, Updates: []*waf.IPSetUpdate{ - &waf.IPSetUpdate{ + { Action: aws.String("DELETE"), IPSetDescriptor: r.descriptor, }, diff --git a/resources/wafregional-rate-based-rule-predicates.go b/resources/wafregional-rate-based-rule-predicates.go index 67319a56..630387d6 100644 --- a/resources/wafregional-rate-based-rule-predicates.go +++ b/resources/wafregional-rate-based-rule-predicates.go @@ -72,7 +72,7 @@ func (r *WAFRegionalRateBasedRulePredicate) Remove() error { RuleId: r.ruleID, RateLimit: r.rateLimit, Updates: []*waf.RuleUpdate{ - &waf.RuleUpdate{ + { Action: aws.String("DELETE"), Predicate: r.predicate, }, diff --git a/resources/wafregional-regex-match-tuples.go b/resources/wafregional-regex-match-tuples.go index f2a9ebaf..5095bfda 100644 --- a/resources/wafregional-regex-match-tuples.go +++ b/resources/wafregional-regex-match-tuples.go @@ -69,7 +69,7 @@ func (r *WAFRegionalRegexMatchTuple) Remove() error { ChangeToken: tokenOutput.ChangeToken, RegexMatchSetId: r.matchSetid, Updates: []*waf.RegexMatchSetUpdate{ - &waf.RegexMatchSetUpdate{ + { Action: aws.String("DELETE"), RegexMatchTuple: r.tuple, }, diff --git a/resources/wafregional-regex-pattern-tuples.go b/resources/wafregional-regex-pattern-tuples.go index 9c7d8dea..3a0c8422 100644 --- a/resources/wafregional-regex-pattern-tuples.go +++ b/resources/wafregional-regex-pattern-tuples.go @@ -69,7 +69,7 @@ func (r *WAFRegionalRegexPatternString) Remove() error { ChangeToken: tokenOutput.ChangeToken, RegexPatternSetId: r.patternSetid, Updates: []*waf.RegexPatternSetUpdate{ - &waf.RegexPatternSetUpdate{ + { Action: aws.String("DELETE"), RegexPatternString: r.patternString, }, diff --git a/resources/wafregional-rule-predicates.go b/resources/wafregional-rule-predicates.go index d7713c20..6c9a9adf 100644 --- a/resources/wafregional-rule-predicates.go +++ b/resources/wafregional-rule-predicates.go @@ -69,7 +69,7 @@ func (r *WAFRegionalRulePredicate) Remove() error { ChangeToken: tokenOutput.ChangeToken, RuleId: r.ruleID, Updates: []*waf.RuleUpdate{ - &waf.RuleUpdate{ + { Action: aws.String("DELETE"), Predicate: r.predicate, }, diff --git a/tools/tools.go b/tools/tools.go index 6f89b957..356e8982 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,4 +1,4 @@ -// +build tools +//go:build tools package main