Skip to content

Commit

Permalink
Add ECRPublicRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
fridim committed Nov 21, 2023
1 parent b41b6e5 commit 987a2bf
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
1 change: 0 additions & 1 deletion resources/cloudcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func init() {
registerCloudControl("AWS::AppRunner::Service")
registerCloudControl("AWS::ApplicationInsights::Application")
registerCloudControl("AWS::Backup::Framework")
registerCloudControl("AWS::ECR::PublicRepository")
registerCloudControl("AWS::ECR::PullThroughCacheRule")
registerCloudControl("AWS::ECR::RegistryPolicy")
registerCloudControl("AWS::ECR::ReplicationConfiguration")
Expand Down
89 changes: 89 additions & 0 deletions resources/ecr-public-repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package resources

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecrpublic"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ECRPublicRepository struct {
svc *ecrpublic.ECRPublic
name *string
createdTime *time.Time
tags []*ecrpublic.Tag
}

func init() {
register("ECRPublicRepository", ListECRPublicRepositories)
}

func ListECRPublicRepositories(sess *session.Session) ([]Resource, error) {
svc := ecrpublic.New(sess)
resources := []Resource{}

input := &ecrpublic.DescribeRepositoriesInput{
MaxResults: aws.Int64(100),
}

for {
output, err := svc.DescribeRepositories(input)
if err != nil {
return nil, err
}

for _, repository := range output.Repositories {
fmt.Println(repository)
tagResp, err := svc.ListTagsForResource(&ecrpublic.ListTagsForResourceInput{
ResourceArn: repository.RepositoryArn,
})
if err != nil {
return nil, err
}
resources = append(resources, &ECRPublicRepository{
svc: svc,
name: repository.RepositoryName,
createdTime: repository.CreatedAt,
tags: tagResp.Tags,
})
}

if output.NextToken == nil {
break
}

input.NextToken = output.NextToken
}

return resources, nil
}

func (r *ECRPublicRepository) Filter() error {
return nil
}

func (r *ECRPublicRepository) Properties() types.Properties {
properties := types.NewProperties().
Set("CreatedTime", r.createdTime.Format(time.RFC3339))

for _, t := range r.tags {
properties.SetTag(t.Key, t.Value)
}
return properties
}

func (r *ECRPublicRepository) Remove() error {
params := &ecrpublic.DeleteRepositoryInput{
RepositoryName: r.name,
Force: aws.Bool(true),
}
_, err := r.svc.DeleteRepository(params)
return err
}

func (r *ECRPublicRepository) String() string {
return fmt.Sprintf("Repository: %s", *r.name)
}

0 comments on commit 987a2bf

Please sign in to comment.