diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6d3a80cb8..345cd2f9e 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 b9908d3e8..166574c2f 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 cf867b16c..866092e74 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 b0148cbdf..2a81fe26b 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 375121f60..943886ad6 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 1d49201cd..b3d454d13 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 669bbfe31..c0d958098 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 c451f6e8e..81fc63c59 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 04a57fa17..cb191e610 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 be78228b5..2ca1054b9 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 d4db7bec7..ece41af34 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 882712517..686a7961c 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 9466d8c52..04a53af3a 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 17978a195..017a2c297 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 a94600c13..767eb0f64 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 35f3bc792..c21cfd3f7 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 ddf7966f7..45ba62251 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 6ad754cc2..875668a21 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 67319a56d..630387d6f 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 f2a9ebafa..5095bfdaa 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 9c7d8dea3..3a0c84223 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 d7713c200..6c9a9adf9 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 6f89b957f..356e89829 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -1,4 +1,4 @@ -// +build tools +//go:build tools package main