-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from ekristen/codebuild-reports
feat: adding codebuild reports and reportgroups
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(®istry.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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(®istry.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() | ||
} |