diff --git a/ecrm.go b/ecrm.go index 4d67e5d..b599865 100644 --- a/ecrm.go +++ b/ecrm.go @@ -9,7 +9,6 @@ import ( "github.com/Songmu/prompter" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/arn" awsConfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/ecr" ecrTypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" @@ -157,15 +156,3 @@ func imageTag(d ecrTypes.ImageDetail) (string, bool) { return untaggedStr, false } } - -func arnToName(name, removePrefix string) string { - if arn.IsARN(name) { - a, _ := arn.Parse(name) - return strings.Replace(a.Resource, removePrefix, "", 1) - } - return name -} - -func clusterArnToName(arn string) string { - return arnToName(arn, "cluster/") -} diff --git a/generate.go b/generate.go index 0f8b043..e7053bc 100644 --- a/generate.go +++ b/generate.go @@ -14,7 +14,6 @@ import ( "github.com/Songmu/prompter" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ecr" - ecrTypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/aws/aws-sdk-go-v2/service/ecs" "github.com/aws/aws-sdk-go-v2/service/lambda" "github.com/goccy/go-yaml" @@ -170,7 +169,7 @@ func (g *Generator) generateLambdaConfig(ctx context.Context, config *Config) er } func (g *Generator) generateRepositoryConfig(ctx context.Context, config *Config) error { - repos, err := g.repositories(ctx) + repos, err := ecrRepositories(ctx, ecr.NewFromConfig(g.awsCfg)) if err != nil { return err } @@ -202,16 +201,3 @@ func (g *Generator) generateRepositoryConfig(ctx context.Context, config *Config }) return nil } - -func (g *Generator) repositories(ctx context.Context) ([]ecrTypes.Repository, error) { - repos := make([]ecrTypes.Repository, 0) - p := ecr.NewDescribeRepositoriesPaginator(ecr.NewFromConfig(g.awsCfg), &ecr.DescribeRepositoriesInput{}) - for p.HasMorePages() { - repo, err := p.NextPage(ctx) - if err != nil { - return nil, err - } - repos = append(repos, repo.Repositories...) - } - return repos, nil -} diff --git a/util.go b/util.go index 5593440..8f841c3 100644 --- a/util.go +++ b/util.go @@ -4,7 +4,11 @@ import ( "context" "log" + "strings" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/ecr" ecrTypes "github.com/aws/aws-sdk-go-v2/service/ecr/types" "github.com/aws/aws-sdk-go-v2/service/ecs" "github.com/aws/aws-sdk-go-v2/service/lambda" @@ -79,3 +83,28 @@ func lambdaFunctions(ctx context.Context, client *lambda.Client) ([]lambdaTypes. } return fns, nil } + +func ecrRepositories(ctx context.Context, client *ecr.Client) ([]ecrTypes.Repository, error) { + repos := make([]ecrTypes.Repository, 0) + p := ecr.NewDescribeRepositoriesPaginator(client, &ecr.DescribeRepositoriesInput{}) + for p.HasMorePages() { + repo, err := p.NextPage(ctx) + if err != nil { + return nil, err + } + repos = append(repos, repo.Repositories...) + } + return repos, nil +} + +func arnToName(name, removePrefix string) string { + if arn.IsARN(name) { + a, _ := arn.Parse(name) + return strings.Replace(a.Resource, removePrefix, "", 1) + } + return name +} + +func clusterArnToName(arn string) string { + return arnToName(arn, "cluster/") +}