summaryrefslogtreecommitdiff
path: root/registry
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2022-03-03 10:32:29 +0100
committerSebastiaan van Stijn <github@gone.nl>2022-07-29 23:05:20 +0200
commitd817f4dcee626b892ab94ccae2e6e71f1b29426b (patch)
tree93c6668de6f62ec511af7f5b37390b165c378dc8 /registry
parent55d1a5682638eb0d28eb52409802a2572177794b (diff)
downloaddocker-d817f4dcee626b892ab94ccae2e6e71f1b29426b.tar.gz
registry: use types/registry.AuthConfig
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'registry')
-rw-r--r--registry/auth.go13
-rw-r--r--registry/auth_test.go15
-rw-r--r--registry/registry_test.go3
-rw-r--r--registry/service.go9
-rw-r--r--registry/session.go7
5 files changed, 21 insertions, 26 deletions
diff --git a/registry/auth.go b/registry/auth.go
index 38f41db221..dd75a49f38 100644
--- a/registry/auth.go
+++ b/registry/auth.go
@@ -9,7 +9,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"
"github.com/docker/docker/api/types/registry"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -19,7 +18,7 @@ import (
const AuthClientID = "docker"
type loginCredentialStore struct {
- authConfig *types.AuthConfig
+ authConfig *registry.AuthConfig
}
func (lcs loginCredentialStore) Basic(*url.URL) (string, string) {
@@ -35,12 +34,12 @@ func (lcs loginCredentialStore) SetRefreshToken(u *url.URL, service, token strin
}
type staticCredentialStore struct {
- auth *types.AuthConfig
+ auth *registry.AuthConfig
}
// NewStaticCredentialStore returns a credential store
// which always returns the same credential values.
-func NewStaticCredentialStore(auth *types.AuthConfig) auth.CredentialStore {
+func NewStaticCredentialStore(auth *registry.AuthConfig) auth.CredentialStore {
return staticCredentialStore{
auth: auth,
}
@@ -66,7 +65,7 @@ func (scs staticCredentialStore) SetRefreshToken(*url.URL, string, string) {
// loginV2 tries to login to the v2 registry server. The given registry
// endpoint will be pinged to get authorization challenges. These challenges
// will be used to authenticate against the registry to validate credentials.
-func loginV2(authConfig *types.AuthConfig, endpoint APIEndpoint, userAgent string) (string, string, error) {
+func loginV2(authConfig *registry.AuthConfig, endpoint APIEndpoint, userAgent string) (string, string, error) {
var (
endpointStr = strings.TrimRight(endpoint.URL.String(), "/") + "/v2/"
modifiers = Headers(userAgent, nil)
@@ -138,7 +137,7 @@ func ConvertToHostname(url string) string {
}
// ResolveAuthConfig matches an auth configuration to a server address or a URL
-func ResolveAuthConfig(authConfigs map[string]types.AuthConfig, index *registry.IndexInfo) types.AuthConfig {
+func ResolveAuthConfig(authConfigs map[string]registry.AuthConfig, index *registry.IndexInfo) registry.AuthConfig {
configKey := GetAuthConfigKey(index)
// First try the happy case
if c, found := authConfigs[configKey]; found || index.Official {
@@ -154,7 +153,7 @@ func ResolveAuthConfig(authConfigs map[string]types.AuthConfig, index *registry.
}
// When all else fails, return an empty auth config
- return types.AuthConfig{}
+ return registry.AuthConfig{}
}
// PingResponseError is used when the response from a ping
diff --git a/registry/auth_test.go b/registry/auth_test.go
index 6e8809260b..eca83931af 100644
--- a/registry/auth_test.go
+++ b/registry/auth_test.go
@@ -3,16 +3,15 @@ package registry // import "github.com/docker/docker/registry"
import (
"testing"
- "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"gotest.tools/v3/assert"
)
-func buildAuthConfigs() map[string]types.AuthConfig {
- authConfigs := map[string]types.AuthConfig{}
+func buildAuthConfigs() map[string]registry.AuthConfig {
+ authConfigs := map[string]registry.AuthConfig{}
for _, reg := range []string{"testIndex", IndexServer} {
- authConfigs[reg] = types.AuthConfig{
+ authConfigs[reg] = registry.AuthConfig{
Username: "docker-user",
Password: "docker-pass",
}
@@ -42,21 +41,21 @@ func TestResolveAuthConfigIndexServer(t *testing.T) {
func TestResolveAuthConfigFullURL(t *testing.T) {
authConfigs := buildAuthConfigs()
- registryAuth := types.AuthConfig{
+ registryAuth := registry.AuthConfig{
Username: "foo-user",
Password: "foo-pass",
}
- localAuth := types.AuthConfig{
+ localAuth := registry.AuthConfig{
Username: "bar-user",
Password: "bar-pass",
}
- officialAuth := types.AuthConfig{
+ officialAuth := registry.AuthConfig{
Username: "baz-user",
Password: "baz-pass",
}
authConfigs[IndexServer] = officialAuth
- expectedAuths := map[string]types.AuthConfig{
+ expectedAuths := map[string]registry.AuthConfig{
"registry.example.com": registryAuth,
"localhost:8000": localAuth,
"example.com": localAuth,
diff --git a/registry/registry_test.go b/registry/registry_test.go
index 7c3a4e16c3..889064e0cc 100644
--- a/registry/registry_test.go
+++ b/registry/registry_test.go
@@ -9,7 +9,6 @@ import (
"github.com/docker/distribution/reference"
"github.com/docker/distribution/registry/client/transport"
- "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@@ -17,7 +16,7 @@ import (
)
func spawnTestRegistrySession(t *testing.T) *session {
- authConfig := &types.AuthConfig{}
+ authConfig := &registry.AuthConfig{}
endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil)
if err != nil {
t.Fatal(err)
diff --git a/registry/service.go b/registry/service.go
index 25b116a279..a4453bb17a 100644
--- a/registry/service.go
+++ b/registry/service.go
@@ -10,7 +10,6 @@ import (
"github.com/docker/distribution/reference"
"github.com/docker/distribution/registry/client/auth"
- "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
"github.com/sirupsen/logrus"
@@ -18,11 +17,11 @@ import (
// Service is the interface defining what a registry service should implement.
type Service interface {
- Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error)
+ Auth(ctx context.Context, authConfig *registry.AuthConfig, userAgent string) (status, token string, err error)
LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error)
LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error)
ResolveRepository(name reference.Named) (*RepositoryInfo, error)
- Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registry.SearchResults, error)
+ Search(ctx context.Context, term string, limit int, authConfig *registry.AuthConfig, userAgent string, headers map[string][]string) (*registry.SearchResults, error)
ServiceConfig() *registry.ServiceConfig
LoadAllowNondistributableArtifacts([]string) error
LoadMirrors([]string) error
@@ -78,7 +77,7 @@ func (s *defaultService) LoadInsecureRegistries(registries []string) error {
// Auth contacts the public registry with the provided credentials,
// and returns OK if authentication was successful.
// It can be used to verify the validity of a client's credentials.
-func (s *defaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) {
+func (s *defaultService) Auth(ctx context.Context, authConfig *registry.AuthConfig, userAgent string) (status, token string, err error) {
// TODO Use ctx when searching for repositories
var registryHostName = IndexHostname
@@ -131,7 +130,7 @@ func splitReposSearchTerm(reposName string) (string, string) {
// Search queries the public registry for images matching the specified
// search terms, and returns the results.
-func (s *defaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registry.SearchResults, error) {
+func (s *defaultService) Search(ctx context.Context, term string, limit int, authConfig *registry.AuthConfig, userAgent string, headers map[string][]string) (*registry.SearchResults, error) {
// TODO Use ctx when searching for repositories
if hasScheme(term) {
return nil, invalidParamf("invalid repository name: repository name (%s) should not have a scheme", term)
diff --git a/registry/session.go b/registry/session.go
index fd193e1dd6..4c6574d26b 100644
--- a/registry/session.go
+++ b/registry/session.go
@@ -11,7 +11,6 @@ import (
"strings"
"sync"
- "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/ioutils"
@@ -30,7 +29,7 @@ type session struct {
type authTransport struct {
http.RoundTripper
- *types.AuthConfig
+ *registry.AuthConfig
alwaysSetBasicAuth bool
token []string
@@ -52,7 +51,7 @@ type authTransport struct {
// If the server sends a token without the client having requested it, it is ignored.
//
// This RoundTripper also has a CancelRequest method important for correct timeout handling.
-func newAuthTransport(base http.RoundTripper, authConfig *types.AuthConfig, alwaysSetBasicAuth bool) *authTransport {
+func newAuthTransport(base http.RoundTripper, authConfig *registry.AuthConfig, alwaysSetBasicAuth bool) *authTransport {
if base == nil {
base = http.DefaultTransport
}
@@ -147,7 +146,7 @@ func (tr *authTransport) CancelRequest(req *http.Request) {
}
}
-func authorizeClient(client *http.Client, authConfig *types.AuthConfig, endpoint *v1Endpoint) error {
+func authorizeClient(client *http.Client, authConfig *registry.AuthConfig, endpoint *v1Endpoint) error {
var alwaysSetBasicAuth bool
// If we're working with a standalone private registry over HTTPS, send Basic Auth headers