Remove duplication

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-12-30 17:19:11 +01:00
parent 00eee7db1d
commit 263f8c5cdd
3 changed files with 10 additions and 11 deletions

View File

@ -97,7 +97,7 @@ func runAction(actionName string, c CommandLine, api libmachine.API) error {
func fatalOnError(command func(commandLine CommandLine, api libmachine.API) error) func(context *cli.Context) { func fatalOnError(command func(commandLine CommandLine, api libmachine.API) error) func(context *cli.Context) {
return func(context *cli.Context) { return func(context *cli.Context) {
api := libmachine.NewClient(mcndirs.GetBaseDir()) api := libmachine.NewClient(mcndirs.GetBaseDir(), mcndirs.GetMachineCertDir())
defer api.Close() defer api.Close()
if context.GlobalBool("native-ssh") { if context.GlobalBool("native-ssh") {

View File

@ -13,7 +13,7 @@ import (
func main() { func main() {
log.SetDebug(true) log.SetDebug(true)
client := libmachine.NewClient("/tmp/automatic") client := libmachine.NewClient("/tmp/automatic", "/tmp/automatic/certs")
hostName := "myfunhost" hostName := "myfunhost"

View File

@ -34,6 +34,7 @@ type API interface {
} }
type Client struct { type Client struct {
certsDir string
IsDebug bool IsDebug bool
SSHClientType ssh.ClientType SSHClientType ssh.ClientType
GithubAPIToken string GithubAPIToken string
@ -41,9 +42,9 @@ type Client struct {
clientDriverFactory rpcdriver.RPCClientDriverFactory clientDriverFactory rpcdriver.RPCClientDriverFactory
} }
func NewClient(storePath string) *Client { func NewClient(storePath, certsDir string) *Client {
certsDir := filepath.Join(storePath, ".docker", "machine", "certs")
return &Client{ return &Client{
certsDir: certsDir,
IsDebug: false, IsDebug: false,
SSHClientType: ssh.External, SSHClientType: ssh.External,
Filestore: persist.NewFilestore(storePath, certsDir, certsDir), Filestore: persist.NewFilestore(storePath, certsDir, certsDir),
@ -57,8 +58,6 @@ func (api *Client) NewHost(driverName string, rawDriver []byte) (*host.Host, err
return nil, err return nil, err
} }
certDir := filepath.Join(api.Path, "certs")
return &host.Host{ return &host.Host{
ConfigVersion: version.ConfigVersion, ConfigVersion: version.ConfigVersion,
Name: driver.GetMachineName(), Name: driver.GetMachineName(),
@ -66,11 +65,11 @@ func (api *Client) NewHost(driverName string, rawDriver []byte) (*host.Host, err
DriverName: driver.DriverName(), DriverName: driver.DriverName(),
HostOptions: &host.Options{ HostOptions: &host.Options{
AuthOptions: &auth.Options{ AuthOptions: &auth.Options{
CertDir: certDir, CertDir: api.certsDir,
CaCertPath: filepath.Join(certDir, "ca.pem"), CaCertPath: filepath.Join(api.certsDir, "ca.pem"),
CaPrivateKeyPath: filepath.Join(certDir, "ca-key.pem"), CaPrivateKeyPath: filepath.Join(api.certsDir, "ca-key.pem"),
ClientCertPath: filepath.Join(certDir, "cert.pem"), ClientCertPath: filepath.Join(api.certsDir, "cert.pem"),
ClientKeyPath: filepath.Join(certDir, "key.pem"), ClientKeyPath: filepath.Join(api.certsDir, "key.pem"),
ServerCertPath: filepath.Join(api.GetMachinesDir(), "server.pem"), ServerCertPath: filepath.Join(api.GetMachinesDir(), "server.pem"),
ServerKeyPath: filepath.Join(api.GetMachinesDir(), "server-key.pem"), ServerKeyPath: filepath.Join(api.GetMachinesDir(), "server-key.pem"),
}, },