mirror of
https://github.com/docker/docs.git
synced 2026-11-05 00:14:17 +03:00
Remove duplication on certificates code
Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
@@ -4,13 +4,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/machine/commands/mcndirs"
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/cert"
|
||||
"github.com/docker/machine/libmachine/crashreport"
|
||||
"github.com/docker/machine/libmachine/drivers/rpc"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
@@ -391,36 +389,3 @@ func consolidateErrs(errs []error) error {
|
||||
|
||||
return errors.New(strings.TrimSpace(finalErr))
|
||||
}
|
||||
|
||||
// Returns the cert paths. codegangsta/cli will not set the cert paths if the
|
||||
// storage-path is set to something different so we cannot use the paths in the
|
||||
// global options. le sigh.
|
||||
func getCertPathInfoFromCommandLine(c CommandLine) cert.PathInfo {
|
||||
caCertPath := c.GlobalString("tls-ca-cert")
|
||||
caKeyPath := c.GlobalString("tls-ca-key")
|
||||
clientCertPath := c.GlobalString("tls-client-cert")
|
||||
clientKeyPath := c.GlobalString("tls-client-key")
|
||||
|
||||
if caCertPath == "" {
|
||||
caCertPath = filepath.Join(mcndirs.GetMachineCertDir(), "ca.pem")
|
||||
}
|
||||
|
||||
if caKeyPath == "" {
|
||||
caKeyPath = filepath.Join(mcndirs.GetMachineCertDir(), "ca-key.pem")
|
||||
}
|
||||
|
||||
if clientCertPath == "" {
|
||||
clientCertPath = filepath.Join(mcndirs.GetMachineCertDir(), "cert.pem")
|
||||
}
|
||||
|
||||
if clientKeyPath == "" {
|
||||
clientKeyPath = filepath.Join(mcndirs.GetMachineCertDir(), "key.pem")
|
||||
}
|
||||
|
||||
return cert.PathInfo{
|
||||
CaCertPath: caCertPath,
|
||||
CaPrivateKeyPath: caKeyPath,
|
||||
ClientCertPath: clientCertPath,
|
||||
ClientKeyPath: clientKeyPath,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,15 +162,13 @@ func cmdCreateInner(c CommandLine, api libmachine.API) error {
|
||||
return fmt.Errorf("Error getting new host: %s", err)
|
||||
}
|
||||
|
||||
certInfo := getCertPathInfoFromCommandLine(c)
|
||||
|
||||
h.HostOptions = &host.Options{
|
||||
AuthOptions: &auth.Options{
|
||||
CertDir: mcndirs.GetMachineCertDir(),
|
||||
CaCertPath: certInfo.CaCertPath,
|
||||
CaPrivateKeyPath: certInfo.CaPrivateKeyPath,
|
||||
ClientCertPath: certInfo.ClientCertPath,
|
||||
ClientKeyPath: certInfo.ClientKeyPath,
|
||||
CaCertPath: tlsPath(c, "tls-ca-cert", "ca.pem"),
|
||||
CaPrivateKeyPath: tlsPath(c, "tls-ca-key", "ca-key.pem"),
|
||||
ClientCertPath: tlsPath(c, "tls-client-cert", "cert.pem"),
|
||||
ClientKeyPath: tlsPath(c, "tls-client-key", "key.pem"),
|
||||
ServerCertPath: filepath.Join(mcndirs.GetMachineDir(), name, "server.pem"),
|
||||
ServerKeyPath: filepath.Join(mcndirs.GetMachineDir(), name, "server-key.pem"),
|
||||
StorePath: filepath.Join(mcndirs.GetMachineDir(), name),
|
||||
@@ -433,3 +431,12 @@ func validateSwarmDiscovery(discovery string) error {
|
||||
|
||||
return fmt.Errorf("Swarm Discovery URL was in the wrong format: %s", discovery)
|
||||
}
|
||||
|
||||
func tlsPath(c CommandLine, flag string, defaultName string) string {
|
||||
path := c.GlobalString(flag)
|
||||
if path != "" {
|
||||
return path
|
||||
}
|
||||
|
||||
return filepath.Join(mcndirs.GetMachineCertDir(), defaultName)
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package cert
|
||||
|
||||
type PathInfo struct {
|
||||
CaCertPath string
|
||||
CaPrivateKeyPath string
|
||||
ClientCertPath string
|
||||
ClientKeyPath string
|
||||
ServerCertPath string
|
||||
ServerKeyPath string
|
||||
}
|
||||
Reference in New Issue
Block a user