Skip to content

Commit

Permalink
Merge pull request #341 from ekristen/rebuy-1139
Browse files Browse the repository at this point in the history
feat(resource): add code guru reviewer repository association resource
  • Loading branch information
ekristen authored Oct 2, 2024
2 parents 9ac7c54 + 375bfd0 commit 575e40b
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions resources/codeguru-reviewer-repository-association.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package resources

import (
"context"

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

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

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

const CodeGuruReviewerRepositoryAssociationResource = "CodeGuruReviewerRepositoryAssociation"

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

type CodeGuruReviewerRepositoryAssociationLister struct{}

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

svc := codegurureviewer.New(opts.Session)

params := &codegurureviewer.ListRepositoryAssociationsInput{}

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

for _, association := range resp.RepositoryAssociationSummaries {
resources = append(resources, &CodeGuruReviewerRepositoryAssociation{
svc: svc,
AssociationARN: association.AssociationArn,
AssociationID: association.AssociationId,
Name: association.Name,
Owner: association.Owner,
ProviderType: association.ProviderType,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type CodeGuruReviewerRepositoryAssociation struct {
svc *codegurureviewer.CodeGuruReviewer
AssociationARN *string
AssociationID *string
Name *string
Owner *string
ProviderType *string
}

func (r *CodeGuruReviewerRepositoryAssociation) Remove(_ context.Context) error {
_, err := r.svc.DisassociateRepository(&codegurureviewer.DisassociateRepositoryInput{
AssociationArn: r.AssociationARN,
})
return err
}

func (r *CodeGuruReviewerRepositoryAssociation) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

0 comments on commit 575e40b

Please sign in to comment.