Refactor cmdline key naming and added TUF skeletons

This commit is contained in:
Diogo Monica 2015-06-16 11:10:35 -07:00 committed by David Lawrence
parent 931c5e2a9b
commit 836521e166
12 changed files with 147 additions and 22 deletions

View File

@ -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,
}

View File

@ -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)
}

View File

@ -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")

View File

@ -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)

View File

@ -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()
}

View File

@ -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

17
cmd/notary/tuf_add.go Normal file
View File

@ -0,0 +1,17 @@
package main
import "github.com/spf13/cobra"
var cmdTufAdd = &cobra.Command{
Use: "add [ QDN ] <target> <file path>",
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")
}
}

17
cmd/notary/tuf_init.go Normal file
View File

@ -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")
}
}

17
cmd/notary/tuf_list.go Normal file
View File

@ -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")
}
}

28
cmd/notary/tuf_lookup.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"github.com/spf13/cobra"
)
var cmdTufLookup = &cobra.Command{
Use: "lookup [ QDN ] <target name>",
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)
}

27
cmd/notary/tuf_push.go Normal file
View File

@ -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)
}

17
cmd/notary/tuf_remove.go Normal file
View File

@ -0,0 +1,17 @@
package main
import "github.com/spf13/cobra"
var cmdTufRemove = &cobra.Command{
Use: "remove [ QDN ] <target>",
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")
}
}