Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cl-724 Adding support for codedeploy deployment configs and codepipeline custom action types and webhooks #20

Merged
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
73 changes: 73 additions & 0 deletions resources/codedeploy-deployment-configs.go
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
}
69 changes: 69 additions & 0 deletions resources/codedeploy-deployment-groups.go
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
}
84 changes: 84 additions & 0 deletions resources/codepipeline-custom-action-types.go
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
}
63 changes: 63 additions & 0 deletions resources/codepipeline-webhooks.go
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
}
Loading