1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #29313 from vdemeester/move-cli-config

Move package cliconfig to cli/config
This commit is contained in:
Alexander Morozov 2016-12-28 09:05:51 -08:00 committed by GitHub
commit 4f657ff55c
22 changed files with 43 additions and 43 deletions

View file

@ -12,10 +12,10 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/versions" "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" 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/client"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
dopts "github.com/docker/docker/opts" dopts "github.com/docker/docker/opts"
@ -150,7 +150,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
cli.defaultVersion = cli.client.ClientVersion() cli.defaultVersion = cli.client.ClientVersion()
if opts.Common.TrustKey == "" { if opts.Common.TrustKey == "" {
cli.keyFile = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) cli.keyFile = filepath.Join(cliconfig.Dir(), cliflags.DefaultTrustKeyFile)
} else { } else {
cli.keyFile = opts.Common.TrustKey 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 // LoadDefaultConfigFile attempts to load the default config file and returns
// an initialized ConfigFile struct if none is found. // an initialized ConfigFile struct if none is found.
func LoadDefaultConfigFile(err io.Writer) *configfile.ConfigFile { func LoadDefaultConfigFile(err io.Writer) *configfile.ConfigFile {
configFile, e := cliconfig.Load(cliconfig.ConfigDir()) configFile, e := cliconfig.Load(cliconfig.Dir())
if e != nil { if e != nil {
fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e) fmt.Fprintf(err, "WARNING: Error loading config file:%v\n", e)
} }

View file

@ -1,4 +1,4 @@
package cliconfig package config
import ( import (
"fmt" "fmt"
@ -7,7 +7,7 @@ import (
"path/filepath" "path/filepath"
"github.com/docker/docker/api/types" "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" "github.com/docker/docker/pkg/homedir"
) )
@ -28,13 +28,13 @@ func init() {
} }
} }
// ConfigDir returns the directory the configuration file is stored in // Dir returns the directory the configuration file is stored in
func ConfigDir() string { func Dir() string {
return configDir return configDir
} }
// SetConfigDir sets the directory the configuration file is stored in // SetDir sets the directory the configuration file is stored in
func SetConfigDir(dir string) { func SetDir(dir string) {
configDir = dir configDir = dir
} }
@ -72,7 +72,7 @@ func LoadFromReader(configData io.Reader) (*configfile.ConfigFile, error) {
// FIXME: use the internal golang config parser // FIXME: use the internal golang config parser
func Load(configDir string) (*configfile.ConfigFile, error) { func Load(configDir string) (*configfile.ConfigFile, error) {
if configDir == "" { if configDir == "" {
configDir = ConfigDir() configDir = Dir()
} }
configFile := configfile.ConfigFile{ configFile := configfile.ConfigFile{

View file

@ -1,4 +1,4 @@
package cliconfig package config
import ( import (
"io/ioutil" "io/ioutil"
@ -7,7 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cli/config/configfile"
"github.com/docker/docker/pkg/homedir" "github.com/docker/docker/pkg/homedir"
) )
@ -18,7 +18,7 @@ func TestEmptyConfigDir(t *testing.T) {
} }
defer os.RemoveAll(tmpHome) defer os.RemoveAll(tmpHome)
SetConfigDir(tmpHome) SetDir(tmpHome)
config, err := Load("") config, err := Load("")
if err != nil { if err != nil {
@ -471,15 +471,15 @@ func TestConfigDir(t *testing.T) {
} }
defer os.RemoveAll(tmpHome) 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) t.Fatalf("Expected ConfigDir to be different than %s by default, but was the same", tmpHome)
} }
// Update configDir // Update configDir
SetConfigDir(tmpHome) SetDir(tmpHome)
if ConfigDir() != tmpHome { if Dir() != tmpHome {
t.Fatalf("Expected ConfigDir to %s, but was %s", tmpHome, ConfigDir()) t.Fatalf("Expected ConfigDir to %s, but was %s", tmpHome, Dir())
} }
} }

View file

@ -3,7 +3,7 @@ package credentials
import ( import (
"os/exec" "os/exec"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cli/config/configfile"
) )
// DetectDefaultStore sets the default credentials store // DetectDefaultStore sets the default credentials store

View file

@ -2,7 +2,7 @@ package credentials
import ( import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cli/config/configfile"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
) )

View file

