Skip to content

Commit 74a2bda

Browse files
committed
replace uses of deprecated api/types.AuthConfig
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 104f119 commit 74a2bda

File tree

10 files changed

+42
-45
lines changed

10 files changed

+42
-45
lines changed

cli/command/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (cli *DockerCli) ManifestStore() manifeststore.Store {
191191
// RegistryClient returns a client for communicating with a Docker distribution
192192
// registry
193193
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient {
194-
resolver := func(ctx context.Context, index *registry.IndexInfo) types.AuthConfig {
194+
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
195195
return ResolveAuthConfig(ctx, cli, index)
196196
}
197197
return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure)

cli/command/image/build.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/docker/docker/api"
2323
"github.com/docker/docker/api/types"
2424
"github.com/docker/docker/api/types/container"
25+
registrytypes "github.com/docker/docker/api/types/registry"
2526
"github.com/docker/docker/builder/remotecontext/urlutil"
2627
"github.com/docker/docker/pkg/archive"
2728
"github.com/docker/docker/pkg/idtools"
@@ -322,9 +323,9 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
322323

323324
configFile := dockerCli.ConfigFile()
324325
creds, _ := configFile.GetAllCredentials()
325-
authConfigs := make(map[string]types.AuthConfig, len(creds))
326+
authConfigs := make(map[string]registrytypes.AuthConfig, len(creds))
326327
for k, auth := range creds {
327-
authConfigs[k] = types.AuthConfig(auth)
328+
authConfigs[k] = registrytypes.AuthConfig(auth)
328329
}
329330
buildOptions := imageBuildOptions(dockerCli, options)
330331
buildOptions.Version = types.BuilderV1

cli/command/image/trust.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type target struct {
3030
}
3131

3232
// TrustedPush handles content trust pushing of an image
33-
func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, options types.ImagePushOptions) error {
33+
func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, options types.ImagePushOptions) error {
3434
responseBody, err := cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
3535
if err != nil {
3636
return err
@@ -44,7 +44,7 @@ func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi
4444
// PushTrustedReference pushes a canonical reference to the trust server.
4545
//
4646
//nolint:gocyclo
47-
func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error {
47+
func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error {
4848
// If it is a trusted push we would like to find the target entry which match the
4949
// tag provided in the function and then do an AddTarget later.
5050
target := &client.Target{}
@@ -340,8 +340,8 @@ func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canon
340340
}
341341

342342
// AuthResolver returns an auth resolver function from a command.Cli
343-
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
344-
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
343+
func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
344+
return func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
345345
return command.ResolveAuthConfig(ctx, cli, index)
346346
}
347347
}

cli/command/registry.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ import (
2222
)
2323

2424
// ElectAuthServer returns the default registry to use
25-
// Deprecated: use registry.IndexServer instead
25+
//
26+
// Deprecated: use [registry.IndexServer] instead.
2627
func ElectAuthServer(_ context.Context, _ Cli) string {
2728
return registry.IndexServer
2829
}
2930

3031
// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload
31-
func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) {
32+
func EncodeAuthToBase64(authConfig registrytypes.AuthConfig) (string, error) {
3233
buf, err := json.Marshal(authConfig)
3334
if err != nil {
3435
return "", err
@@ -58,19 +59,19 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
5859
// ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the
5960
// default index, it uses the default index name for the daemon's platform,
6061
// not the client's platform.
61-
func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) types.AuthConfig {
62+
func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) registrytypes.AuthConfig {
6263
configKey := index.Name
6364
if index.Official {
6465
configKey = registry.IndexServer
6566
}
6667

6768
a, _ := cli.ConfigFile().GetAuthConfig(configKey)
68-
return types.AuthConfig(a)
69+
return registrytypes.AuthConfig(a)
6970
}
7071

7172
// GetDefaultAuthConfig gets the default auth config given a serverAddress
7273
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
73-
func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
74+
func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error) {
7475
if !isDefaultRegistry {
7576
serverAddress = registry.ConvertToHostname(serverAddress)
7677
}
@@ -79,19 +80,19 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is
7980
if checkCredStore {
8081
authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress)
8182
if err != nil {
82-
return types.AuthConfig{
83+
return registrytypes.AuthConfig{
8384
ServerAddress: serverAddress,
8485
}, err
8586
}
8687
}
8788
authconfig.ServerAddress = serverAddress
8889
authconfig.IdentityToken = ""
89-
res := types.AuthConfig(authconfig)
90+
res := registrytypes.AuthConfig(authconfig)
9091
return res, nil
9192
}
9293

9394
// ConfigureAuth handles prompting of user's username and password if needed
94-
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *types.AuthConfig, isDefaultRegistry bool) error {
95+
func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes.AuthConfig, isDefaultRegistry bool) error {
9596
// On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210
9697
if runtime.GOOS == "windows" {
9798
cli.SetIn(streams.NewIn(os.Stdin))
@@ -181,14 +182,14 @@ func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (str
181182
}
182183

183184
// resolveAuthConfigFromImage retrieves that AuthConfig using the image string
184-
func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (types.AuthConfig, error) {
185+
func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (registrytypes.AuthConfig, error) {
185186
registryRef, err := reference.ParseNormalizedNamed(image)
186187
if err != nil {
187-
return types.AuthConfig{}, err
188+
return registrytypes.AuthConfig{}, err
188189
}
189190
repoInfo, err := registry.ParseRepositoryInfo(registryRef)
190191
if err != nil {
191-
return types.AuthConfig{}, err
192+
return registrytypes.AuthConfig{}, err
192193
}
193194
return ResolveAuthConfig(ctx, cli, repoInfo.Index), nil
194195
}

cli/command/registry/login.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/cli/command"
1111
"github.com/docker/cli/cli/command/completion"
1212
configtypes "github.com/docker/cli/cli/config/types"
13-
"github.com/docker/docker/api/types"
1413
registrytypes "github.com/docker/docker/api/types/registry"
1514
"github.com/docker/docker/client"
1615
"github.com/docker/docker/errdefs"
@@ -164,7 +163,7 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint:gocyclo
164163
return nil
165164
}
166165

167-
func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
166+
func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
168167
fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n")
169168
cliClient := dockerCli.Client()
170169
response, err := cliClient.RegistryLogin(ctx, *authConfig)
@@ -178,7 +177,7 @@ func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authCon
178177
return response, err
179178
}
180179

181-
func loginClientSide(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
180+
func loginClientSide(ctx context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
182181
svc, err := registry.NewService(registry.ServiceOptions{})
183182
if err != nil {
184183
return registrytypes.AuthenticateOKBody{}, err

cli/command/registry/login_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (c fakeClient) Info(ctx context.Context) (types.Info, error) {
3838
return types.Info{}, nil
3939
}
4040

41-
func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
41+
func (c fakeClient) RegistryLogin(ctx context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) {
4242
if auth.Password == expiredPassword {
4343
return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password")
4444
}
@@ -53,16 +53,16 @@ func (c fakeClient) RegistryLogin(ctx context.Context, auth types.AuthConfig) (r
5353

5454
func TestLoginWithCredStoreCreds(t *testing.T) {
5555
testCases := []struct {
56-
inputAuthConfig types.AuthConfig
56+
inputAuthConfig registrytypes.AuthConfig
5757
expectedMsg string
5858
expectedErr string
5959
}{
6060
{
61-
inputAuthConfig: types.AuthConfig{},
61+
inputAuthConfig: registrytypes.AuthConfig{},
6262
expectedMsg: "Authenticating with existing credentials...\n",
6363
},
6464
{
65-
inputAuthConfig: types.AuthConfig{
65+
inputAuthConfig: registrytypes.AuthConfig{
6666
Username: userErr,
6767
},
6868
expectedMsg: "Authenticating with existing credentials...\n",

cli/command/registry_test.go

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

9-
"gotest.tools/v3/assert"
10-
is "gotest.tools/v3/assert/cmp"
11-
12-
// Prevents a circular import with "github.com/docker/cli/internal/test"
13-
14-
. "github.com/docker/cli/cli/command"
9+
. "github.com/docker/cli/cli/command" // Prevents a circular import with "github.com/docker/cli/internal/test"
1510
configtypes "github.com/docker/cli/cli/config/types"
1611
"github.com/docker/cli/internal/test"
1712
"github.com/docker/docker/api/types"
13+
"github.com/docker/docker/api/types/registry"
1814
"github.com/docker/docker/client"
15+
"gotest.tools/v3/assert"
16+
is "gotest.tools/v3/assert/cmp"
1917
)
2018

2119
type fakeClient struct {
2220
client.Client
2321
infoFunc func() (types.Info, error)
2422
}
2523

26-
var testAuthConfigs = []types.AuthConfig{
24+
var testAuthConfigs = []registry.AuthConfig{
2725
{
2826
ServerAddress: "https://index.docker.io/v1/",
2927
Username: "u0",
@@ -48,13 +46,13 @@ func TestGetDefaultAuthConfig(t *testing.T) {
4846
checkCredStore bool
4947
inputServerAddress string
5048
expectedErr string
51-
expectedAuthConfig types.AuthConfig
49+
expectedAuthConfig registry.AuthConfig
5250
}{
5351
{
5452
checkCredStore: false,
5553
inputServerAddress: "",
5654
expectedErr: "",
57-
expectedAuthConfig: types.AuthConfig{
55+
expectedAuthConfig: registry.AuthConfig{
5856
ServerAddress: "",
5957
Username: "",
6058
Password: "",
@@ -104,7 +102,7 @@ func TestGetDefaultAuthConfig_HelperError(t *testing.T) {
104102
cli.SetErr(errBuf)
105103
cli.ConfigFile().CredentialsStore = "fake-does-not-exist"
106104
serverAddress := "test-server-address"
107-
expectedAuthConfig := types.AuthConfig{
105+
expectedAuthConfig := registry.AuthConfig{
108106
ServerAddress: serverAddress,
109107
}
110108
authconfig, err := GetDefaultAuthConfig(cli, true, serverAddress, serverAddress == "https://index.docker.io/v1/")

cli/registry/client/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/distribution"
1111
"github.com/docker/distribution/reference"
1212
distributionclient "github.com/docker/distribution/registry/client"
13-
"github.com/docker/docker/api/types"
1413
registrytypes "github.com/docker/docker/api/types/registry"
1514
"github.com/opencontainers/go-digest"
1615
"github.com/pkg/errors"
@@ -36,7 +35,7 @@ func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure b
3635
}
3736

3837
// AuthConfigResolver returns Auth Configuration for an index
39-
type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig
38+
type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig
4039

4140
// PutManifestOptions is the data sent to push a manifest
4241
type PutManifestOptions struct {

cli/registry/client/endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/docker/distribution/reference"
1010
"github.com/docker/distribution/registry/client/auth"
1111
"github.com/docker/distribution/registry/client/transport"
12-
authtypes "github.com/docker/docker/api/types"
12+
registrytypes "github.com/docker/docker/api/types/registry"
1313
"github.com/docker/docker/registry"
1414
"github.com/pkg/errors"
1515
)
@@ -74,7 +74,7 @@ func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry
7474
}
7575

7676
// getHTTPTransport builds a transport for use in communicating with a registry
77-
func getHTTPTransport(authConfig authtypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) {
77+
func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) {
7878
// get the http transport, this will be used in a client to upload manifest
7979
base := &http.Transport{
8080
Proxy: http.ProxyFromEnvironment,

cli/trust/trust.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/docker/distribution/registry/client/auth"
1818
"github.com/docker/distribution/registry/client/auth/challenge"
1919
"github.com/docker/distribution/registry/client/transport"
20-
"github.com/docker/docker/api/types"
2120
registrytypes "github.com/docker/docker/api/types/registry"
2221
"github.com/docker/docker/registry"
2322
"github.com/docker/go-connections/tlsconfig"
@@ -79,7 +78,7 @@ func Server(index *registrytypes.IndexInfo) (string, error) {
7978
}
8079

8180
type simpleCredentialStore struct {
82-
auth types.AuthConfig
81+
auth registrytypes.AuthConfig
8382
}
8483

8584
func (scs simpleCredentialStore) Basic(u *url.URL) (string, string) {
@@ -96,7 +95,7 @@ func (scs simpleCredentialStore) SetRefreshToken(*url.URL, string, string) {
9695
// GetNotaryRepository returns a NotaryRepository which stores all the
9796
// information needed to operate on a notary repository.
9897
// It creates an HTTP transport providing authentication support.
99-
func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *registry.RepositoryInfo, authConfig *types.AuthConfig, actions ...string) (client.Repository, error) {
98+
func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *registry.RepositoryInfo, authConfig *registrytypes.AuthConfig, actions ...string) (client.Repository, error) {
10099
server, err := Server(repoInfo.Index)
101100
if err != nil {
102101
return nil, err
@@ -292,7 +291,7 @@ func GetSignableRoles(repo client.Repository, target *client.Target) ([]data.Rol
292291
// ImageRefAndAuth contains all reference information and the auth config for an image request
293292
type ImageRefAndAuth struct {
294293
original string
295-
authConfig *types.AuthConfig
294+
authConfig *registrytypes.AuthConfig
296295
reference reference.Named
297296
repoInfo *registry.RepositoryInfo
298297
tag string
@@ -302,7 +301,7 @@ type ImageRefAndAuth struct {
302301
// GetImageReferencesAndAuth retrieves the necessary reference and auth information for an image name
303302
// as an ImageRefAndAuth struct
304303
func GetImageReferencesAndAuth(ctx context.Context, rs registry.Service,
305-
authResolver func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig,
304+
authResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig,
306305
imgName string,
307306
) (ImageRefAndAuth, error) {
308307
ref, err := reference.ParseNormalizedNamed(imgName)
@@ -356,7 +355,7 @@ func getDigest(ref reference.Named) digest.Digest {
356355
}
357356

358357
// AuthConfig returns the auth information (username, etc) for a given ImageRefAndAuth
359-
func (imgRefAuth *ImageRefAndAuth) AuthConfig() *types.AuthConfig {
358+
func (imgRefAuth *ImageRefAndAuth) AuthConfig() *registrytypes.AuthConfig {
360359
return imgRefAuth.authConfig
361360
}
362361

0 commit comments

Comments
 (0)