Skip to content

Commit

Permalink
Merge pull request #43 from ekristen/resources-appconfig
Browse files Browse the repository at this point in the history
add appconfig resources from upstream converted to libnuke format
  • Loading branch information
ekristen authored Jan 25, 2024
2 parents de15680 + 208259f commit e4a0a8a
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 0 deletions.
72 changes: 72 additions & 0 deletions resources/appconfig-applications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appconfig"

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

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

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

const AppConfigApplicationResource = "AppConfigApplication"

func init() {
resource.Register(&resource.Registration{
Name: AppConfigApplicationResource,
Scope: nuke.Account,
Lister: &AppConfigApplicationLister{},
DependsOn: []string{
AppConfigConfigurationProfileResource,
AppConfigEnvironmentResource,
},
})
}

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),
}
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(_ context.Context) 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)
}
92 changes: 92 additions & 0 deletions resources/appconfig-configurationprofiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package resources

import (
"context"

"github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appconfig"

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

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

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

const AppConfigConfigurationProfileResource = "AppConfigConfigurationProfile"

func init() {
resource.Register(&resource.Registration{
Name: AppConfigConfigurationProfileResource,
Scope: nuke.Account,
Lister: &AppConfigConfigurationProfileLister{},
DependsOn: []string{
AppConfigHostedConfigurationVersionResource,
},
})
}

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
}
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(50),
}
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(_ context.Context) 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)
}
77 changes: 77 additions & 0 deletions resources/appconfig-deploymentstrategies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package resources

import (
"context"
"fmt"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appconfig"

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

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

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

const AppConfigDeploymentStrategyResource = "AppConfigDeploymentStrategy"

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

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),
}
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) Filter() error {
if strings.HasPrefix(*f.name, "AppConfig.") {
return fmt.Errorf("cannot delete predefined Deployment Strategy")
}
return nil
}

func (f *AppConfigDeploymentStrategy) Remove(_ context.Context) 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)
}
88 changes: 88 additions & 0 deletions resources/appconfig-environments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package resources

import (
"context"

"github.com/sirupsen/logrus"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appconfig"

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

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

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

const AppConfigEnvironmentResource = "AppConfigEnvironment"

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

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
}
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(50),
}
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(_ context.Context) 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 e4a0a8a

Please sign in to comment.