Skip to content

Commit 2f04b24

Browse files
tonistiigiTibor Vass
authored andcommitted
Remove docker api dependency from cli/config
Signed-off-by: Tonis Tiigi <[email protected]> Signed-off-by: Tibor Vass <[email protected]>
1 parent 080f30a commit 2f04b24

File tree

16 files changed

+87
-34
lines changed

16 files changed

+87
-34
lines changed

cli/command/container/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewRunCommand(dockerCli command.Cli) *cobra.Command {
6868
}
6969

7070
func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copts *containerOptions) error {
71-
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), copts.env.GetAll())
71+
proxyConfig := dockerCli.ConfigFile().ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(copts.env.GetAll()))
7272
newEnv := []string{}
7373
for k, v := range proxyConfig {
7474
if v == nil {

cli/command/image/build.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
383383
}
384384

385385
configFile := dockerCli.ConfigFile()
386-
authConfigs, _ := configFile.GetAllCredentials()
386+
creds, _ := configFile.GetAllCredentials()
387+
authConfigs := make(map[string]types.AuthConfig, len(creds))
388+
for k, auth := range creds {
389+
authConfigs[k] = types.AuthConfig(auth)
390+
}
387391
buildOptions := imageBuildOptions(dockerCli, options)
388392
buildOptions.Version = types.BuilderV1
389393
buildOptions.Dockerfile = relDockerfile
@@ -619,7 +623,7 @@ func imageBuildOptions(dockerCli command.Cli, options buildOptions) types.ImageB
619623
CgroupParent: options.cgroupParent,
620624
ShmSize: options.shmSize.Value(),
621625
Ulimits: options.ulimits.GetList(),
622-
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), options.buildArgs.GetAll()),
626+
BuildArgs: configFile.ParseProxyConfig(dockerCli.Client().DaemonHost(), opts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll())),
623627
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
624628
CacheFrom: options.cacheFrom,
625629
SecurityOpt: options.securityOpt,

cli/command/registry.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"runtime"
1212
"strings"
1313

14+
configtypes "github.com/docker/cli/cli/config/types"
1415
"github.com/docker/cli/cli/debug"
1516
"github.com/docker/distribution/reference"
1617
"github.com/docker/docker/api/types"
@@ -76,7 +77,7 @@ func ResolveAuthConfig(ctx context.Context, cli Cli, index *registrytypes.IndexI
7677
}
7778

7879
a, _ := cli.ConfigFile().GetAuthConfig(configKey)
79-
return a
80+
return types.AuthConfig(a)
8081
}
8182

8283
// GetDefaultAuthConfig gets the default auth config given a serverAddress
@@ -85,16 +86,17 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is
8586
if !isDefaultRegistry {
8687
serverAddress = registry.ConvertToHostname(serverAddress)
8788
}
88-
var authconfig types.AuthConfig
89+
var authconfig configtypes.AuthConfig
8990
var err error
9091
if checkCredStore {
9192
authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress)
9293
} else {
93-
authconfig = types.AuthConfig{}
94+
authconfig = configtypes.AuthConfig{}
9495
}
9596
authconfig.ServerAddress = serverAddress
9697
authconfig.IdentityToken = ""
97-
return &authconfig, err
98+
res := types.AuthConfig(authconfig)
99+
return &res, err
98100
}
99101

100102
// ConfigureAuth handles prompting of user's username and password if needed

cli/command/registry/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/docker/cli/cli"
1010
"github.com/docker/cli/cli/command"
11+
configtypes "github.com/docker/cli/cli/config/types"
1112
"github.com/docker/docker/api/types"
1213
registrytypes "github.com/docker/docker/api/types/registry"
1314
"github.com/docker/docker/client"
@@ -149,7 +150,7 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint: gocycl
149150
}
150151
}
151152

