Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/cloudfront-origin-request-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann authored Aug 2, 2023
2 parents 2088c94 + 90ad6c4 commit 332b33f
Show file tree
Hide file tree
Showing 38 changed files with 484 additions and 135 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func NewRootCommand() *cobra.Command {
awsutil.DefaultAWSPartitionID = endpoints.AwsPartitionID
case endpoints.UsGovEast1RegionID, endpoints.UsGovWest1RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsUsGovPartitionID
case endpoints.CnNorth1RegionID, endpoints.CnNorthwest1RegionID:
awsutil.DefaultAWSPartitionID = endpoints.AwsCnPartitionID
default:
if config.CustomEndpoints.GetRegion(defaultRegion) == nil {
err = fmt.Errorf("The custom region '%s' must be specified in the configuration 'endpoints'", defaultRegion)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/rebuy-de/aws-nuke/v2
go 1.19

require (
github.com/aws/aws-sdk-go v1.44.307
github.com/aws/aws-sdk-go v1.44.313
github.com/fatih/color v1.15.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/aws/aws-sdk-go v1.44.307 h1:2R0/EPgpZcFSUwZhYImq/srjaOrOfLv5MNRzrFyAM38=
github.com/aws/aws-sdk-go v1.44.307/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go v1.44.313 h1:u6EuNQqgAmi09GEZ5g/XGHLF0XV31WcdU5rnHyIBHBc=
github.com/aws/aws-sdk-go v1.44.313/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
7 changes: 4 additions & 3 deletions pkg/config/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func parseDate(input string) (time.Time, error) {
return t, nil
}

formats := []string{"2006-01-02",
formats := []string{
"2006-01-02",
"2006/01/02",
"2006-01-02T15:04:05Z",
"2006-01-02 15:04:05.000 -0700 MST", // Date format used by AWS for CreateTime on ASGs
time.RFC3339Nano, // Format of t.MarshalText() and t.MarshalJSON()
"2006-01-02 15:04:05 -0700 MST", // Date format used by AWS for CreateTime on ASGs
time.RFC3339Nano, // Format of t.MarshalText() and t.MarshalJSON()
time.RFC3339,
}
for _, f := range formats {
Expand Down
9 changes: 6 additions & 3 deletions pkg/config/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ func TestUnmarshalFilter(t *testing.T) {
},
{
yaml: `{"type":"dateOlderThan","value":"0"}`,
match: []string{strconv.Itoa(int(future.Unix())),
match: []string{
strconv.Itoa(int(future.Unix())),
future.Format("2006-01-02"),
future.Format("2006/01/02"),
future.Format("2006-01-02T15:04:05Z"),
future.Format("2006-01-02 15:04:05.000 +0000 UTC"),
future.Format(time.RFC3339Nano),
future.Format(time.RFC3339),
},
mismatch: []string{"",
mismatch: []string{
"",
strconv.Itoa(int(past.Unix())),
past.Format("2006-01-02"),
past.Format("2006/01/02"),
past.Format("2006-01-02T15:04:05Z"),
past.Format("2006-01-02 15:04:05.14 -0700 MST"),
past.Format(time.RFC3339Nano),
past.Format(time.RFC3339),
},
Expand Down Expand Up @@ -98,5 +102,4 @@ func TestUnmarshalFilter(t *testing.T) {
}
})
}

}
53 changes: 53 additions & 0 deletions resources/appconfig-applications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type AppConfigApplication struct {
svc *appconfig.AppConfig
id *string
name *string
}

func init() {
register("AppConfigApplication", ListAppConfigApplications)
}

func ListAppConfigApplications(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
params := &appconfig.ListApplicationsInput{
MaxResults: aws.Int64(100),
}
err := svc.ListApplicationsPages(params, func(page *appconfig.ListApplicationsOutput, lastPage bool) bool {
for _, item := range page.Items {
resources = append(resources, &AppConfigApplication{
svc: svc,
id: item.Id,
name: item.Name,
})
}
return true
})
if err != nil {
return nil, err
}
return resources, nil
}

func (f *AppConfigApplication) Remove() error {
_, err := f.svc.DeleteApplication(&appconfig.DeleteApplicationInput{
ApplicationId: f.id,
})
return err
}

func (f *AppConfigApplication) Properties() types.Properties {
return types.NewProperties().
Set("ID", f.id).
Set("Name", f.name)
}
70 changes: 70 additions & 0 deletions resources/appconfig-configurationprofiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"
)

type AppConfigConfigurationProfile struct {
svc *appconfig.AppConfig
applicationId *string
id *string
name *string
}

func init() {
register("AppConfigConfigurationProfile", ListAppConfigConfigurationProfiles)
}

func ListAppConfigConfigurationProfiles(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
applications, err := ListAppConfigApplications(sess)
if err != nil {
return nil, err
}
for _, applicationResource := range applications {
application, ok := applicationResource.(*AppConfigApplication)
if !ok {
logrus.Errorf("Unable to cast AppConfigApplication.")
continue
}
params := &appconfig.ListConfigurationProfilesInput{
ApplicationId: application.id,
MaxResults: aws.Int64(100),
}
err := svc.ListConfigurationProfilesPages(params, func(page *appconfig.ListConfigurationProfilesOutput, lastPage bool) bool {
for _, item := range page.Items {
resources = append(resources, &AppConfigConfigurationProfile{
svc: svc,
applicationId: application.id,
id: item.Id,
name: item.Name,
})
}
return true
})
if err != nil {
return nil, err
}
}
return resources, nil
}

func (f *AppConfigConfigurationProfile) Remove() error {
_, err := f.svc.DeleteConfigurationProfile(&appconfig.DeleteConfigurationProfileInput{
ApplicationId: f.applicationId,
ConfigurationProfileId: f.id,
})
return err
}

func (f *AppConfigConfigurationProfile) Properties() types.Properties {
return types.NewProperties().
Set("ApplicationID", f.applicationId).
Set("ID", f.id).
Set("Name", f.name)
}
53 changes: 53 additions & 0 deletions resources/appconfig-deploymentstrategies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type AppConfigDeploymentStrategy struct {
svc *appconfig.AppConfig
id *string
name *string
}

func init() {
register("AppConfigDeploymentStrategy", ListAppConfigDeploymentStrategies)
}

func ListAppConfigDeploymentStrategies(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
params := &appconfig.ListDeploymentStrategiesInput{
MaxResults: aws.Int64(100),
}
err := svc.ListDeploymentStrategiesPages(params, func(page *appconfig.ListDeploymentStrategiesOutput, lastPage bool) bool {
for _, item := range page.Items {
resources = append(resources, &AppConfigDeploymentStrategy{
svc: svc,
id: item.Id,
name: item.Name,
})
}
return true
})
if err != nil {
return nil, err
}
return resources, nil
}

func (f *AppConfigDeploymentStrategy) Remove() error {
_, err := f.svc.DeleteDeploymentStrategy(&appconfig.DeleteDeploymentStrategyInput{
DeploymentStrategyId: f.id,
})
return err
}

func (f *AppConfigDeploymentStrategy) Properties() types.Properties {
return types.NewProperties().
Set("ID", f.id).
Set("Name", f.name)
}
70 changes: 70 additions & 0 deletions resources/appconfig-environments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"
)

type AppConfigEnvironment struct {
svc *appconfig.AppConfig
applicationId *string
id *string
name *string
}

func init() {
register("AppConfigEnvironment", ListAppConfigEnvironments)
}

func ListAppConfigEnvironments(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
applications, err := ListAppConfigApplications(sess)
if err != nil {
return nil, err
}
for _, applicationResource := range applications {
application, ok := applicationResource.(*AppConfigApplication)
if !ok {
logrus.Errorf("Unable to cast AppConfigApplication.")
continue
}
params := &appconfig.ListEnvironmentsInput{
ApplicationId: application.id,
MaxResults: aws.Int64(100),
}
err := svc.ListEnvironmentsPages(params, func(page *appconfig.ListEnvironmentsOutput, lastPage bool) bool {
for _, item := range page.Items {
resources = append(resources, &AppConfigEnvironment{
svc: svc,
applicationId: application.id,
id: item.Id,
name: item.Name,
})
}
return true
})
if err != nil {
return nil, err
}
}
return resources, nil
}

func (f *AppConfigEnvironment) Remove() error {
_, err := f.svc.DeleteEnvironment(&appconfig.DeleteEnvironmentInput{
ApplicationId: f.applicationId,
EnvironmentId: f.id,
})
return err
}

func (f *AppConfigEnvironment) Properties() types.Properties {
return types.NewProperties().
Set("ApplicationID", f.applicationId).
Set("ID", f.id).
Set("Name", f.name)
}
Loading

0 comments on commit 332b33f

Please sign in to comment.