Skip to content

Commit

Permalink
Merge pull request #172 from ekristen/codebuild-reports
Browse files Browse the repository at this point in the history
feat: adding codebuild reports and reportgroups
  • Loading branch information
ekristen authored Jun 8, 2024
2 parents 1097aec + d38db80 commit 02216b2
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
72 changes: 72 additions & 0 deletions resources/codebuild-report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

import (
"context"
"strings"

"github.com/aws/aws-sdk-go/service/codebuild"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

const CodeBuildReportResource = "CodeBuildReport"

func init() {
registry.Register(&registry.Registration{
Name: CodeBuildReportResource,
Scope: nuke.Account,
Lister: &CodeBuildReportLister{},
})
}

type CodeBuildReportLister struct{}

func (l *CodeBuildReportLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := codebuild.New(opts.Session)
var resources []resource.Resource

res, err := svc.ListReports(&codebuild.ListReportsInput{})
if err != nil {
return nil, err
}

for _, arn := range res.Reports {
resources = append(resources, &CodeBuildReport{
svc: svc,
arn: arn,
})
}

return resources, nil
}

type CodeBuildReport struct {
svc *codebuild.CodeBuild
arn *string
}

func (r *CodeBuildReport) Name() string {
return strings.Split(*r.arn, "report/")[1]
}

func (r *CodeBuildReport) Remove(_ context.Context) error {
_, err := r.svc.DeleteReport(&codebuild.DeleteReportInput{
Arn: r.arn,
})
return err
}

func (r *CodeBuildReport) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", r.Name())
return properties
}

func (r *CodeBuildReport) String() string {
return r.Name()
}
78 changes: 78 additions & 0 deletions resources/codebuild-reportgroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package resources

import (
"context"
"strings"

"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/service/codebuild"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

const CodeBuildReportGroupResource = "CodeBuildReportGroup"

func init() {
registry.Register(&registry.Registration{
Name: CodeBuildReportGroupResource,
Scope: nuke.Account,
Lister: &CodebuildReportGroupLister{},
DependsOn: []string{
CodeBuildReportResource,
},
})
}

type CodebuildReportGroupLister struct{}

func (l *CodebuildReportGroupLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := codebuild.New(opts.Session)
var resources []resource.Resource

res, err := svc.ListReportGroups(&codebuild.ListReportGroupsInput{})
if err != nil {
return nil, err
}

for _, arn := range res.ReportGroups {
resources = append(resources, &CodebuildReportGroup{
svc: svc,
arn: arn,
})
}

return resources, nil
}

type CodebuildReportGroup struct {
svc *codebuild.CodeBuild
arn *string
}

func (r *CodebuildReportGroup) Name() string {
return strings.Split(*r.arn, "report-group/")[1]
}

func (r *CodebuildReportGroup) Remove(_ context.Context) error {
_, err := r.svc.DeleteReportGroup(&codebuild.DeleteReportGroupInput{
Arn: r.arn,
DeleteReports: ptr.Bool(true),
})
return err
}

func (r *CodebuildReportGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", r.Name())
return properties
}

func (r *CodebuildReportGroup) String() string {
return r.Name()
}

0 comments on commit 02216b2

Please sign in to comment.