Skip to content

Commit 0bc09f2

Browse files
Adding custom action type support.
1 parent 31d479e commit 0bc09f2

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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/codepipeline"
9+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
10+
)
11+
12+
type CodePipelineCustomActionType struct {
13+
svc *codepipeline.CodePipeline
14+
owner *string
15+
category *string
16+
provider *string
17+
}
18+
19+
func init() {
20+
register("CodePipelineCustomActionType", ListCodePipelineCustomActionTypes)
21+
}
22+
23+
func ListCodePipelineCustomActionTypes(sess *session.Session) ([]Resource, error) {
24+
svc := codepipeline.New(sess)
25+
resources := []Resource{}
26+
27+
params := &codepipeline.ListActionTypesInput{}
28+
29+
for {
30+
resp, err := svc.ListActionTypes(params)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
for _, actionTypes := range resp.ActionTypes {
36+
resources = append(resources, &CodePipelineCustomActionType{
37+
svc: svc,
38+
owner: actionTypes.Id.Owner,
39+
category: actionTypes.Id.Category,
40+
provider: actionTypes.Id.Provider,
41+
})
42+
}
43+
44+
if resp.NextToken == nil {
45+
break
46+
}
47+
48+
params.NextToken = resp.NextToken
49+
}
50+
51+
return resources, nil
52+
}
53+
54+
func (f *CodePipelineCustomActionType) Filter() error {
55+
if !strings.HasPrefix(*f.owner, "Custom") {
56+
return fmt.Errorf("cannot delete default codepipeline custom action type")
57+
}
58+
return nil
59+
}
60+
61+
func (f *CodePipelineCustomActionType) Remove() error {
62+
_, err := f.svc.DeleteCustomActionType(&codepipeline.DeleteCustomActionTypeInput{
63+
Category: f.category,
64+
})
65+
66+
return err
67+
}
68+
69+
func (f *CodePipelineCustomActionType) Properties() types.Properties {
70+
properties := types.NewProperties()
71+
properties.Set("Category", f.category)
72+
properties.Set("Owner", f.owner)
73+
properties.Set("Provider", f.provider)
74+
return properties
75+
}
76+
77+
func (f *CodePipelineCustomActionType) String() string {
78+
return *f.owner
79+
}

0 commit comments

Comments
 (0)