|
| 1 | +package resources |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/aws/aws-sdk-go/aws/session" |
| 8 | + "github.com/aws/aws-sdk-go/service/codedeploy" |
| 9 | + "github.com/rebuy-de/aws-nuke/v2/pkg/types" |
| 10 | +) |
| 11 | + |
| 12 | +type CodeDeployDeploymentConfig struct { |
| 13 | + svc *codedeploy.CodeDeploy |
| 14 | + deploymentConfigName *string |
| 15 | +} |
| 16 | + |
| 17 | +func init() { |
| 18 | + register("CodeDeployDeploymentConfig", ListCodeDeployDeploymentConfigs) |
| 19 | +} |
| 20 | + |
| 21 | +func ListCodeDeployDeploymentConfigs(sess *session.Session) ([]Resource, error) { |
| 22 | + svc := codedeploy.New(sess) |
| 23 | + resources := []Resource{} |
| 24 | + |
| 25 | + params := &codedeploy.ListDeploymentConfigsInput{} |
| 26 | + |
| 27 | + for { |
| 28 | + resp, err := svc.ListDeploymentConfigs(params) |
| 29 | + if err != nil { |
| 30 | + return nil, err |
| 31 | + } |
| 32 | + |
| 33 | + for _, config := range resp.DeploymentConfigsList { |
| 34 | + resources = append(resources, &CodeDeployDeploymentConfig{ |
| 35 | + svc: svc, |
| 36 | + deploymentConfigName: config, |
| 37 | + }) |
| 38 | + } |
| 39 | + |
| 40 | + if resp.NextToken == nil { |
| 41 | + break |
| 42 | + } |
| 43 | + |
| 44 | + params.NextToken = resp.NextToken |
| 45 | + } |
| 46 | + |
| 47 | + return resources, nil |
| 48 | +} |
| 49 | + |
| 50 | +func (f *CodeDeployDeploymentConfig) Filter() error { |
| 51 | + if strings.HasPrefix(*f.deploymentConfigName, "CodeDeployDefault") { |
| 52 | + return fmt.Errorf("cannot delete default codedeploy config") |
| 53 | + } |
| 54 | + return nil |
| 55 | +} |
| 56 | + |
| 57 | +func (f *CodeDeployDeploymentConfig) Remove() error { |
| 58 | + |
| 59 | + _, err := f.svc.DeleteDeploymentConfig(&codedeploy.DeleteDeploymentConfigInput{ |
| 60 | + DeploymentConfigName: f.deploymentConfigName, |
| 61 | + }) |
| 62 | + |
| 63 | + return err |
| 64 | +} |
| 65 | + |
| 66 | +func (f *CodeDeployDeploymentConfig) Properties() types.Properties { |
| 67 | + properties := types.NewProperties() |
| 68 | + properties.Set("DeploymentConfigName", f.deploymentConfigName) |
| 69 | + return properties |
| 70 | +} |
| 71 | + |
| 72 | +func (f *CodeDeployDeploymentConfig) String() string { |
| 73 | + return *f.deploymentConfigName |
| 74 | +} |
0 commit comments