152-
if err := creds.Store(*authConfig); err != nil {
153+
if err := creds.Store(configtypes.AuthConfig(*authConfig)); err != nil {
153154
return errors.Errorf("Error saving credentials: %v", err)
154155
}
155156

cli/command/registry/login_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"testing"
88

9+
configtypes "github.com/docker/cli/cli/config/types"
910
"github.com/docker/cli/internal/test"
1011
"github.com/docker/docker/api/types"
1112
registrytypes "github.com/docker/docker/api/types/registry"
@@ -79,21 +80,21 @@ func TestRunLogin(t *testing.T) {
7980
const validPassword = "p1"
8081
const validPassword2 = "p2"
8182

82-
validAuthConfig := types.AuthConfig{
83+
validAuthConfig := configtypes.AuthConfig{
8384
ServerAddress: storedServerAddress,
8485
Username: validUsername,
8586
Password: validPassword,
8687
}
87-
expiredAuthConfig := types.AuthConfig{
88+
expiredAuthConfig := configtypes.AuthConfig{
8889
ServerAddress: storedServerAddress,
8990
Username: validUsername,
9091
Password: expiredPassword,
9192
}
9293
testCases := []struct {
9394
inputLoginOption loginOptions
94-
inputStoredCred *types.AuthConfig
95+
inputStoredCred *configtypes.AuthConfig
9596
expectedErr string
96-
expectedSavedCred types.AuthConfig
97+
expectedSavedCred configtypes.AuthConfig
9798
}{
9899
{
99100
inputLoginOption: loginOptions{
@@ -118,7 +119,7 @@ func TestRunLogin(t *testing.T) {
118119
},
119120
inputStoredCred: &validAuthConfig,
120121
expectedErr: "",
121-
expectedSavedCred: types.AuthConfig{
122+
expectedSavedCred: configtypes.AuthConfig{
122123
ServerAddress: storedServerAddress,
123124
Username: validUsername,
124125
Password: validPassword2,

cli/command/registry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// Prevents a circular import with "github.com/docker/cli/internal/test"
1414

1515
. "github.com/docker/cli/cli/command"
16+
configtypes "github.com/docker/cli/cli/config/types"
1617
"github.com/docker/cli/cli/debug"
1718
"github.com/docker/cli/internal/test"
1819
"github.com/docker/docker/api/types"
@@ -134,7 +135,7 @@ func TestGetDefaultAuthConfig(t *testing.T) {
134135
errBuf := new(bytes.Buffer)
135136
cli.SetErr(errBuf)
136137
for _, authconfig := range testAuthConfigs {
137-
cli.ConfigFile().GetCredentialsStore(authconfig.ServerAddress).Store(authconfig)
138+
cli.ConfigFile().GetCredentialsStore(authconfig.ServerAddress).Store(configtypes.AuthConfig(authconfig))
138139
}
139140
for _, tc := range testCases {
140141
serverAddress := tc.inputServerAddress

cli/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"github.com/docker/cli/cli/config/configfile"
1010
"github.com/docker/cli/cli/config/credentials"
11-
"github.com/docker/docker/api/types"
11+
"github.com/docker/cli/cli/config/types"
1212
"github.com/docker/docker/pkg/homedir"
1313
"github.com/pkg/errors"
1414
)

cli/config/configfile/file.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/docker/cli/cli/config/credentials"
14-
"github.com/docker/cli/opts"
15-
"github.com/docker/docker/api/types"
14+
"github.com/docker/cli/cli/config/types"
1615
"github.com/pkg/errors"
1716
)
1817

@@ -195,7 +194,7 @@ func (configFile *ConfigFile) Save() error {
195194

196195
// ParseProxyConfig computes proxy configuration by retrieving the config for the provided host and
197196
// then checking this against any environment variables provided to the container
198-
func (configFile *ConfigFile) ParseProxyConfig(host string, runOpts []string) map[string]*string {
197+
func (configFile *ConfigFile) ParseProxyConfig(host string, runOpts map[string]*string) map[string]*string {
199198
var cfgKey string
200199

201200
if _, ok := configFile.Proxies[host]; !ok {
@@ -211,7 +210,10 @@ func (configFile *ConfigFile) ParseProxyConfig(host string, runOpts []string) ma
211210
"NO_PROXY": &config.NoProxy,
212211
"FTP_PROXY": &config.FTPProxy,
213212
}
214-
m := opts.ConvertKVStringsToMapWithNil(runOpts)
213+
m := runOpts
214+
if m == nil {
215+
m = make(map[string]*string)
216+
}
215217
for k := range permitted {
216218
if *permitted[k] == "" {
217219
continue

cli/config/configfile/file_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package configfile
22

33
import (
4-
"fmt"
54
"io/ioutil"
65
"os"
76
"testing"
87

98
"github.com/docker/cli/cli/config/credentials"
10-
"github.com/docker/docker/api/types"
9+
"github.com/docker/cli/cli/config/types"
1110
"gotest.tools/assert"
1211
is "gotest.tools/assert/cmp"
1312
)
@@ -41,7 +40,7 @@ func TestProxyConfig(t *testing.T) {
4140
},
4241
}
4342

44-
proxyConfig := cfg.ParseProxyConfig("/var/run/docker.sock", []string{})
43+
proxyConfig := cfg.ParseProxyConfig("/var/run/docker.sock", nil)
4544
expected := map[string]*string{
4645
"HTTP_PROXY": &httpProxy,
4746
"http_proxy": &httpProxy,
@@ -75,9 +74,14 @@ func TestProxyConfigOverride(t *testing.T) {
7574
},
7675
}
7776

78-
ropts := []string{
79-
fmt.Sprintf("HTTP_PROXY=%s", overrideHTTPProxy),
80-
"NO_PROXY=",
77+
clone := func(s string) *string {
78+
s2 := s
79+
return &s2
80+
}
81+
82+
ropts := map[string]*string{
83+
"HTTP_PROXY": clone(overrideHTTPProxy),
84+
"NO_PROXY": clone(overrideNoProxy),
8185
}
8286
proxyConfig := cfg.ParseProxyConfig("/var/run/docker.sock", ropts)
8387
expected := map[string]*string{
@@ -124,7 +128,7 @@ func TestProxyConfigPerHost(t *testing.T) {
124128
},
125129
}
126130

127-
proxyConfig := cfg.ParseProxyConfig("tcp://example.docker.com:2376", []string{})
131+
proxyConfig := cfg.ParseProxyConfig("tcp://example.docker.com:2376", nil)
128132
expected := map[string]*string{
129133
"HTTP_PROXY": &extHTTPProxy,
130134
"http_proxy": &extHTTPProxy,

cli/config/credentials/credentials.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package credentials
22

33
import (
4-
"github.com/docker/docker/api/types"
4+
"github.com/docker/cli/cli/config/types"
55
)
66

77
// Store is the interface that any credentials store must implement.

0 commit comments

Comments
 (0)