From 54c1ff91ff772912562e48bd6667eba29ac2b76e Mon Sep 17 00:00:00 2001 From: "Gabriela S. Soria" Date: Tue, 3 Oct 2023 14:07:54 +0000 Subject: [PATCH 1/5] Add support for codebuild builds Signed-off-by: Gabriela S. Soria --- resources/codebuild-builds.go | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 resources/codebuild-builds.go diff --git a/resources/codebuild-builds.go b/resources/codebuild-builds.go new file mode 100644 index 000000000..e6e108107 --- /dev/null +++ b/resources/codebuild-builds.go @@ -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 +} From 08d196c1e8c2b34e832c075b386bce6d882df0bd Mon Sep 17 00:00:00 2001 From: "Gabriela S. Soria" Date: Tue, 3 Oct 2023 14:08:42 +0000 Subject: [PATCH 2/5] Add support for codebuild build batches Signed-off-by: Gabriela S. Soria --- resources/codebuild-build-batches.go | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 resources/codebuild-build-batches.go diff --git a/resources/codebuild-build-batches.go b/resources/codebuild-build-batches.go new file mode 100644 index 000000000..c8fb12f62 --- /dev/null +++ b/resources/codebuild-build-batches.go @@ -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 +} From fd2fcaf5242fb606c48acaf54201afac619ede6c Mon Sep 17 00:00:00 2001 From: "Gabriela S. Soria" Date: Tue, 3 Oct 2023 14:09:07 +0000 Subject: [PATCH 3/5] Add support for codebuild report group Signed-off-by: Gabriela S. Soria --- resources/codebuild-report-group.go | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 resources/codebuild-report-group.go diff --git a/resources/codebuild-report-group.go b/resources/codebuild-report-group.go new file mode 100644 index 000000000..f9505efd8 --- /dev/null +++ b/resources/codebuild-report-group.go @@ -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 +} From 12f072b8372757a37f6500e1c5dc621cf4ce425c Mon Sep 17 00:00:00 2001 From: "Gabriela S. Soria" Date: Tue, 3 Oct 2023 14:09:35 +0000 Subject: [PATCH 4/5] Add support for codebuild source credentials Signed-off-by: Gabriela S. Soria --- resources/codebuild-source-credentials.go | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 resources/codebuild-source-credentials.go diff --git a/resources/codebuild-source-credentials.go b/resources/codebuild-source-credentials.go new file mode 100644 index 000000000..ff2c0d671 --- /dev/null +++ b/resources/codebuild-source-credentials.go @@ -0,0 +1,57 @@ +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 + } + + if resp == nil { + return nil, nil + } + + 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 +} From 6c8489e4ab1477da1fb49b3bde73720f6092d209 Mon Sep 17 00:00:00 2001 From: "Gabriela S. Soria" Date: Wed, 4 Oct 2023 18:37:29 +0000 Subject: [PATCH 5/5] Remove unnecessary validation Signed-off-by: Gabriela S. Soria --- resources/codebuild-source-credentials.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/resources/codebuild-source-credentials.go b/resources/codebuild-source-credentials.go index ff2c0d671..d2d742800 100644 --- a/resources/codebuild-source-credentials.go +++ b/resources/codebuild-source-credentials.go @@ -24,14 +24,11 @@ func ListCodeBuildSourceCredential(sess *session.Session) ([]Resource, error) { params := &codebuild.ListSourceCredentialsInput{} resp, err := svc.ListSourceCredentials(params) + if err != nil { return nil, err } - if resp == nil { - return nil, nil - } - for _, credential := range resp.SourceCredentialsInfos { resources = append(resources, &CodeBuildSourceCredential{ svc: svc,