Skip to content

Commit

Permalink
fix acm delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuchiki committed Dec 4, 2017
1 parent 2488dd7 commit d11e814
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
12 changes: 9 additions & 3 deletions acm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion cli/aws-cert-utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d11e814

Please sign in to comment.