Skip to content

Commit

Permalink
Merge pull request #17 from oreillymedia/codebuild-support
Browse files Browse the repository at this point in the history
Support for additional codebuild resources
  • Loading branch information
gsoria authored Oct 4, 2023
2 parents a90dcf2 + 6c8489e commit 076892d
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 0 deletions.
60 changes: 60 additions & 0 deletions resources/codebuild-build-batches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeBuildBuildBatch struct {
svc *codebuild.CodeBuild
Id *string
}

func init() {
register("CodeBuildBuildBatch", ListCodeBuildBuildBatch)
}

func ListCodeBuildBuildBatch(sess *session.Session) ([]Resource, error) {
svc := codebuild.New(sess)
resources := []Resource{}

params := &codebuild.ListBuildBatchesInput{}

for {
resp, err := svc.ListBuildBatches(params)
if err != nil {
return nil, err
}

for _, batch := range resp.Ids {
resources = append(resources, &CodeBuildBuildBatch{
svc: svc,
Id: batch,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (f *CodeBuildBuildBatch) Remove() error {
_, err := f.svc.DeleteBuildBatch(&codebuild.DeleteBuildBatchInput{
Id: f.Id,
})

return err
}

func (f *CodeBuildBuildBatch) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("Id", f.Id)
return properties
}
60 changes: 60 additions & 0 deletions resources/codebuild-builds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeBuildBuild struct {
svc *codebuild.CodeBuild
Id *string
}

func init() {
register("CodeBuildBuild", ListCodeBuildBuild)
}

func ListCodeBuildBuild(sess *session.Session) ([]Resource, error) {
svc := codebuild.New(sess)
resources := []Resource{}

params := &codebuild.ListBuildsInput{}

for {
resp, err := svc.ListBuilds(params)
if err != nil {
return nil, err
}

for _, build := range resp.Ids {
resources = append(resources, &CodeBuildBuild{
svc: svc,
Id: build,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (f *CodeBuildBuild) Remove() error {
_, err := f.svc.BatchDeleteBuilds(&codebuild.BatchDeleteBuildsInput{
Ids: []*string{f.Id},
})

return err
}

func (f *CodeBuildBuild) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("Id", f.Id)
return properties
}
60 changes: 60 additions & 0 deletions resources/codebuild-report-group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeBuildReportGroup struct {
svc *codebuild.CodeBuild
Arn *string
}

func init() {
register("CodeBuildReportGroup", ListCodeBuildReportGroup)
}

func ListCodeBuildReportGroup(sess *session.Session) ([]Resource, error) {
svc := codebuild.New(sess)
resources := []Resource{}

params := &codebuild.ListReportGroupsInput{}

for {
resp, err := svc.ListReportGroups(params)
if err != nil {
return nil, err
}

for _, reportGroup := range resp.ReportGroups {
resources = append(resources, &CodeBuildReportGroup{
svc: svc,
Arn: reportGroup,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (f *CodeBuildReportGroup) Remove() error {
_, err := f.svc.DeleteReportGroup(&codebuild.DeleteReportGroupInput{
Arn: f.Arn,
})

return err
}

func (f *CodeBuildReportGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("Arn", f.Arn)
return properties
}
54 changes: 54 additions & 0 deletions resources/codebuild-source-credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codebuild"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CodeBuildSourceCredential struct {
svc *codebuild.CodeBuild
Arn *string
AuthType *string
ServerType *string
}

func init() {
register("CodeBuildSourceCredential", ListCodeBuildSourceCredential)
}

func ListCodeBuildSourceCredential(sess *session.Session) ([]Resource, error) {
svc := codebuild.New(sess)
resources := []Resource{}

params := &codebuild.ListSourceCredentialsInput{}

resp, err := svc.ListSourceCredentials(params)

if err != nil {
return nil, err
}

for _, credential := range resp.SourceCredentialsInfos {
resources = append(resources, &CodeBuildSourceCredential{
svc: svc,
Arn: credential.Arn,
})
}

return resources, nil
}

func (f *CodeBuildSourceCredential) Remove() error {
_, err := f.svc.DeleteSourceCredentials(&codebuild.DeleteSourceCredentialsInput{Arn: f.Arn})
return err
}

func (f *CodeBuildSourceCredential) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Arn", f.Arn)
properties.Set("AuthType", f.AuthType)
properties.Set("ServerType", f.ServerType)

return properties
}

0 comments on commit 076892d

Please sign in to comment.