diff --git a/README.md b/README.md index bc3bf23..8c651c7 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ Imported arn:aws:acm:us-east-1:xxxxxxxxxxxx:certificate/zzzzzzzz-zzzz-zzzz-zzzz- ```console $ ./aws-cert-utils acm delete -? Choose the server certificate you want to delete : arn:aws:acm:us-east-1:xxxxxxxxxxxx:certificate/zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz +? Choose the server certificate you want to delete : [example.com] arn:aws:acm:us-east-1:xxxxxxxxxxxx:certificate/zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz Deleted arn:aws:acm:us-east-1:xxxxxxxxxxxx:certificate/zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz ``` diff --git a/acm.go b/acm.go index b336de1..01fc8d3 100644 --- a/acm.go +++ b/acm.go @@ -117,15 +117,21 @@ func (a *ACM) List(statuses string, maxItems int64, nextToken string) ([]ACMDesc return descs, err } -func (a *ACM) ListArns(statuses string, maxItems int64, nextToken string) ([]string, error) { +func (a *ACM) ListDeleteTargets(statuses string, maxItems int64, nextToken string) ([]string, map[string]string, error) { descs, err := a.List(statuses, maxItems, nextToken) + if err != nil { + return []string{}, map[string]string{}, err + } + targets := make(map[string]string, 0) arns := make([]string, 0, len(descs)) for _, desc := range descs { - arns = append(arns, desc.arn) + tagArn := fmt.Sprintf("[%s] %s", desc.nameTag, desc.arn) + arns = append(arns, tagArn) + targets[tagArn] = desc.arn } - return arns, err + return arns, targets, err } func toACMTags(tags []Tag) []*acm.Tag { diff --git a/cli/aws-cert-utils/main.go b/cli/aws-cert-utils/main.go index ad7b486..6c269e8 100644 --- a/cli/aws-cert-utils/main.go +++ b/cli/aws-cert-utils/main.go @@ -217,12 +217,14 @@ func main() { case "delete": arn := *acmDeleteArn if arn == "" { - arns, err := a.ListArns(*acmDeleteStatuses, int64(*acmDeleteMaxItems), "") + arns, targets, err := a.ListDeleteTargets(*acmDeleteStatuses, int64(*acmDeleteMaxItems), "") if err != nil { log.Fatal(err) } arn = certutils.Choice(arns, "Choose the server certificate you want to delete : ", 20) + arn = targets[arn] + if arn == "" { os.Exit(0) }