From 7f5127e2798d1928ebbca917310c663ccf38998a Mon Sep 17 00:00:00 2001 From: Patrick Zheng Date: Thu, 25 May 2023 15:00:57 +0800 Subject: [PATCH 1/3] based on spec, updated messages of notation key command Signed-off-by: Patrick Zheng --- cmd/notation/key.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/notation/key.go b/cmd/notation/key.go index aff21f636..863d589ea 100644 --- a/cmd/notation/key.go +++ b/cmd/notation/key.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" - "github.com/notaryproject/notation-go/config" "os" + "github.com/notaryproject/notation-go/config" + "github.com/notaryproject/notation-go/log" "github.com/notaryproject/notation/internal/cmd" "github.com/notaryproject/notation/internal/ioutil" @@ -74,7 +75,7 @@ func keyAddCommand(opts *keyAddOpts) *cobra.Command { } command := &cobra.Command{ Use: "add --plugin [flags] ", - Short: "Add key to signing key list", + Short: "Add key to Notation signing key list", Args: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("either missing key name or unnecessary parameters passed") @@ -105,7 +106,7 @@ func keyUpdateCommand(opts *keyUpdateOpts) *cobra.Command { command := &cobra.Command{ Use: "update [flags] ", Aliases: []string{"set"}, - Short: "Update key in signing key list", + Short: "Update key in Notation signing key list", Args: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("missing key name") @@ -142,7 +143,7 @@ func keyDeleteCommand(opts *keyDeleteOpts) *cobra.Command { command := &cobra.Command{ Use: "delete [flags] ...", - Short: "Delete key from signing key list", + Short: "Remove key from Notation signing key list", Args: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return errors.New("missing key names") @@ -226,11 +227,7 @@ 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 { @@ -243,10 +240,11 @@ func deleteKeys(ctx context.Context, opts *keyDeleteOpts) error { } // write out - for _, name := range deletedNames { - if prevDefault == name { - fmt.Printf("%s: unmarked as default\n", name) - } else { + if len(deletedNames) == 1 { + fmt.Printf("Removed %s from Notation signing key list. The source key still exists.\n", deletedNames[0]) + } 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) } } From 34d44e1e41ba5a060dd2383533890e9c1806137f Mon Sep 17 00:00:00 2001 From: Patrick Zheng Date: Thu, 25 May 2023 16:15:23 +0800 Subject: [PATCH 2/3] updated per code review Signed-off-by: Patrick Zheng --- cmd/notation/key.go | 17 +++++++++++++++-- specs/commandline/key.md | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/notation/key.go b/cmd/notation/key.go index 863d589ea..9764bdbd0 100644 --- a/cmd/notation/key.go +++ b/cmd/notation/key.go @@ -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 { @@ -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 diff --git a/specs/commandline/key.md b/specs/commandline/key.md index bc5b64a64..70019ab49 100644 --- a/specs/commandline/key.md +++ b/specs/commandline/key.md @@ -130,6 +130,11 @@ Removed from Notation signing key list. The source key still exists. ```text Removed 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 from Notation signing key list. The source key still exists. ``` ### Remove two keys from Notation signing key list @@ -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. - + (default) ``` \ No newline at end of file From 61f4a8eefbc2cfc781453e91a21e2671c471cc64 Mon Sep 17 00:00:00 2001 From: Patrick Zheng Date: Thu, 25 May 2023 16:44:59 +0800 Subject: [PATCH 3/3] update Signed-off-by: Patrick Zheng --- specs/commandline/key.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/commandline/key.md b/specs/commandline/key.md index 70019ab49..dbd9fd72a 100644 --- a/specs/commandline/key.md +++ b/specs/commandline/key.md @@ -130,6 +130,7 @@ Removed from Notation signing key list. The source key still exists. ```text Removed 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: