diff --git a/resources/codeguru-reviewer-repository-association.go b/resources/codeguru-reviewer-repository-association.go new file mode 100644 index 00000000..cd1c1a66 --- /dev/null +++ b/resources/codeguru-reviewer-repository-association.go @@ -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(®istry.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) +} diff --git a/resources/codegurureviewer-repository-associations.go b/resources/codegurureviewer-repository-associations.go deleted file mode 100644 index e630ad94..00000000 --- a/resources/codegurureviewer-repository-associations.go +++ /dev/null @@ -1,72 +0,0 @@ -package resources - -import ( - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/codegurureviewer" - "github.com/rebuy-de/aws-nuke/v2/pkg/types" -) - -type CodeGuruReviewerRepositoryAssociation struct { - svc *codegurureviewer.CodeGuruReviewer - AssociationArn *string - AssociationId *string - Name *string - Owner *string - ProviderType *string -} - -func init() { - register("CodeGuruReviewerRepositoryAssociation", ListCodeGuruReviewerRepositoryAssociations, - mapCloudControl("AWS::CodeGuruReviewer::RepositoryAssociation")) -} - -func ListCodeGuruReviewerRepositoryAssociations(sess *session.Session) ([]Resource, error) { - svc := codegurureviewer.New(sess) - resources := []Resource{} - - 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 -} - -func (f *CodeGuruReviewerRepositoryAssociation) Remove() error { - _, err := f.svc.DisassociateRepository(&codegurureviewer.DisassociateRepositoryInput{ - AssociationArn: f.AssociationArn, - }) - return err -} - -func (f *CodeGuruReviewerRepositoryAssociation) Properties() types.Properties { - properties := types.NewProperties() - properties. - Set("AssociationArn", f.AssociationArn) - properties.Set("AssociationId", f.AssociationId) - properties.Set("Name", f.Name) - properties.Set("Owner", f.Owner) - properties.Set("ProviderType", f.ProviderType) - return properties -}