-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ekristen/resources-appconfig
add appconfig resources from upstream converted to libnuke format
- Loading branch information
Showing
5 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.