mirror of https://github.com/docker/docs.git
Refactor cmdline key naming and added TUF skeletons
This commit is contained in:
parent
931c5e2a9b
commit
836521e166
|
@ -2,9 +2,9 @@ package main
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
var keysCmd = &cobra.Command{
|
var cmdKeys = &cobra.Command{
|
||||||
Use: "keys",
|
Use: "keys",
|
||||||
Short: "Operates on keys",
|
Short: "Operates on keys.",
|
||||||
Long: "operations on signature keys and trusted certificate authorities",
|
Long: "operations on signature keys and trusted certificate authorities.",
|
||||||
Run: nil,
|
Run: nil,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,17 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdList = &cobra.Command{
|
var cmdKeysList = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List the currently trusted certificate authorities.",
|
Short: "List the currently trusted certificate authorities.",
|
||||||
Long: "lists 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
|
// Load all the certificates
|
||||||
trustedCAs := caStore.GetCertificates()
|
trustedCAs := caStore.GetCertificates()
|
||||||
|
|
||||||
fmt.Println("CAs Loaded:")
|
|
||||||
for _, c := range trustedCAs {
|
for _, c := range trustedCAs {
|
||||||
print_cert(c)
|
print_cert(c)
|
||||||
}
|
}
|
|
@ -7,16 +7,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
subjectKeyID string
|
subjectKeyID string
|
||||||
cmdRemove = &cobra.Command{
|
cmdKeysRemove = &cobra.Command{
|
||||||
Use: "remove [ Subject Key ID ]",
|
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.",
|
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 {
|
if len(args) < 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
fatalf("must specify a SHA256 SubjectKeyID of the certificate")
|
fatalf("must specify a SHA256 SubjectKeyID of the certificate")
|
|
@ -9,14 +9,14 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdtrust = &cobra.Command{
|
var cmdKeysTrust = &cobra.Command{
|
||||||
Use: "trust [ QDN ] [ certificate ]",
|
Use: "trust [ QDN ] [ certificate ]",
|
||||||
Short: "Trusts a new certificate for a specific QDN.",
|
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.",
|
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 {
|
if len(args) < 2 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
fatalf("not enough arguments provided")
|
fatalf("not enough arguments provided")
|
||||||
|
@ -40,8 +40,8 @@ func trust(cmd *cobra.Command, args []string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatalf("error adding certificate from file: %v", err)
|
fatalf("error adding certificate from file: %v", err)
|
||||||
}
|
}
|
||||||
|
fmt.Printf("Adding: ")
|
||||||
fmt.Println(string(cert.RawSubject))
|
print_cert(cert)
|
||||||
} else if _, err := os.Stat(certLocationStr); err == nil {
|
} else if _, err := os.Stat(certLocationStr); err == nil {
|
||||||
if err := caStore.AddCertFromFile(certLocationStr); err != nil {
|
if err := caStore.AddCertFromFile(certLocationStr); err != nil {
|
||||||
fatalf("error adding certificate from file: %v", err)
|
fatalf("error adding certificate from file: %v", err)
|
|
@ -74,8 +74,9 @@ func main() {
|
||||||
Long: "notary is the main trust-related command for Docker.",
|
Long: "notary is the main trust-related command for Docker.",
|
||||||
}
|
}
|
||||||
|
|
||||||
NotaryCmd.AddCommand(keysCmd, tufCmd)
|
NotaryCmd.AddCommand(cmdKeys, cmdTuf)
|
||||||
keysCmd.AddCommand(cmdtrust, cmdList, cmdRemove)
|
cmdKeys.AddCommand(cmdKeysTrust, cmdKeysList, cmdKeysRemove)
|
||||||
|
cmdTuf.AddCommand(cmdTufInit, cmdTufAdd, cmdTufRemove, cmdTufPush, cmdTufLookup, cmdTufList)
|
||||||
|
|
||||||
NotaryCmd.Execute()
|
NotaryCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ package main
|
||||||
|
|
||||||
import "github.com/spf13/cobra"
|
import "github.com/spf13/cobra"
|
||||||
|
|
||||||
var tufCmd = &cobra.Command{
|
var cmdTuf = &cobra.Command{
|
||||||
Use: "tuf",
|
Use: "tuf",
|
||||||
Short: "Manages trust of data for notary",
|
Short: "Manages trust of data for notary.",
|
||||||
Long: "manages signed repository metadata",
|
Long: "manages signed repository metadata.",
|
||||||
Run: nil,
|
Run: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var remoteTrustServer string
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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)
|
||||||
|
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue