Skip to content

Commit 076892d

Browse files
authored
Merge pull request #17 from oreillymedia/codebuild-support
Support for additional codebuild resources
2 parents a90dcf2 + 6c8489e commit 076892d

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/codebuild"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type CodeBuildBuildBatch struct {
10+
svc *codebuild.CodeBuild
11+
Id *string
12+
}
13+
14+
func init() {
15+
register("CodeBuildBuildBatch", ListCodeBuildBuildBatch)
16+
}
17+
18+
func ListCodeBuildBuildBatch(sess *session.Session) ([]Resource, error) {
19+
svc := codebuild.New(sess)
20+
resources := []Resource{}
21+
22+
params := &codebuild.ListBuildBatchesInput{}
23+
24+
for {
25+
resp, err := svc.ListBuildBatches(params)
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
for _, batch := range resp.Ids {
31+
resources = append(resources, &CodeBuildBuildBatch{
32+
svc: svc,
33+
Id: batch,
34+
})
35+
}
36+
37+
if resp.NextToken == nil {
38+
break
39+
}
40+
41+
params.NextToken = resp.NextToken
42+
}
43+
44+
return resources, nil
45+
}
46+
47+
func (f *CodeBuildBuildBatch) Remove() error {
48+
_, err := f.svc.DeleteBuildBatch(&codebuild.DeleteBuildBatchInput{
49+
Id: f.Id,
50+
})
51+
52+
return err
53+
}
54+
55+
func (f *CodeBuildBuildBatch) Properties() types.Properties {
56+
properties := types.NewProperties()
57+
properties.
58+
Set("Id", f.Id)
59+
return properties
60+
}

resources/codebuild-builds.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/codebuild"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type CodeBuildBuild struct {
10+
svc *codebuild.CodeBuild
11+
Id *string
12+
}
13+
14+
func init() {
15+
register("CodeBuildBuild", ListCodeBuildBuild)
16+
}
17+
18+
func ListCodeBuildBuild(sess *session.Session) ([]Resource, error) {
19+
svc := codebuild.New(sess)
20+
resources := []Resource{}
21+
22+
params := &codebuild.ListBuildsInput{}
23+
24+
for {
25+
resp, err := svc.ListBuilds(params)
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
for _, build := range resp.Ids {
31+
resources = append(resources, &CodeBuildBuild{
32+
svc: svc,
33+
Id: build,
34+
})
35+
}
36+
37+
if resp.NextToken == nil {
38+
break
39+
}
40+
41+
params.NextToken = resp.NextToken
42+
}
43+
44+
return resources, nil
45+
}
46+
47+
func (f *CodeBuildBuild) Remove() error {
48+
_, err := f.svc.BatchDeleteBuilds(&codebuild.BatchDeleteBuildsInput{
49+
Ids: []*string{f.Id},
50+
})
51+
52+
return err
53+
}
54+
55+
func (f *CodeBuildBuild) Properties() types.Properties {
56+
properties := types.NewProperties()
57+
properties.
58+
Set("Id", f.Id)
59+
return properties
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/codebuild"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type CodeBuildReportGroup struct {
10+
svc *codebuild.CodeBuild
11+
Arn *string
12+
}
13+
14+
func init() {
15+
register("CodeBuildReportGroup", ListCodeBuildReportGroup)
16+
}
17+
18+
func ListCodeBuildReportGroup(sess *session.Session) ([]Resource, error) {
19+
svc := codebuild.New(sess)
20+
resources := []Resource{}
21+
22+
params := &codebuild.ListReportGroupsInput{}
23+
24+
for {
25+
resp, err := svc.ListReportGroups(params)
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
for _, reportGroup := range resp.ReportGroups {
31+
resources = append(resources, &CodeBuildReportGroup{
32+
svc: svc,
33+
Arn: reportGroup,
34+
})
35+
}
36+
37+
if resp.NextToken == nil {
38+
break
39+
}
40+
41+
params.NextToken = resp.NextToken
42+
}
43+
44+
return resources, nil
45+
}
46+
47+
func (f *CodeBuildReportGroup) Remove() error {
48+
_, err := f.svc.DeleteReportGroup(&codebuild.DeleteReportGroupInput{
49+
Arn: f.Arn,
50+
})
51+
52+
return err
53+
}
54+
55+
func (f *CodeBuildReportGroup) Properties() types.Properties {
56+
properties := types.NewProperties()
57+
properties.
58+
Set("Arn", f.Arn)
59+
return properties
60+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/codebuild"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type CodeBuildSourceCredential struct {
10+
svc *codebuild.CodeBuild
11+
Arn *string
12+
AuthType *string
13+
ServerType *string
14+
}
15+
16+
func init() {
17+
register("CodeBuildSourceCredential", ListCodeBuildSourceCredential)
18+
}
19+
20+
func ListCodeBuildSourceCredential(sess *session.Session) ([]Resource, error) {
21+
svc := codebuild.New(sess)
22+
resources := []Resource{}
23+
24+
params := &codebuild.ListSourceCredentialsInput{}
25+
26+
resp, err := svc.ListSourceCredentials(params)
27+
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
for _, credential := range resp.SourceCredentialsInfos {
33+
resources = append(resources, &CodeBuildSourceCredential{
34+
svc: svc,
35+
Arn: credential.Arn,
36+
})
37+
}
38+
39+
return resources, nil
40+
}
41+
42+
func (f *CodeBuildSourceCredential) Remove() error {
43+
_, err := f.svc.DeleteSourceCredentials(&codebuild.DeleteSourceCredentialsInput{Arn: f.Arn})
44+
return err
45+
}
46+
47+
func (f *CodeBuildSourceCredential) Properties() types.Properties {
48+
properties := types.NewProperties()
49+
properties.Set("Arn", f.Arn)
50+
properties.Set("AuthType", f.AuthType)
51+
properties.Set("ServerType", f.ServerType)
52+
53+
return properties
54+
}

0 commit comments

Comments
 (0)