mirror of https://github.com/docker/docs.git
Addressing small comments and nits
This commit is contained in:
parent
93c7950516
commit
c90a362cfe
|
@ -21,7 +21,7 @@ func add(ctx *cli.Context) {
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
||||||
errorf("must specify a URL or file.")
|
fatalf("must specify a URL or file.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify if argument is a valid URL
|
// Verify if argument is a valid URL
|
||||||
|
@ -29,14 +29,14 @@ func add(ctx *cli.Context) {
|
||||||
if err == nil && url.Scheme != "" {
|
if err == nil && url.Scheme != "" {
|
||||||
err = caStore.AddCertFromURL(args[0])
|
err = caStore.AddCertFromURL(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("error adding certificate to CA Store: %v", err)
|
fatalf("error adding certificate to CA Store: %v", err)
|
||||||
}
|
}
|
||||||
// Verify is argument is a valid file
|
// Verify is argument is a valid file
|
||||||
} else if _, err := os.Stat(args[0]); err == nil {
|
} else if _, err := os.Stat(args[0]); err == nil {
|
||||||
if err := caStore.AddCertFromFile(args[0]); err != nil {
|
if err := caStore.AddCertFromFile(args[0]); err != nil {
|
||||||
errorf("error adding certificate from file: %v", err)
|
fatalf("error adding certificate from file: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errorf("please provide a file location or URL for CA certificate.")
|
fatalf("please provide a file location or URL for CA certificate.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,13 @@ func init() {
|
||||||
// Retrieve current user to get home directory
|
// Retrieve current user to get home directory
|
||||||
usr, err := user.Current()
|
usr, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("cannot get current user: %v", err)
|
fatalf("cannot get current user: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get home directory for current user
|
// Get home directory for current user
|
||||||
homeDir := usr.HomeDir
|
homeDir := usr.HomeDir
|
||||||
if homeDir == "" {
|
if homeDir == "" {
|
||||||
errorf("cannot get current user home directory")
|
fatalf("cannot get current user home directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the configuration details
|
// Setup the configuration details
|
||||||
|
@ -75,13 +75,14 @@ func main() {
|
||||||
app.RunAndExitOnError()
|
app.RunAndExitOnError()
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorf(format string, args ...interface{}) {
|
func fatalf(format string, args ...interface{}) {
|
||||||
fmt.Printf("* fatal: "+format+"\n", args...)
|
fmt.Println("* fatal: ", format)
|
||||||
|
fmt.Println(args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDirectory(dir string) {
|
func createDirectory(dir string) {
|
||||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||||
errorf("cannot create directory: %v", err)
|
fatalf("cannot create directory: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
var (
|
var (
|
||||||
commandRemove = cli.Command{
|
commandRemove = cli.Command{
|
||||||
Name: "remove",
|
Name: "remove",
|
||||||
Usage: "remove trust from a specifice certificate authority",
|
Usage: "remove trust from a specific certificate authority",
|
||||||
Description: "remove trust from a specifice certificate authority.",
|
Description: "remove trust from a specific certificate authority.",
|
||||||
Action: remove,
|
Action: remove,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -20,12 +20,12 @@ func remove(ctx *cli.Context) {
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
||||||
errorf("must specify a SHA256 SubjectKeyID of the certificate")
|
fatalf("must specify a SHA256 SubjectKeyID of the certificate")
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := caStore.GetCertificateBySKID(args[0])
|
cert, err := caStore.GetCertificateBySKID(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("certificate not found")
|
fatalf("certificate not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Removing: ")
|
fmt.Printf("Removing: ")
|
||||||
|
@ -33,6 +33,6 @@ func remove(ctx *cli.Context) {
|
||||||
|
|
||||||
err = caStore.RemoveCert(cert)
|
err = caStore.RemoveCert(cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorf("failed to remove certificate for Key Store")
|
fatalf("failed to remove certificate for Key Store")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func loadCertFromFile(filename string) (*x509.Certificate, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadCertFromPEM returns the first certificate found in a bunch of bytes or error
|
// loadCertFromPEM returns the first certificate found in a bunch of bytes or error
|
||||||
// if nothing is found
|
// if nothing is found. Taken from https://golang.org/src/crypto/x509/cert_pool.go#L85.
|
||||||
func loadCertFromPEM(pemBytes []byte) (*x509.Certificate, error) {
|
func loadCertFromPEM(pemBytes []byte) (*x509.Certificate, error) {
|
||||||
for len(pemBytes) > 0 {
|
for len(pemBytes) > 0 {
|
||||||
var block *pem.Block
|
var block *pem.Block
|
||||||
|
|
Loading…
Reference in New Issue