forked from rebuy-de/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #20 from oreillymedia/cl-724-add-codedeploy-deploy…
…ment-configs cl-724 Adding support for codedeploy deployment configs and codepipeline custom action types and webhooks
- Loading branch information
Showing
4 changed files
with
289 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,73 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/codedeploy" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type CodeDeployDeploymentConfig struct { | ||
svc *codedeploy.CodeDeploy | ||
deploymentConfigName *string | ||
} | ||
|
||
func init() { | ||
register("CodeDeployDeploymentConfig", ListCodeDeployDeploymentConfigs, mapCloudControl("AWS::CodeDeploy::DeploymentConfig")) | ||
} | ||
|
||
func ListCodeDeployDeploymentConfigs(sess *session.Session) ([]Resource, error) { | ||
svc := codedeploy.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &codedeploy.ListDeploymentConfigsInput{} | ||
|
||
for { | ||
resp, err := svc.ListDeploymentConfigs(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, config := range resp.DeploymentConfigsList { | ||
resources = append(resources, &CodeDeployDeploymentConfig{ | ||
svc: svc, | ||
deploymentConfigName: config, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *CodeDeployDeploymentConfig) Filter() error { | ||
if strings.HasPrefix(*f.deploymentConfigName, "CodeDeployDefault") { | ||
return fmt.Errorf("cannot delete default codedeploy config") | ||
} | ||
return nil | ||
} | ||
|
||
func (f *CodeDeployDeploymentConfig) Remove() error { | ||
_, err := f.svc.DeleteDeploymentConfig(&codedeploy.DeleteDeploymentConfigInput{ | ||
DeploymentConfigName: f.deploymentConfigName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *CodeDeployDeploymentConfig) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("DeploymentConfigName", f.deploymentConfigName) | ||
return properties | ||
} | ||
|
||
func (f *CodeDeployDeploymentConfig) String() string { | ||
return *f.deploymentConfigName | ||
} |
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,69 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/codedeploy" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type CodeDeployDeploymentGroup struct { | ||
svc *codedeploy.CodeDeploy | ||
deploymentGroupName *string | ||
applicationName *string | ||
} | ||
|
||
func init() { | ||
register("CodeDeployDeploymentGroup", ListCodeDeployDeploymentGroups) | ||
} | ||
|
||
func ListCodeDeployDeploymentGroups(sess *session.Session) ([]Resource, error) { | ||
svc := codedeploy.New(sess) | ||
resources := []Resource{} | ||
|
||
appParams := &codedeploy.ListApplicationsInput{} | ||
appResp, err := svc.ListApplications(appParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, appName := range appResp.Applications { | ||
// For each application, list deployment groups | ||
deploymentGroupParams := &codedeploy.ListDeploymentGroupsInput{ | ||
ApplicationName: appName, | ||
} | ||
deploymentGroupResp, err := svc.ListDeploymentGroups(deploymentGroupParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, group := range deploymentGroupResp.DeploymentGroups { | ||
resources = append(resources, &CodeDeployDeploymentGroup{ | ||
svc: svc, | ||
deploymentGroupName: group, | ||
applicationName: appName, | ||
}) | ||
} | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *CodeDeployDeploymentGroup) Remove() error { | ||
_, err := f.svc.DeleteDeploymentGroup(&codedeploy.DeleteDeploymentGroupInput{ | ||
ApplicationName: f.applicationName, | ||
DeploymentGroupName: f.deploymentGroupName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *CodeDeployDeploymentGroup) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("DeploymentGroupName", f.deploymentGroupName) | ||
properties.Set("ApplicationName", f.applicationName) | ||
return properties | ||
} | ||
|
||
func (f *CodeDeployDeploymentGroup) String() string { | ||
return *f.deploymentGroupName | ||
} |
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,84 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/codepipeline" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type CodePipelineCustomActionType struct { | ||
svc *codepipeline.CodePipeline | ||
owner *string | ||
category *string | ||
provider *string | ||
version *string | ||
} | ||
|
||
func init() { | ||
register("CodePipelineCustomActionType", ListCodePipelineCustomActionTypes, mapCloudControl("AWS::CodePipeline::CustomActionType")) | ||
} | ||
|
||
func ListCodePipelineCustomActionTypes(sess *session.Session) ([]Resource, error) { | ||
svc := codepipeline.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &codepipeline.ListActionTypesInput{} | ||
|
||
for { | ||
resp, err := svc.ListActionTypes(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, actionTypes := range resp.ActionTypes { | ||
resources = append(resources, &CodePipelineCustomActionType{ | ||
svc: svc, | ||
owner: actionTypes.Id.Owner, | ||
category: actionTypes.Id.Category, | ||
provider: actionTypes.Id.Provider, | ||
version: actionTypes.Id.Version, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *CodePipelineCustomActionType) Filter() error { | ||
if !strings.HasPrefix(*f.owner, "Custom") { | ||
return fmt.Errorf("cannot delete default codepipeline custom action type") | ||
} | ||
return nil | ||
} | ||
|
||
func (f *CodePipelineCustomActionType) Remove() error { | ||
_, err := f.svc.DeleteCustomActionType(&codepipeline.DeleteCustomActionTypeInput{ | ||
Category: f.category, | ||
Provider: f.provider, | ||
Version: f.version, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *CodePipelineCustomActionType) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Category", f.category) | ||
properties.Set("Owner", f.owner) | ||
properties.Set("Provider", f.provider) | ||
properties.Set("Version", f.version) | ||
return properties | ||
} | ||
|
||
func (f *CodePipelineCustomActionType) String() string { | ||
return *f.owner | ||
} |
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,63 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/codepipeline" | ||
"github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
) | ||
|
||
type CodePipelineWebhook struct { | ||
svc *codepipeline.CodePipeline | ||
name *string | ||
} | ||
|
||
func init() { | ||
register("CodePipelineWebhook", ListCodePipelineWebhooks) | ||
} | ||
|
||
func ListCodePipelineWebhooks(sess *session.Session) ([]Resource, error) { | ||
svc := codepipeline.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &codepipeline.ListWebhooksInput{} | ||
|
||
for { | ||
resp, err := svc.ListWebhooks(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, webHooks := range resp.Webhooks { | ||
resources = append(resources, &CodePipelineWebhook{ | ||
svc: svc, | ||
name: webHooks.Definition.Name, | ||
}) | ||
} | ||
|
||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (f *CodePipelineWebhook) Remove() error { | ||
_, err := f.svc.DeleteWebhook(&codepipeline.DeleteWebhookInput{ | ||
Name: f.name, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *CodePipelineWebhook) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Name", f.name) | ||
return properties | ||
} | ||
|
||
func (f *CodePipelineWebhook) String() string { | ||
return *f.name | ||
} |