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

appconfig: add support for five resources #1055

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
72 changes: 72 additions & 0 deletions resources/appconfig-hostedconfigurationversions.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading