Skip to content

Commit

Permalink
updated per code review
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <patrickzheng@microsoft.com>
  • Loading branch information
Two-Hearts committed May 25, 2023
1 parent 7f5127e commit 34d44e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 15 additions & 2 deletions cmd/notation/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func deleteKeys(ctx context.Context, opts *keyDeleteOpts) error {

// core process
var deletedNames []string
var prevDefault string
exec := func(s *config.SigningKeys) error {
if s.Default != nil {
prevDefault = *s.Default
}
var err error
deletedNames, err = s.Remove(opts.names...)
if err != nil {
Expand All @@ -241,11 +245,20 @@ func deleteKeys(ctx context.Context, opts *keyDeleteOpts) error {

// write out
if len(deletedNames) == 1 {
fmt.Printf("Removed %s from Notation signing key list. The source key still exists.\n", deletedNames[0])
name := deletedNames[0]
if name == prevDefault {
fmt.Printf("Removed default key %s from Notation signing key list. The source key still exists.\n", name)
} else {
fmt.Printf("Removed %s from Notation signing key list. The source key still exists.\n", name)
}
} else if len(deletedNames) > 1 {
fmt.Println("Removed the following keys from Notation signing key list. The source keys still exist.")
for _, name := range deletedNames {
fmt.Println(name)
if name == prevDefault {
fmt.Println(name, "(default)")
} else {
fmt.Println(name)
}
}
}
return nil
Expand Down
7 changes: 6 additions & 1 deletion specs/commandline/key.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ Removed <key_name> from Notation signing key list. The source key still exists.

```text
Removed <key_name> from Notation signing key list. The source key still exists.
- Upon successful removal of the default key, the output message is printed out as follows:
```text
Removed default key <key_name> from Notation signing key list. The source key still exists.
```

### Remove two keys from Notation signing key list
Expand All @@ -143,5 +148,5 @@ Upon successful execution, the output message is printed out as follows. Please
```text
Removed the following keys from Notation signing key list. The source keys still exist.
<key_name_1>
<key_name_2>
<key_name_2> (default)
```

0 comments on commit 34d44e1

Please sign in to comment.