Skip to content

Commit

Permalink
refactor(codeguru-reviewer): convert to libnuke resource standard format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Sep 30, 2024
1 parent ed78a91 commit 375bfd0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 72 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)
}
72 changes: 0 additions & 72 deletions resources/codegurureviewer-repository-associations.go

This file was deleted.

0 comments on commit 375bfd0

Please sign in to comment.