From 7189716d5ad2027b70553ef03e1f91f8c905b1fa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 8 Feb 2023 02:31:59 +0100 Subject: [PATCH] replace uses of deprecated api/types.AuthConfig Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 2 +- cli/command/image/build.go | 5 +++-- cli/command/image/trust.go | 8 ++++---- cli/command/registry.go | 20 ++++++++++---------- cli/command/registry/login.go | 5 ++--- cli/command/registry/login_test.go | 8 ++++---- cli/command/registry_test.go | 9 +++++---- cli/registry/client/client.go | 3 +-- cli/registry/client/endpoint.go | 4 ++-- cli/trust/trust.go | 11 +++++------ 10 files changed, 37 insertions(+), 38 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index b4fc151474..6750ce1c0c 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -191,7 +191,7 @@ func (cli *DockerCli) ManifestStore() manifeststore.Store { // RegistryClient returns a client for communicating with a Docker distribution // registry func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient { - resolver := func(ctx context.Context, index *registry.IndexInfo) types.AuthConfig { + resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig { return ResolveAuthConfig(ctx, cli, index) } return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure) diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 7012f60867..27b6cafd87 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -22,6 +22,7 @@ import ( "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" + registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/builder/remotecontext/urlutil" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/idtools" @@ -322,9 +323,9 @@ func runBuild(dockerCli command.Cli, options buildOptions) error { configFile := dockerCli.ConfigFile() creds, _ := configFile.GetAllCredentials() - authConfigs := make(map[string]types.AuthConfig, len(creds)) + authConfigs := make(map[string]registrytypes.AuthConfig, len(creds)) for k, auth := range creds { - authConfigs[k] = types.AuthConfig(auth) + authConfigs[k] = registrytypes.AuthConfig(auth) } buildOptions := imageBuildOptions(dockerCli, options) buildOptions.Version = types.BuilderV1 diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index 91e0b67477..9e06c4604b 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -30,7 +30,7 @@ type target struct { } // TrustedPush handles content trust pushing of an image -func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, options types.ImagePushOptions) error { +func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, options types.ImagePushOptions) error { responseBody, err := cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options) if err != nil { return err @@ -44,7 +44,7 @@ func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi // PushTrustedReference pushes a canonical reference to the trust server. // //nolint:gocyclo -func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, in io.Reader) error { +func PushTrustedReference(streams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error { // If it is a trusted push we would like to find the target entry which match the // tag provided in the function and then do an AddTarget later. target := &client.Target{} @@ -340,8 +340,8 @@ func TagTrusted(ctx context.Context, cli command.Cli, trustedRef reference.Canon } // AuthResolver returns an auth resolver function from a command.Cli -func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig { - return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig { +func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig { + return func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig { return command.ResolveAuthConfig(ctx, cli, index) } } diff --git a/cli/command/registry.go b/cli/command/registry.go index 8bfad12fd2..7ed01b55f4 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -22,7 +22,7 @@ import ( ) // EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload -func EncodeAuthToBase64(authConfig types.AuthConfig) (string, error) { +func EncodeAuthToBase64(authConfig registrytypes.AuthConfig) (string, error) { buf, err := json.Marshal(authConfig) if err != nil { return "", err @@ -52,19 +52,19 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf // ResolveAuthConfig is like registry.ResolveAuthConfig, but if using the // default index, it uses the default index name for the daemon's platform, // not the client's platform. -func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) types.AuthConfig { +func ResolveAuthConfig(_ context.Context, cli Cli, index *registrytypes.IndexInfo) registrytypes.AuthConfig { configKey := index.Name if index.Official { configKey = registry.IndexServer } a, _ := cli.ConfigFile().GetAuthConfig(configKey) - return types.AuthConfig(a) + return registrytypes.AuthConfig(a) } // 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(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) { +func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (registrytypes.AuthConfig, error) { if !isDefaultRegistry { serverAddress = registry.ConvertToHostname(serverAddress) } @@ -73,19 +73,19 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is if checkCredStore { authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress) if err != nil { - return types.AuthConfig{ + return registrytypes.AuthConfig{ ServerAddress: serverAddress, }, err } } authconfig.ServerAddress = serverAddress authconfig.IdentityToken = "" - res := types.AuthConfig(authconfig) + res := registrytypes.AuthConfig(authconfig) return res, nil } // ConfigureAuth handles prompting of user's username and password if needed -func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *types.AuthConfig, isDefaultRegistry bool) error { +func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes.AuthConfig, isDefaultRegistry bool) error { // On Windows, force the use of the regular OS stdin stream. Fixes #14336/#14210 if runtime.GOOS == "windows" { cli.SetIn(streams.NewIn(os.Stdin)) @@ -175,14 +175,14 @@ func RetrieveAuthTokenFromImage(ctx context.Context, cli Cli, image string) (str } // resolveAuthConfigFromImage retrieves that AuthConfig using the image string -func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (types.AuthConfig, error) { +func resolveAuthConfigFromImage(ctx context.Context, cli Cli, image string) (registrytypes.AuthConfig, error) { registryRef, err := reference.ParseNormalizedNamed(image) if err != nil { - return types.AuthConfig{}, err + return registrytypes.AuthConfig{}, err } repoInfo, err := registry.ParseRepositoryInfo(registryRef) if err != nil { - return types.AuthConfig{}, err + return registrytypes.AuthConfig{}, err } return ResolveAuthConfig(ctx, cli, repoInfo.Index), nil } diff --git a/cli/command/registry/login.go b/cli/command/registry/login.go index 0e0a8465fd..7ddfccca20 100644 --- a/cli/command/registry/login.go +++ b/cli/command/registry/login.go @@ -10,7 +10,6 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" configtypes "github.com/docker/cli/cli/config/types" - "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/client" "github.com/docker/docker/errdefs" @@ -164,7 +163,7 @@ func runLogin(dockerCli command.Cli, opts loginOptions) error { //nolint:gocyclo return nil } -func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *types.AuthConfig) (registrytypes.AuthenticateOKBody, error) { +func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authConfig *registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { fmt.Fprintf(dockerCli.Out(), "Authenticating with existing credentials...\n") cliClient := dockerCli.Client() response, err := cliClient.RegistryLogin(ctx, *authConfig) @@ -178,7 +177,7 @@ func loginWithCredStoreCreds(ctx context.Context, dockerCli command.Cli, authCon return response, err } -func loginClientSide(ctx context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) { +func loginClientSide(ctx context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { svc, err := registry.NewService(registry.ServiceOptions{}) if err != nil { return registrytypes.AuthenticateOKBody{}, err diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index 483f4578ee..8a16925705 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -38,7 +38,7 @@ func (c fakeClient) Info(context.Context) (types.Info, error) { return types.Info{}, nil } -func (c fakeClient) RegistryLogin(_ context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) { +func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { if auth.Password == expiredPassword { return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") } @@ -53,16 +53,16 @@ func (c fakeClient) RegistryLogin(_ context.Context, auth types.AuthConfig) (reg func TestLoginWithCredStoreCreds(t *testing.T) { testCases := []struct { - inputAuthConfig types.AuthConfig + inputAuthConfig registrytypes.AuthConfig expectedMsg string expectedErr string }{ { - inputAuthConfig: types.AuthConfig{}, + inputAuthConfig: registrytypes.AuthConfig{}, expectedMsg: "Authenticating with existing credentials...\n", }, { - inputAuthConfig: types.AuthConfig{ + inputAuthConfig: registrytypes.AuthConfig{ Username: userErr, }, expectedMsg: "Authenticating with existing credentials...\n", diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index be518e3175..6c45614930 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -10,6 +10,7 @@ import ( configtypes "github.com/docker/cli/cli/config/types" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/client" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -20,7 +21,7 @@ type fakeClient struct { infoFunc func() (types.Info, error) } -var testAuthConfigs = []types.AuthConfig{ +var testAuthConfigs = []registry.AuthConfig{ { ServerAddress: "https://index.docker.io/v1/", Username: "u0", @@ -45,13 +46,13 @@ func TestGetDefaultAuthConfig(t *testing.T) { checkCredStore bool inputServerAddress string expectedErr string - expectedAuthConfig types.AuthConfig + expectedAuthConfig registry.AuthConfig }{ { checkCredStore: false, inputServerAddress: "", expectedErr: "", - expectedAuthConfig: types.AuthConfig{ + expectedAuthConfig: registry.AuthConfig{ ServerAddress: "", Username: "", Password: "", @@ -101,7 +102,7 @@ func TestGetDefaultAuthConfig_HelperError(t *testing.T) { cli.SetErr(errBuf) cli.ConfigFile().CredentialsStore = "fake-does-not-exist" serverAddress := "test-server-address" - expectedAuthConfig := types.AuthConfig{ + expectedAuthConfig := registry.AuthConfig{ ServerAddress: serverAddress, } authconfig, err := GetDefaultAuthConfig(cli, true, serverAddress, serverAddress == "https://index.docker.io/v1/") diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index ba76a34fc8..86fc775684 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -10,7 +10,6 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/reference" distributionclient "github.com/docker/distribution/registry/client" - "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/opencontainers/go-digest" "github.com/pkg/errors" @@ -36,7 +35,7 @@ func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure b } // AuthConfigResolver returns Auth Configuration for an index -type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig +type AuthConfigResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig // PutManifestOptions is the data sent to push a manifest type PutManifestOptions struct { diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index 31295eed33..c6987badb3 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -9,7 +9,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/transport" - authtypes "github.com/docker/docker/api/types" + registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/registry" "github.com/pkg/errors" ) @@ -74,7 +74,7 @@ func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry } // getHTTPTransport builds a transport for use in communicating with a registry -func getHTTPTransport(authConfig authtypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) { +func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) { // get the http transport, this will be used in a client to upload manifest base := &http.Transport{ Proxy: http.ProxyFromEnvironment, diff --git a/cli/trust/trust.go b/cli/trust/trust.go index d194dbe459..5a862e7f0b 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -17,7 +17,6 @@ import ( "github.com/docker/distribution/registry/client/auth" "github.com/docker/distribution/registry/client/auth/challenge" "github.com/docker/distribution/registry/client/transport" - "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/registry" "github.com/docker/go-connections/tlsconfig" @@ -79,7 +78,7 @@ func Server(index *registrytypes.IndexInfo) (string, error) { } type simpleCredentialStore struct { - auth types.AuthConfig + auth registrytypes.AuthConfig } func (scs simpleCredentialStore) Basic(*url.URL) (string, string) { @@ -95,7 +94,7 @@ func (scs simpleCredentialStore) SetRefreshToken(*url.URL, string, string) {} // GetNotaryRepository returns a NotaryRepository which stores all the // information needed to operate on a notary repository. // It creates an HTTP transport providing authentication support. -func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *registry.RepositoryInfo, authConfig *types.AuthConfig, actions ...string) (client.Repository, error) { +func GetNotaryRepository(in io.Reader, out io.Writer, userAgent string, repoInfo *registry.RepositoryInfo, authConfig *registrytypes.AuthConfig, actions ...string) (client.Repository, error) { server, err := Server(repoInfo.Index) if err != nil { return nil, err @@ -291,7 +290,7 @@ func GetSignableRoles(repo client.Repository, target *client.Target) ([]data.Rol // ImageRefAndAuth contains all reference information and the auth config for an image request type ImageRefAndAuth struct { original string - authConfig *types.AuthConfig + authConfig *registrytypes.AuthConfig reference reference.Named repoInfo *registry.RepositoryInfo tag string @@ -301,7 +300,7 @@ type ImageRefAndAuth struct { // GetImageReferencesAndAuth retrieves the necessary reference and auth information for an image name // as an ImageRefAndAuth struct func GetImageReferencesAndAuth(ctx context.Context, - authResolver func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig, + authResolver func(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig, imgName string, ) (ImageRefAndAuth, error) { ref, err := reference.ParseNormalizedNamed(imgName) @@ -349,7 +348,7 @@ func getDigest(ref reference.Named) digest.Digest { } // AuthConfig returns the auth information (username, etc) for a given ImageRefAndAuth -func (imgRefAuth *ImageRefAndAuth) AuthConfig() *types.AuthConfig { +func (imgRefAuth *ImageRefAndAuth) AuthConfig() *registrytypes.AuthConfig { return imgRefAuth.authConfig }