@ -5,8 +5,8 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cliconfig" cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cli/config/configfile"
) )
func newConfigFile(auths map[string]types.AuthConfig) *configfile.ConfigFile { func newConfigFile(auths map[string]types.AuthConfig) *configfile.ConfigFile {

View file

@ -4,7 +4,7 @@ import (
"github.com/docker/docker-credential-helpers/client" "github.com/docker/docker-credential-helpers/client"
"github.com/docker/docker-credential-helpers/credentials" "github.com/docker/docker-credential-helpers/credentials"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cli/config/configfile"
) )
const ( const (

View file

@ -6,7 +6,7 @@ import (
"path/filepath" "path/filepath"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/cliconfig" cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -49,7 +49,7 @@ func NewCommonOptions() *CommonOptions {
// InstallFlags adds flags for the common options on the FlagSet // InstallFlags adds flags for the common options on the FlagSet
func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
if dockerCertPath == "" { if dockerCertPath == "" {
dockerCertPath = cliconfig.ConfigDir() dockerCertPath = cliconfig.Dir()
} }
flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode") flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode")

View file

@ -18,7 +18,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/cli/command" "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/docker/registry"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/docker/notary" "github.com/docker/notary"
@ -37,7 +37,7 @@ var (
) )
func trustDirectory() string { func trustDirectory() string {
return filepath.Join(cliconfig.ConfigDir(), "trust") return filepath.Join(cliconfig.Dir(), "trust")
} }
// certificateDirectory returns the directory containing // certificateDirectory returns the directory containing
@ -49,7 +49,7 @@ func certificateDirectory(server string) (string, error) {
return "", err 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. // Server returns the base URL for the trust server.

View file

@ -10,9 +10,9 @@ import (
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/docker/docker/cli/command/commands" "github.com/docker/docker/cli/command/commands"
cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/cli/debug" "github.com/docker/docker/cli/debug"
cliflags "github.com/docker/docker/cli/flags" cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -75,7 +75,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command {
flags = cmd.Flags() flags = cmd.Flags()
flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") 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) opts.Common.InstallFlags(flags)
cmd.SetOutput(dockerCli.Out()) cmd.SetOutput(dockerCli.Out())
@ -126,7 +126,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
cliflags.SetLogLevel(opts.Common.LogLevel) cliflags.SetLogLevel(opts.Common.LogLevel)
if opts.ConfigDir != "" { if opts.ConfigDir != "" {
cliconfig.SetConfigDir(opts.ConfigDir) cliconfig.SetDir(opts.ConfigDir)
} }
if opts.Common.Debug { if opts.Common.Debug {

View file

@ -26,9 +26,9 @@ import (
systemrouter "github.com/docker/docker/api/server/router/system" systemrouter "github.com/docker/docker/api/server/router/system"
"github.com/docker/docker/api/server/router/volume" "github.com/docker/docker/api/server/router/volume"
"github.com/docker/docker/builder/dockerfile" "github.com/docker/docker/builder/dockerfile"
cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/cli/debug" "github.com/docker/docker/cli/debug"
cliflags "github.com/docker/docker/cli/flags" cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/daemon" "github.com/docker/docker/daemon"
"github.com/docker/docker/daemon/cluster" "github.com/docker/docker/daemon/cluster"
"github.com/docker/docker/daemon/logger" "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 // 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) newPath := filepath.Join(getDaemonConfDir(config.Root), cliflags.DefaultTrustKeyFile)
if _, statErr := os.Stat(newPath); os.IsNotExist(statErr) && currentUserIsOwner(oldPath) { if _, statErr := os.Stat(newPath); os.IsNotExist(statErr) && currentUserIsOwner(oldPath) {
defer func() { defer func() {

View file

@ -10,7 +10,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "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/integration-cli/daemon"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/go-check/check" "github.com/go-check/check"
@ -359,7 +359,7 @@ func (s *DockerTrustSuite) TearDownTest(c *check.C) {
} }
// Remove trusted keys and metadata after test // 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) s.ds.TearDownTest(c)
} }

View file

@ -14,7 +14,7 @@ import (
"time" "time"
"github.com/docker/distribution/reference" "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/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "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)) 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 // 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")) c.Assert(err, check.IsNil, check.Commentf("Unable to read local tuf key files"))
// Check that we only have 1 key (targets key) // Check that we only have 1 key (targets key)
c.Assert(contents, checker.HasLen, 1) c.Assert(contents, checker.HasLen, 1)
@ -496,7 +496,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegationOnly(c *check.C)
s.assertTargetNotInRoles(c, repoName, "latest", "targets") s.assertTargetNotInRoles(c, repoName, "latest", "targets")
// Try pull after push // Try pull after push
os.RemoveAll(filepath.Join(cliconfig.ConfigDir(), "trust")) os.RemoveAll(filepath.Join(cliconfig.Dir(), "trust"))
pullCmd := exec.Command(dockerBinary, "pull", targetName) pullCmd := exec.Command(dockerBinary, "pull", targetName)
s.trustedCmd(pullCmd) s.trustedCmd(pullCmd)
@ -539,7 +539,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsAllFirstLevelRolesWeHaveKeysFor(c
s.assertTargetNotInRoles(c, repoName, "latest", "targets") s.assertTargetNotInRoles(c, repoName, "latest", "targets")
// Try pull after push // 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 // pull should fail because none of these are the releases role
pullCmd := exec.Command(dockerBinary, "pull", targetName) pullCmd := exec.Command(dockerBinary, "pull", targetName)
@ -580,7 +580,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsForRolesWithKeysAndValidPaths(c *
s.assertTargetNotInRoles(c, repoName, "latest", "targets") s.assertTargetNotInRoles(c, repoName, "latest", "targets")
// Try pull after push // 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 // pull should fail because none of these are the releases role
pullCmd := exec.Command(dockerBinary, "pull", targetName) pullCmd := exec.Command(dockerBinary, "pull", targetName)

View file

@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/cliconfig" cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/pkg/integration/checker" "github.com/docker/docker/pkg/integration/checker"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/go-check/check" "github.com/go-check/check"
@ -90,7 +90,7 @@ func newTestNotary(c *check.C) (*testNotary, error) {
"skipTLSVerify": true "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) os.RemoveAll(tmp)
return nil, err return nil, err
} }