Skip to content

Commit

Permalink
migrate: appconfig resources to libnuke format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 25, 2024
1 parent 54900d3 commit 8b6cb8e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 41 deletions.
29 changes: 22 additions & 7 deletions resources/appconfig-applications.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package resources

import (
"context"

"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/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type AppConfigApplication struct {
Expand All @@ -13,13 +18,23 @@ type AppConfigApplication struct {
name *string
}

const AppConfigApplicationResource = "AppConfigApplication"

func init() {
register("AppConfigApplication", ListAppConfigApplications)
resource.Register(&resource.Registration{
Name: AppConfigApplicationResource,
Scope: nuke.Account,
Lister: &AppConfigApplicationLister{},
})
}

func ListAppConfigApplications(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
type AppConfigApplicationLister struct{}

func (l *AppConfigApplicationLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := appconfig.New(opts.Session)
resources := make([]resource.Resource, 0)
params := &appconfig.ListApplicationsInput{
MaxResults: aws.Int64(50),
}
Expand All @@ -39,7 +54,7 @@ func ListAppConfigApplications(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func (f *AppConfigApplication) Remove() error {
func (f *AppConfigApplication) Remove(_ context.Context) error {
_, err := f.svc.DeleteApplication(&appconfig.DeleteApplicationInput{
ApplicationId: f.id,
})
Expand Down
37 changes: 28 additions & 9 deletions resources/appconfig-configurationprofiles.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package resources

import (
"context"

"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/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"

"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type AppConfigConfigurationProfile struct {
Expand All @@ -15,14 +21,27 @@ type AppConfigConfigurationProfile struct {
name *string
}

const AppConfigConfigurationProfileResource = "AppConfigConfigurationProfile"

func init() {
register("AppConfigConfigurationProfile", ListAppConfigConfigurationProfiles)
resource.Register(&resource.Registration{
Name: AppConfigConfigurationProfileResource,
Scope: nuke.Account,
Lister: &AppConfigConfigurationProfileLister{},
})
}

func ListAppConfigConfigurationProfiles(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
applications, err := ListAppConfigApplications(sess)
type AppConfigConfigurationProfileLister struct{}

func (l *AppConfigConfigurationProfileLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := appconfig.New(opts.Session)
resources := make([]resource.Resource, 0)

applicationLister := &AppConfigApplicationLister{}

applications, err := applicationLister.List(ctx, o)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -54,7 +73,7 @@ func ListAppConfigConfigurationProfiles(sess *session.Session) ([]Resource, erro
return resources, nil
}

func (f *AppConfigConfigurationProfile) Remove() error {
func (f *AppConfigConfigurationProfile) Remove(_ context.Context) error {
_, err := f.svc.DeleteConfigurationProfile(&appconfig.DeleteConfigurationProfileInput{
ApplicationId: f.applicationId,
ConfigurationProfileId: f.id,
Expand Down
28 changes: 21 additions & 7 deletions resources/appconfig-deploymentstrategies.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package resources

import (
"context"
"fmt"
"strings"

"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/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type AppConfigDeploymentStrategy struct {
Expand All @@ -16,13 +20,23 @@ type AppConfigDeploymentStrategy struct {
name *string
}

const AppConfigDeploymentStrategyResource = "AppConfigDeploymentStrategy"

func init() {
register("AppConfigDeploymentStrategy", ListAppConfigDeploymentStrategies)
resource.Register(&resource.Registration{
Name: AppConfigDeploymentStrategyResource,
Scope: nuke.Account,
Lister: &AppConfigDeploymentStrategyLister{},
})
}

func ListAppConfigDeploymentStrategies(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
type AppConfigDeploymentStrategyLister struct{}

func (l *AppConfigDeploymentStrategyLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := appconfig.New(opts.Session)
resources := make([]resource.Resource, 0)
params := &appconfig.ListDeploymentStrategiesInput{
MaxResults: aws.Int64(50),
}
Expand All @@ -49,7 +63,7 @@ func (f *AppConfigDeploymentStrategy) Filter() error {
return nil
}

func (f *AppConfigDeploymentStrategy) Remove() error {
func (f *AppConfigDeploymentStrategy) Remove(_ context.Context) error {
_, err := f.svc.DeleteDeploymentStrategy(&appconfig.DeleteDeploymentStrategyInput{
DeploymentStrategyId: f.id,
})
Expand Down
36 changes: 27 additions & 9 deletions resources/appconfig-environments.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package resources

import (
"context"

"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/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"

"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type AppConfigEnvironment struct {
Expand All @@ -15,14 +21,26 @@ type AppConfigEnvironment struct {
name *string
}

const AppConfigEnvironmentResource = "AppConfigEnvironment"

func init() {
register("AppConfigEnvironment", ListAppConfigEnvironments)
resource.Register(&resource.Registration{
Name: AppConfigEnvironmentResource,
Scope: nuke.Account,
Lister: &AppConfigEnvironmentLister{},
})
}

func ListAppConfigEnvironments(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
applications, err := ListAppConfigApplications(sess)
type AppConfigEnvironmentLister struct{}

func (l *AppConfigEnvironmentLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := appconfig.New(opts.Session)
resources := make([]resource.Resource, 0)

applicationLister := &AppConfigApplicationLister{}
applications, err := applicationLister.List(ctx, o)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -54,7 +72,7 @@ func ListAppConfigEnvironments(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func (f *AppConfigEnvironment) Remove() error {
func (f *AppConfigEnvironment) Remove(_ context.Context) error {
_, err := f.svc.DeleteEnvironment(&appconfig.DeleteEnvironmentInput{
ApplicationId: f.applicationId,
EnvironmentId: f.id,
Expand Down
36 changes: 27 additions & 9 deletions resources/appconfig-hostedconfigurationversions.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package resources

import (
"context"

"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/appconfig"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
"github.com/sirupsen/logrus"

"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type AppConfigHostedConfigurationVersion struct {
Expand All @@ -15,14 +21,26 @@ type AppConfigHostedConfigurationVersion struct {
versionNumber *int64
}

const AppConfigHostedConfigurationVersionResource = "AppConfigHostedConfigurationVersion"

func init() {
register("AppConfigHostedConfigurationVersion", ListAppConfigHostedConfigurationVersions)
resource.Register(&resource.Registration{
Name: AppConfigHostedConfigurationVersionResource,
Scope: nuke.Account,
Lister: &AppConfigHostedConfigurationVersionLister{},
})
}

func ListAppConfigHostedConfigurationVersions(sess *session.Session) ([]Resource, error) {
svc := appconfig.New(sess)
resources := []Resource{}
configurationProfiles, err := ListAppConfigConfigurationProfiles(sess)
type AppConfigHostedConfigurationVersionLister struct{}

func (l *AppConfigHostedConfigurationVersionLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := appconfig.New(opts.Session)
resources := make([]resource.Resource, 0)

profilerLister := &AppConfigConfigurationProfileLister{}
configurationProfiles, err := profilerLister.List(ctx, o)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -55,7 +73,7 @@ func ListAppConfigHostedConfigurationVersions(sess *session.Session) ([]Resource
return resources, nil
}

func (f *AppConfigHostedConfigurationVersion) Remove() error {
func (f *AppConfigHostedConfigurationVersion) Remove(_ context.Context) error {
_, err := f.svc.DeleteHostedConfigurationVersion(&appconfig.DeleteHostedConfigurationVersionInput{
ApplicationId: f.applicationId,
ConfigurationProfileId: f.configurationProfileId,
Expand Down

0 comments on commit 8b6cb8e

Please sign in to comment.