Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/command/container/auth_config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/types"
"github.com/moby/moby/api/types/registry"
)

// readCredentials resolves auth-config from the current environment to be
Expand All @@ -22,7 +22,7 @@ import (
// formatted, or when failing to read from the credentials store.
//
// A nil value is returned if neither option contained any credentials.
func readCredentials(dockerCLI config.Provider) (creds map[string]types.AuthConfig, _ error) {
func readCredentials(dockerCLI config.Provider) (creds map[string]registry.AuthConfig, _ error) {
if v, ok := os.LookupEnv("DOCKER_AUTH_CONFIG"); ok && v != "" {
// The results are expected to have been unmarshaled the same as
// when reading from a config-file, which includes decoding the
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/types"
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/internal/jsonstream"
"github.com/docker/cli/opts"
"github.com/moby/moby/api/types/mount"
"github.com/moby/moby/api/types/registry"
"github.com/moby/moby/client"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -239,7 +239,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
}

const dockerConfigPathInContainer = "/run/secrets/docker/config.json"
var apiSocketCreds map[string]types.AuthConfig
var apiSocketCreds map[string]registry.AuthConfig

if options.useAPISocket {
// We'll create two new mounts to handle this flag:
Expand Down
31 changes: 15 additions & 16 deletions cli/command/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import (
"github.com/distribution/reference"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/credentials"
configtypes "github.com/docker/cli/cli/config/types"
"github.com/docker/cli/cli/hints"
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/internal/prompt"
"github.com/docker/cli/internal/tui"
"github.com/moby/moby/api/pkg/authconfig"
registrytypes "github.com/moby/moby/api/types/registry"
"github.com/moby/moby/api/types/registry"
"github.com/morikuni/aec"
)

Expand All @@ -40,14 +39,14 @@ const authConfigKey = "https://index.docker.io/v1/"
// found.
//
// Deprecated: this function is no longer used, and will be removed in the next release.
func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registry.IndexInfo) registry.AuthConfig {
configKey := index.Name
if index.Official {
configKey = authConfigKey
}

a, _ := cfg.GetAuthConfig(configKey)
return registrytypes.AuthConfig{
return registry.AuthConfig{
Username: a.Username,
Password: a.Password,
ServerAddress: a.ServerAddress,
Expand All @@ -61,22 +60,22 @@ func ResolveAuthConfig(cfg *configfile.ConfigFile, index *registrytypes.IndexInf

// GetDefaultAuthConfig gets the default auth config given a serverAddress
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error) {
func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registry.AuthConfig, error) {
if !isDefaultRegistry {
serverAddress = credentials.ConvertToHostname(serverAddress)
}
authCfg := configtypes.AuthConfig{}
authCfg := registry.AuthConfig{}
var err error
if checkCredStore {
authCfg, err = cfg.GetAuthConfig(serverAddress)
if err != nil {
return registrytypes.AuthConfig{
return registry.AuthConfig{
ServerAddress: serverAddress,
}, err
}
}

return registrytypes.AuthConfig{
return registry.AuthConfig{
Username: authCfg.Username,
Password: authCfg.Password,
ServerAddress: serverAddress,
Expand All @@ -97,7 +96,7 @@ func GetDefaultAuthConfig(cfg *configfile.ConfigFile, checkCredStore bool, serve
// If defaultUsername is not empty, the username prompt includes that username
// and the user can hit enter without inputting a username to use that default
// username.
func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword, defaultUsername, serverAddress string) (registrytypes.AuthConfig, error) {
func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword, defaultUsername, serverAddress string) (registry.AuthConfig, error) {
// On Windows, force the use of the regular OS stdin stream.
//
// See:
Expand Down Expand Up @@ -134,21 +133,21 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword
var err error
argUser, err = prompt.ReadInput(ctx, cli.In(), cli.Out(), msg)
if err != nil {
return registrytypes.AuthConfig{}, err
return registry.AuthConfig{}, err
}
if argUser == "" {
argUser = defaultUsername
}
if argUser == "" {
return registrytypes.AuthConfig{}, errors.New("error: username is required")
return registry.AuthConfig{}, errors.New("error: username is required")
}
}

argPassword = strings.TrimSpace(argPassword)
if argPassword == "" {
restoreInput, err := prompt.DisableInputEcho(cli.In())
if err != nil {
return registrytypes.AuthConfig{}, err
return registry.AuthConfig{}, err
}
defer func() {
if err := restoreInput(); err != nil {
Expand All @@ -168,15 +167,15 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword

argPassword, err = prompt.ReadInput(ctx, cli.In(), cli.Out(), "Password: ")
if err != nil {
return registrytypes.AuthConfig{}, err
return registry.AuthConfig{}, err
}
_, _ = fmt.Fprintln(cli.Out())
if argPassword == "" {
return registrytypes.AuthConfig{}, errors.New("error: password is required")
return registry.AuthConfig{}, errors.New("error: password is required")
}
}

return registrytypes.AuthConfig{
return registry.AuthConfig{
Username: argUser,
Password: argPassword,
ServerAddress: serverAddress,
Expand All @@ -200,7 +199,7 @@ func RetrieveAuthTokenFromImage(cfg *configfile.ConfigFile, image string) (strin
return "", err
}

encodedAuth, err := authconfig.Encode(registrytypes.AuthConfig{
encodedAuth, err := authconfig.Encode(registry.AuthConfig{
Username: authConfig.Username,
Password: authConfig.Password,
ServerAddress: authConfig.ServerAddress,
Expand Down
3 changes: 1 addition & 2 deletions cli/command/registry/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config/configfile"
configtypes "github.com/docker/cli/cli/config/types"
"github.com/docker/cli/internal/commands"
"github.com/docker/cli/internal/oauth/manager"
"github.com/docker/cli/internal/registry"
Expand Down Expand Up @@ -283,7 +282,7 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCLI command.Cli) (msg st

func storeCredentials(cfg *configfile.ConfigFile, authConfig registrytypes.AuthConfig) error {
creds := cfg.GetCredentialsStore(authConfig.ServerAddress)
if err := creds.Store(configtypes.AuthConfig{
if err := creds.Store(registrytypes.AuthConfig{
Username: authConfig.Username,
Password: authConfig.Password,
ServerAddress: authConfig.ServerAddress,
Expand Down
49 changes: 24 additions & 25 deletions cli/command/registry/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/creack/pty"
configtypes "github.com/docker/cli/cli/config/types"
"github.com/docker/cli/cli/streams"
"github.com/docker/cli/internal/prompt"
"github.com/docker/cli/internal/registry"
Expand Down Expand Up @@ -90,14 +89,14 @@ func TestLoginWithCredStoreCreds(t *testing.T) {
func TestRunLogin(t *testing.T) {
testCases := []struct {
doc string
priorCredentials map[string]configtypes.AuthConfig
priorCredentials map[string]registrytypes.AuthConfig
input loginOptions
expectedCredentials map[string]configtypes.AuthConfig
expectedCredentials map[string]registrytypes.AuthConfig
expectedErr string
}{
{
doc: "valid auth from store",
priorCredentials: map[string]configtypes.AuthConfig{
priorCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: "a-password",
Expand All @@ -107,7 +106,7 @@ func TestRunLogin(t *testing.T) {
input: loginOptions{
serverAddress: "reg1",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: "a-password",
Expand All @@ -117,7 +116,7 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "expired auth from store",
priorCredentials: map[string]configtypes.AuthConfig{
priorCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: expiredPassword,
Expand All @@ -131,13 +130,13 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "store valid username and password",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
serverAddress: "reg1",
user: "my-username",
password: "p2",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: "p2",
Expand All @@ -147,7 +146,7 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "unknown user w/ prior credentials",
priorCredentials: map[string]configtypes.AuthConfig{
priorCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: "a-password",
Expand All @@ -160,7 +159,7 @@ func TestRunLogin(t *testing.T) {
password: "a-password",
},
expectedErr: errUnknownUser,
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "a-password",
Password: "a-password",
Expand All @@ -170,24 +169,24 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "unknown user w/o prior credentials",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
serverAddress: "reg1",
user: unknownUser,
password: "a-password",
},
expectedErr: errUnknownUser,
expectedCredentials: map[string]configtypes.AuthConfig{},
expectedCredentials: map[string]registrytypes.AuthConfig{},
},
{
doc: "store valid token",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
serverAddress: "reg1",
user: "my-username",
password: useToken,
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
IdentityToken: useToken,
Expand All @@ -197,7 +196,7 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "valid token from store",
priorCredentials: map[string]configtypes.AuthConfig{
priorCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
Password: useToken,
Expand All @@ -207,7 +206,7 @@ func TestRunLogin(t *testing.T) {
input: loginOptions{
serverAddress: "reg1",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"reg1": {
Username: "my-username",
IdentityToken: useToken,
Expand All @@ -217,12 +216,12 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "no registry specified defaults to index server",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
user: "my-username",
password: "my-password",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
registry.IndexServer: {
Username: "my-username",
Password: "my-password",
Expand All @@ -232,13 +231,13 @@ func TestRunLogin(t *testing.T) {
},
{
doc: "registry-1.docker.io",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
serverAddress: "registry-1.docker.io",
user: "my-username",
password: "my-password",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"registry-1.docker.io": {
Username: "my-username",
Password: "my-password",
Expand All @@ -249,13 +248,13 @@ func TestRunLogin(t *testing.T) {
// Regression test for https://github.com/docker/cli/issues/5382
{
doc: "sanitizes server address to remove repo",
priorCredentials: map[string]configtypes.AuthConfig{},
priorCredentials: map[string]registrytypes.AuthConfig{},
input: loginOptions{
serverAddress: "registry-1.docker.io/bork/test",
user: "my-username",
password: "a-password",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"registry-1.docker.io": {
Username: "my-username",
Password: "a-password",
Expand All @@ -266,7 +265,7 @@ func TestRunLogin(t *testing.T) {
// Regression test for https://github.com/docker/cli/issues/5382
{
doc: "updates credential if server address includes repo",
priorCredentials: map[string]configtypes.AuthConfig{
priorCredentials: map[string]registrytypes.AuthConfig{
"registry-1.docker.io": {
Username: "my-username",
Password: "a-password",
Expand All @@ -278,7 +277,7 @@ func TestRunLogin(t *testing.T) {
user: "my-username",
password: "new-password",
},
expectedCredentials: map[string]configtypes.AuthConfig{
expectedCredentials: map[string]registrytypes.AuthConfig{
"registry-1.docker.io": {
Username: "my-username",
Password: "new-password",
Expand Down Expand Up @@ -428,7 +427,7 @@ func TestLoginNonInteractive(t *testing.T) {
if serverAddress == "" {
serverAddress = "https://index.docker.io/v1/"
}
assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(configtypes.AuthConfig{
assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(registrytypes.AuthConfig{
Username: "my-username",
Password: "my-password",
ServerAddress: serverAddress,
Expand Down
3 changes: 1 addition & 2 deletions cli/command/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config/configfile"
configtypes "github.com/docker/cli/cli/config/types"
"github.com/moby/moby/api/pkg/authconfig"
"github.com/moby/moby/api/types/registry"
"gotest.tools/v3/assert"
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestGetDefaultAuthConfig(t *testing.T) {
}
cfg := configfile.New("filename")
for _, authConfig := range testAuthConfigs {
assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(configtypes.AuthConfig{
assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(registry.AuthConfig{
Username: authConfig.Username,
Password: authConfig.Password,
ServerAddress: authConfig.ServerAddress,
Expand Down
Loading
Loading