From 836521e166a22b05bf1f0ac16edb62a9dd8883ca Mon Sep 17 00:00:00 2001 From: Diogo Monica Date: Tue, 16 Jun 2015 11:10:35 -0700 Subject: [PATCH] Refactor cmdline key naming and added TUF skeletons --- cmd/notary/keys.go | 6 ++--- cmd/notary/{list.go => keys_list.go} | 7 +++--- cmd/notary/{remove.go => keys_remove.go} | 10 ++++----- cmd/notary/{trust.go => keys_trust.go} | 10 ++++----- cmd/notary/main.go | 5 +++-- cmd/notary/tuf.go | 8 ++++--- cmd/notary/tuf_add.go | 17 ++++++++++++++ cmd/notary/tuf_init.go | 17 ++++++++++++++ cmd/notary/tuf_list.go | 17 ++++++++++++++ cmd/notary/tuf_lookup.go | 28 ++++++++++++++++++++++++ cmd/notary/tuf_push.go | 27 +++++++++++++++++++++++ cmd/notary/tuf_remove.go | 17 ++++++++++++++ 12 files changed, 147 insertions(+), 22 deletions(-) rename cmd/notary/{list.go => keys_list.go} (87%) rename cmd/notary/{remove.go => keys_remove.go} (80%) rename cmd/notary/{trust.go => keys_trust.go} (89%) create mode 100644 cmd/notary/tuf_add.go create mode 100644 cmd/notary/tuf_init.go create mode 100644 cmd/notary/tuf_list.go create mode 100644 cmd/notary/tuf_lookup.go create mode 100644 cmd/notary/tuf_push.go create mode 100644 cmd/notary/tuf_remove.go diff --git a/cmd/notary/keys.go b/cmd/notary/keys.go index 5feee889b1..94606a02e3 100644 --- a/cmd/notary/keys.go +++ b/cmd/notary/keys.go @@ -2,9 +2,9 @@ package main import "github.com/spf13/cobra" -var keysCmd = &cobra.Command{ +var cmdKeys = &cobra.Command{ Use: "keys", - Short: "Operates on keys", - Long: "operations on signature keys and trusted certificate authorities", + Short: "Operates on keys.", + Long: "operations on signature keys and trusted certificate authorities.", Run: nil, } diff --git a/cmd/notary/list.go b/cmd/notary/keys_list.go similarity index 87% rename from cmd/notary/list.go rename to cmd/notary/keys_list.go index 840ea4a5e8..946f42c073 100644 --- a/cmd/notary/list.go +++ b/cmd/notary/keys_list.go @@ -11,18 +11,17 @@ import ( "github.com/spf13/cobra" ) -var cmdList = &cobra.Command{ +var cmdKeysList = &cobra.Command{ Use: "list", Short: "List the currently trusted certificate authorities.", Long: "lists the currently trusted certificate authorities.", - Run: list, + Run: keysList, } -func list(cmd *cobra.Command, args []string) { +func keysList(cmd *cobra.Command, args []string) { // Load all the certificates trustedCAs := caStore.GetCertificates() - fmt.Println("CAs Loaded:") for _, c := range trustedCAs { print_cert(c) } diff --git a/cmd/notary/remove.go b/cmd/notary/keys_remove.go similarity index 80% rename from cmd/notary/remove.go rename to cmd/notary/keys_remove.go index 6edb122bc4..cc47afd802 100644 --- a/cmd/notary/remove.go +++ b/cmd/notary/keys_remove.go @@ -7,16 +7,16 @@ import ( ) var ( - subjectKeyID string - cmdRemove = &cobra.Command{ + subjectKeyID string + cmdKeysRemove = &cobra.Command{ Use: "remove [ Subject Key ID ]", - Short: "removes trust from a specific certificate authority or certificate", + Short: "removes trust from a specific certificate authority or certificate.", Long: "remove trust from a specific certificate authority.", - Run: remove, + Run: keysRemove, } ) -func remove(cmd *cobra.Command, args []string) { +func keysRemove(cmd *cobra.Command, args []string) { if len(args) < 1 { cmd.Usage() fatalf("must specify a SHA256 SubjectKeyID of the certificate") diff --git a/cmd/notary/trust.go b/cmd/notary/keys_trust.go similarity index 89% rename from cmd/notary/trust.go rename to cmd/notary/keys_trust.go index d5d5452f71..d243ad7c66 100644 --- a/cmd/notary/trust.go +++ b/cmd/notary/keys_trust.go @@ -9,14 +9,14 @@ import ( "github.com/spf13/cobra" ) -var cmdtrust = &cobra.Command{ +var cmdKeysTrust = &cobra.Command{ Use: "trust [ QDN ] [ certificate ]", Short: "Trusts a new certificate for a specific QDN.", Long: "Adds a the certificate to the trusted certificate authority list for the specified Qualified Docker Name.", - Run: trust, + Run: keysTrust, } -func trust(cmd *cobra.Command, args []string) { +func keysTrust(cmd *cobra.Command, args []string) { if len(args) < 2 { cmd.Usage() fatalf("not enough arguments provided") @@ -40,8 +40,8 @@ func trust(cmd *cobra.Command, args []string) { if err != nil { fatalf("error adding certificate from file: %v", err) } - - fmt.Println(string(cert.RawSubject)) + fmt.Printf("Adding: ") + print_cert(cert) } else if _, err := os.Stat(certLocationStr); err == nil { if err := caStore.AddCertFromFile(certLocationStr); err != nil { fatalf("error adding certificate from file: %v", err) diff --git a/cmd/notary/main.go b/cmd/notary/main.go index 0a24495bfd..6221590ece 100644 --- a/cmd/notary/main.go +++ b/cmd/notary/main.go @@ -74,8 +74,9 @@ func main() { Long: "notary is the main trust-related command for Docker.", } - NotaryCmd.AddCommand(keysCmd, tufCmd) - keysCmd.AddCommand(cmdtrust, cmdList, cmdRemove) + NotaryCmd.AddCommand(cmdKeys, cmdTuf) + cmdKeys.AddCommand(cmdKeysTrust, cmdKeysList, cmdKeysRemove) + cmdTuf.AddCommand(cmdTufInit, cmdTufAdd, cmdTufRemove, cmdTufPush, cmdTufLookup, cmdTufList) NotaryCmd.Execute() } diff --git a/cmd/notary/tuf.go b/cmd/notary/tuf.go index 8db0b81777..11cdb67e95 100644 --- a/cmd/notary/tuf.go +++ b/cmd/notary/tuf.go @@ -2,9 +2,11 @@ package main import "github.com/spf13/cobra" -var tufCmd = &cobra.Command{ +var cmdTuf = &cobra.Command{ Use: "tuf", - Short: "Manages trust of data for notary", - Long: "manages signed repository metadata", + Short: "Manages trust of data for notary.", + Long: "manages signed repository metadata.", Run: nil, } + +var remoteTrustServer string diff --git a/cmd/notary/tuf_add.go b/cmd/notary/tuf_add.go new file mode 100644 index 0000000000..e6819e8765 --- /dev/null +++ b/cmd/notary/tuf_add.go @@ -0,0 +1,17 @@ +package main + +import "github.com/spf13/cobra" + +var cmdTufAdd = &cobra.Command{ + Use: "add [ QDN ] ", + Short: "pushes local updates.", + Long: "pushes all local updates within a specific TUF repo to remote trust server.", + Run: tufAdd, +} + +func tufAdd(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } +} diff --git a/cmd/notary/tuf_init.go b/cmd/notary/tuf_init.go new file mode 100644 index 0000000000..c1875c1ca5 --- /dev/null +++ b/cmd/notary/tuf_init.go @@ -0,0 +1,17 @@ +package main + +import "github.com/spf13/cobra" + +var cmdTufInit = &cobra.Command{ + Use: "init [ QDN ]", + Short: "initializes the local TUF repository.", + Long: "creates locally the initial set of TUF metadata for the Qualified Docker Name.", + Run: tufInit, +} + +func tufInit(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } +} diff --git a/cmd/notary/tuf_list.go b/cmd/notary/tuf_list.go new file mode 100644 index 0000000000..e6e26b2ec9 --- /dev/null +++ b/cmd/notary/tuf_list.go @@ -0,0 +1,17 @@ +package main + +import "github.com/spf13/cobra" + +var cmdTufList = &cobra.Command{ + Use: "list [ QDN ]", + Short: "Lists all targets in a TUF repository.", + Long: "lists all the targets in the TUF repository identified by the Qualified Docker Name.", + Run: tufList, +} + +func tufList(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } +} diff --git a/cmd/notary/tuf_lookup.go b/cmd/notary/tuf_lookup.go new file mode 100644 index 0000000000..6733f76008 --- /dev/null +++ b/cmd/notary/tuf_lookup.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var cmdTufLookup = &cobra.Command{ + Use: "lookup [ QDN ] ", + Short: "Looks up a specific TUF target in a repository.", + Long: "looks up a TUF target in a repository given a Qualified Docker Name.", + Run: tufLookup, +} + +func init() { + cmdTufLookup.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location") +} + +func tufLookup(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } + + fmt.Println("Remote trust server configured: " + remoteTrustServer) + +} diff --git a/cmd/notary/tuf_push.go b/cmd/notary/tuf_push.go new file mode 100644 index 0000000000..bb6f24fba6 --- /dev/null +++ b/cmd/notary/tuf_push.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var cmdTufPush = &cobra.Command{ + Use: "push [ QDN ]", + Short: "initializes the local TUF repository.", + Long: "creates locally the initial set of TUF metadata for the Qualified Docker Name.", + Run: tufPush, +} + +func init() { + cmdTufPush.Flags().StringVarP(&remoteTrustServer, "remote", "r", "", "Remote trust server location") +} + +func tufPush(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } + + fmt.Println("Remote trust server configured: " + remoteTrustServer) +} diff --git a/cmd/notary/tuf_remove.go b/cmd/notary/tuf_remove.go new file mode 100644 index 0000000000..111ae8aac0 --- /dev/null +++ b/cmd/notary/tuf_remove.go @@ -0,0 +1,17 @@ +package main + +import "github.com/spf13/cobra" + +var cmdTufRemove = &cobra.Command{ + Use: "remove [ QDN ] ", + Short: "Removes a target from the TUF repo.", + Long: "removes a target from the local TUF repo identified by a Qualified Docker Name.", + Run: tufRemove, +} + +func tufRemove(cmd *cobra.Command, args []string) { + if len(args) < 1 { + cmd.Usage() + fatalf("must specify a QDN") + } +}