diff --git a/resources/appconfig-applications.go b/resources/appconfig-applications.go new file mode 100644 index 000000000..cb419decc --- /dev/null +++ b/resources/appconfig-applications.go @@ -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) +} diff --git a/resources/appconfig-configurationprofiles.go b/resources/appconfig-configurationprofiles.go new file mode 100644 index 000000000..79efd01c6 --- /dev/null +++ b/resources/appconfig-configurationprofiles.go @@ -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) +} diff --git a/resources/appconfig-deploymentstrategies.go b/resources/appconfig-deploymentstrategies.go new file mode 100644 index 000000000..670cb09d6 --- /dev/null +++ b/resources/appconfig-deploymentstrategies.go @@ -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) +} diff --git a/resources/appconfig-environments.go b/resources/appconfig-environments.go new file mode 100644 index 000000000..d12015a73 --- /dev/null +++ b/resources/appconfig-environments.go @@ -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) +} diff --git a/resources/appconfig-hostedconfigurationversions.go b/resources/appconfig-hostedconfigurationversions.go new file mode 100644 index 000000000..6fff16c1b --- /dev/null +++ b/resources/appconfig-hostedconfigurationversions.go @@ -0,0 +1,72 @@ +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 AppConfigHostedConfigurationVersion struct { + svc *appconfig.AppConfig + applicationId *string + configurationProfileId *string + versionNumber *int64 +} + +func init() { + register("AppConfigHostedConfigurationVersion", ListAppConfigHostedConfigurationVersions) +} + +func ListAppConfigHostedConfigurationVersions(sess *session.Session) ([]Resource, error) { + svc := appconfig.New(sess) + resources := []Resource{} + configurationProfiles, err := ListAppConfigConfigurationProfiles(sess) + if err != nil { + return nil, err + } + for _, configurationProfileResource := range configurationProfiles { + configurationProfile, ok := configurationProfileResource.(*AppConfigConfigurationProfile) + if !ok { + logrus.Errorf("Unable to cast AppConfigConfigurationProfile.") + continue + } + params := &appconfig.ListHostedConfigurationVersionsInput{ + ApplicationId: configurationProfile.applicationId, + ConfigurationProfileId: configurationProfile.id, + MaxResults: aws.Int64(100), + } + err := svc.ListHostedConfigurationVersionsPages(params, func(page *appconfig.ListHostedConfigurationVersionsOutput, lastPage bool) bool { + for _, item := range page.Items { + resources = append(resources, &AppConfigHostedConfigurationVersion{ + svc: svc, + applicationId: configurationProfile.applicationId, + configurationProfileId: configurationProfile.id, + versionNumber: item.VersionNumber, + }) + } + return true + }) + if err != nil { + return nil, err + } + } + return resources, nil +} + +func (f *AppConfigHostedConfigurationVersion) Remove() error { + _, err := f.svc.DeleteHostedConfigurationVersion(&appconfig.DeleteHostedConfigurationVersionInput{ + ApplicationId: f.applicationId, + ConfigurationProfileId: f.configurationProfileId, + VersionNumber: f.versionNumber, + }) + return err +} + +func (f *AppConfigHostedConfigurationVersion) Properties() types.Properties { + return types.NewProperties(). + Set("ApplicationID", f.applicationId). + Set("ConfigurationProfileID", f.configurationProfileId). + Set("VersionNumber", f.versionNumber) +}