diff --git a/cli/command/cli.go b/cli/command/cli.go index 6d1dd7472e..c287ebcf77 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -12,10 +12,10 @@ import ( "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" + cliconfig "github.com/docker/docker/cli/config" + "github.com/docker/docker/cli/config/configfile" + "github.com/docker/docker/cli/config/credentials" cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/cliconfig/configfile" - "github.com/docker/docker/cliconfig/credentials" "github.com/docker/docker/client" "github.com/docker/docker/dockerversion" dopts "github.com/docker/docker/opts" @@ -150,7 +150,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error { cli.defaultVersion = cli.client.ClientVersion() if opts.Common.TrustKey == "" { - cli.keyFile = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) + cli.keyFile = filepath.Join(cliconfig.Dir(), cliflags.DefaultTrustKeyFile) } else { cli.keyFile = opts.Common.TrustKey } @@ -179,7 +179,7 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer) *DockerCli { // LoadDefaultConfigFile attempts to load the default config file and returns // an initialized ConfigFile struct if none is found. func LoadDefaultConfigFile(err io.Writer) *configfile.ConfigFile { - configFile, e := cliconfig.Load(cliconfig.ConfigDir()) + configFile, e := cliconfig.Load(cliconfig.Dir()) if e != nil { fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e) } diff --git a/cliconfig/config.go b/cli/config/config.go similarity index 91% rename from cliconfig/config.go rename to cli/config/config.go index d81bf86b7a..ab0fa5451a 100644 --- a/cliconfig/config.go +++ b/cli/config/config.go @@ -1,4 +1,4 @@ -package cliconfig +package config import ( "fmt" @@ -7,7 +7,7 @@ import ( "path/filepath" "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" + "github.com/docker/docker/cli/config/configfile" "github.com/docker/docker/pkg/homedir" ) @@ -28,13 +28,13 @@ func init() { } } -// ConfigDir returns the directory the configuration file is stored in -func ConfigDir() string { +// Dir returns the directory the configuration file is stored in +func Dir() string { return configDir } -// SetConfigDir sets the directory the configuration file is stored in -func SetConfigDir(dir string) { +// SetDir sets the directory the configuration file is stored in +func SetDir(dir string) { configDir = dir } @@ -72,7 +72,7 @@ func LoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) { // FIXME: use the internal golang config parser func Load(configDir string) (*configfile.ConfigFile, error) { if configDir == "" { - configDir = ConfigDir() + configDir = Dir() } configFile := configfile.ConfigFile{ diff --git a/cliconfig/config_test.go b/cli/config/config_test.go similarity index 98% rename from cliconfig/config_test.go rename to cli/config/config_test.go index d8a099ab58..195473bb8a 100644 --- a/cliconfig/config_test.go +++ b/cli/config/config_test.go @@ -1,4 +1,4 @@ -package cliconfig +package config import ( "io/ioutil" @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/docker/docker/cliconfig/configfile" + "github.com/docker/docker/cli/config/configfile" "github.com/docker/docker/pkg/homedir" ) @@ -18,7 +18,7 @@ func TestEmptyConfigDir(t *testing.T) { } defer os.RemoveAll(tmpHome) - SetConfigDir(tmpHome) + SetDir(tmpHome) config, err := Load("") if err != nil { @@ -471,15 +471,15 @@ func TestConfigDir(t *testing.T) { } defer os.RemoveAll(tmpHome) - if ConfigDir() == tmpHome { + if Dir() == tmpHome { t.Fatalf("Expected ConfigDir to be different than %s by default, but was the same", tmpHome) } // Update configDir - SetConfigDir(tmpHome) + SetDir(tmpHome) - if ConfigDir() != tmpHome { - t.Fatalf("Expected ConfigDir to %s, but was %s", tmpHome, ConfigDir()) + if Dir() != tmpHome { + t.Fatalf("Expected ConfigDir to %s, but was %s", tmpHome, Dir()) } } diff --git a/cliconfig/configfile/file.go b/cli/config/configfile/file.go similarity index 100% rename from cliconfig/configfile/file.go rename to cli/config/configfile/file.go diff --git a/cliconfig/configfile/file_test.go b/cli/config/configfile/file_test.go similarity index 100% rename from cliconfig/configfile/file_test.go rename to cli/config/configfile/file_test.go diff --git a/cliconfig/credentials/credentials.go b/cli/config/credentials/credentials.go similarity index 100% rename from cliconfig/credentials/credentials.go rename to cli/config/credentials/credentials.go diff --git a/cliconfig/credentials/default_store.go b/cli/config/credentials/default_store.go similarity index 90% rename from cliconfig/credentials/default_store.go rename to cli/config/credentials/default_store.go index b4733709b1..263a4ea879 100644 --- a/cliconfig/credentials/default_store.go +++ b/cli/config/credentials/default_store.go @@ -3,7 +3,7 @@ package credentials import ( "os/exec" - "github.com/docker/docker/cliconfig/configfile" + "github.com/docker/docker/cli/config/configfile" ) // DetectDefaultStore sets the default credentials store diff --git a/cliconfig/credentials/default_store_darwin.go b/cli/config/credentials/default_store_darwin.go similarity index 100% rename from cliconfig/credentials/default_store_darwin.go rename to cli/config/credentials/default_store_darwin.go diff --git a/cliconfig/credentials/default_store_linux.go b/cli/config/credentials/default_store_linux.go similarity index 100% rename from cliconfig/credentials/default_store_linux.go rename to cli/config/credentials/default_store_linux.go diff --git a/cliconfig/credentials/default_store_unsupported.go b/cli/config/credentials/default_store_unsupported.go similarity index 100% rename from cliconfig/credentials/default_store_unsupported.go rename to cli/config/credentials/default_store_unsupported.go diff --git a/cliconfig/credentials/default_store_windows.go b/cli/config/credentials/default_store_windows.go similarity index 100% rename from cliconfig/credentials/default_store_windows.go rename to cli/config/credentials/default_store_windows.go diff --git a/cliconfig/credentials/file_store.go b/cli/config/credentials/file_store.go similarity index 96% rename from cliconfig/credentials/file_store.go rename to cli/config/credentials/file_store.go index ca73a384d4..3cab4a448b 100644 --- a/cliconfig/credentials/file_store.go +++ b/cli/config/credentials/file_store.go @@ -2,7 +2,7 @@ package credentials import ( "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" + "github.com/docker/docker/cli/config/configfile" "github.com/docker/docker/registry" ) diff --git a/cliconfig/credentials/file_store_test.go b/cli/config/credentials/file_store_test.go similarity index 97% rename from cliconfig/credentials/file_store_test.go rename to cli/config/credentials/file_store_test.go index efed4e9040..b6bfaa0607 100644 --- a/cliconfig/credentials/file_store_test.go +++ b/cli/config/credentials/file_store_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig" - "github.com/docker/docker/cliconfig/configfile" + cliconfig "github.com/docker/docker/cli/config" + "github.com/docker/docker/cli/config/configfile" ) func newConfigFile(auths map[string]types.AuthConfig) *configfile.ConfigFile { diff --git a/cliconfig/credentials/native_store.go b/cli/config/credentials/native_store.go similarity index 98% rename from cliconfig/credentials/native_store.go rename to cli/config/credentials/native_store.go index dec2dbcb82..9e0ab7f0f8 100644 --- a/cliconfig/credentials/native_store.go +++ b/cli/config/credentials/native_store.go @@ -4,7 +4,7 @@ import ( "github.com/docker/docker-credential-helpers/client" "github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker/api/types" - "github.com/docker/docker/cliconfig/configfile" + "github.com/docker/docker/cli/config/configfile" ) const ( diff --git a/cliconfig/credentials/native_store_test.go b/cli/config/credentials/native_store_test.go similarity index 100% rename from cliconfig/credentials/native_store_test.go rename to cli/config/credentials/native_store_test.go diff --git a/cli/flags/common.go b/cli/flags/common.go index 490c2922fc..9d3245c99c 100644 --- a/cli/flags/common.go +++ b/cli/flags/common.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/Sirupsen/logrus" - "github.com/docker/docker/cliconfig" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/opts" "github.com/docker/go-connections/tlsconfig" "github.com/spf13/pflag" @@ -49,7 +49,7 @@ func NewCommonOptions() *CommonOptions { // InstallFlags adds flags for the common options on the FlagSet func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { if dockerCertPath == "" { - dockerCertPath = cliconfig.ConfigDir() + dockerCertPath = cliconfig.Dir() } flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode") diff --git a/cli/trust/trust.go b/cli/trust/trust.go index 51914f74b0..44f8197ba2 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -18,7 +18,7 @@ import ( "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/cli/command" - "github.com/docker/docker/cliconfig" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/registry" "github.com/docker/go-connections/tlsconfig" "github.com/docker/notary" @@ -37,7 +37,7 @@ var ( ) func trustDirectory() string { - return filepath.Join(cliconfig.ConfigDir(), "trust") + return filepath.Join(cliconfig.Dir(), "trust") } // certificateDirectory returns the directory containing @@ -49,7 +49,7 @@ func certificateDirectory(server string) (string, error) { return "", err } - return filepath.Join(cliconfig.ConfigDir(), "tls", u.Host), nil + return filepath.Join(cliconfig.Dir(), "tls", u.Host), nil } // Server returns the base URL for the trust server. diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index f4033738b7..685f565c8d 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -10,9 +10,9 @@ import ( "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/commands" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/cli/debug" cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/term" "github.com/spf13/cobra" @@ -75,7 +75,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { flags = cmd.Flags() flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") - flags.StringVar(&opts.ConfigDir, "config", cliconfig.ConfigDir(), "Location of client config files") + flags.StringVar(&opts.ConfigDir, "config", cliconfig.Dir(), "Location of client config files") opts.Common.InstallFlags(flags) cmd.SetOutput(dockerCli.Out()) @@ -126,7 +126,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) { cliflags.SetLogLevel(opts.Common.LogLevel) if opts.ConfigDir != "" { - cliconfig.SetConfigDir(opts.ConfigDir) + cliconfig.SetDir(opts.ConfigDir) } if opts.Common.Debug { diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index a3f61c2cb8..7b39066f00 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -26,9 +26,9 @@ import ( systemrouter "github.com/docker/docker/api/server/router/system" "github.com/docker/docker/api/server/router/volume" "github.com/docker/docker/builder/dockerfile" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/cli/debug" cliflags "github.com/docker/docker/cli/flags" - "github.com/docker/docker/cliconfig" "github.com/docker/docker/daemon" "github.com/docker/docker/daemon/cluster" "github.com/docker/docker/daemon/logger" @@ -75,7 +75,7 @@ func migrateKey(config *daemon.Config) (err error) { } // Migrate trust key if exists at ~/.docker/key.json and owned by current user - oldPath := filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) + oldPath := filepath.Join(cliconfig.Dir(), cliflags.DefaultTrustKeyFile) newPath := filepath.Join(getDaemonConfDir(config.Root), cliflags.DefaultTrustKeyFile) if _, statErr := os.Stat(newPath); os.IsNotExist(statErr) && currentUserIsOwner(oldPath) { defer func() { diff --git a/integration-cli/check_test.go b/integration-cli/check_test.go index f09d980faf..37f4b1923d 100644 --- a/integration-cli/check_test.go +++ b/integration-cli/check_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/cliconfig" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/pkg/reexec" "github.com/go-check/check" @@ -359,7 +359,7 @@ func (s *DockerTrustSuite) TearDownTest(c *check.C) { } // Remove trusted keys and metadata after test - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) + os.RemoveAll(filepath.Join(cliconfig.Dir(), "trust")) s.ds.TearDownTest(c) } diff --git a/integration-cli/docker_cli_push_test.go b/integration-cli/docker_cli_push_test.go index f750c12674..69eca31bb2 100644 --- a/integration-cli/docker_cli_push_test.go +++ b/integration-cli/docker_cli_push_test.go @@ -14,7 +14,7 @@ import ( "time" "github.com/docker/distribution/reference" - "github.com/docker/docker/cliconfig" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -300,7 +300,7 @@ func (s *DockerTrustSuite) TestTrustedPush(c *check.C) { c.Assert(string(out), checker.Contains, "Status: Image is up to date", check.Commentf(out)) // Assert that we rotated the snapshot key to the server by checking our local keystore - contents, err := ioutil.ReadDir(filepath.Join(cliconfig.ConfigDir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest")) + contents, err := ioutil.ReadDir(filepath.Join(cliconfig.Dir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest")) c.Assert(err, check.IsNil, check.Commentf("Unable to read local tuf key files")) // Check that we only have 1 key (targets key) c.Assert(contents, checker.HasLen, 1) @@ -496,7 +496,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegationOnly(c *check.C) s.assertTargetNotInRoles(c, repoName, "latest", "targets") // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) + os.RemoveAll(filepath.Join(cliconfig.Dir(), "trust")) pullCmd := exec.Command(dockerBinary, "pull", targetName) s.trustedCmd(pullCmd) @@ -539,7 +539,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsAllFirstLevelRolesWeHaveKeysFor(c s.assertTargetNotInRoles(c, repoName, "latest", "targets") // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) + os.RemoveAll(filepath.Join(cliconfig.Dir(), "trust")) // pull should fail because none of these are the releases role pullCmd := exec.Command(dockerBinary, "pull", targetName) @@ -580,7 +580,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsForRolesWithKeysAndValidPaths(c * s.assertTargetNotInRoles(c, repoName, "latest", "targets") // Try pull after push - os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) + os.RemoveAll(filepath.Join(cliconfig.Dir(), "trust")) // pull should fail because none of these are the releases role pullCmd := exec.Command(dockerBinary, "pull", targetName) diff --git a/integration-cli/trust_server.go b/integration-cli/trust_server.go index 18876311a1..648efa6a01 100644 --- a/integration-cli/trust_server.go +++ b/integration-cli/trust_server.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/docker/docker/cliconfig" + cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/pkg/integration/checker" "github.com/docker/go-connections/tlsconfig" "github.com/go-check/check" @@ -90,7 +90,7 @@ func newTestNotary(c *check.C) (*testNotary, error) { "skipTLSVerify": true } }` - if _, err = fmt.Fprintf(clientConfig, template, filepath.Join(cliconfig.ConfigDir(), "trust"), notaryURL); err != nil { + if _, err = fmt.Fprintf(clientConfig, template, filepath.Join(cliconfig.Dir(), "trust"), notaryURL); err != nil { os.RemoveAll(tmp) return nil, err }