Move AuthConfig to api/types
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
4a3b23718b
commit
6fc54d049b
5 changed files with 23 additions and 26 deletions
14
docs/auth.go
14
docs/auth.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Login tries to register/login to the registry server.
|
// Login tries to register/login to the registry server.
|
||||||
func Login(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string, error) {
|
func Login(authConfig *types.AuthConfig, registryEndpoint *Endpoint) (string, error) {
|
||||||
// Separates the v2 registry login logic from the v1 logic.
|
// Separates the v2 registry login logic from the v1 logic.
|
||||||
if registryEndpoint.Version == APIVersion2 {
|
if registryEndpoint.Version == APIVersion2 {
|
||||||
return loginV2(authConfig, registryEndpoint, "" /* scope */)
|
return loginV2(authConfig, registryEndpoint, "" /* scope */)
|
||||||
|
@ -21,7 +21,7 @@ func Login(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string
|
||||||
}
|
}
|
||||||
|
|
||||||
// loginV1 tries to register/login to the v1 registry server.
|
// loginV1 tries to register/login to the v1 registry server.
|
||||||
func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string, error) {
|
func loginV1(authConfig *types.AuthConfig, registryEndpoint *Endpoint) (string, error) {
|
||||||
var (
|
var (
|
||||||
status string
|
status string
|
||||||
respBody []byte
|
respBody []byte
|
||||||
|
@ -136,7 +136,7 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri
|
||||||
// now, users should create their account through other means like directly from a web page
|
// now, users should create their account through other means like directly from a web page
|
||||||
// served by the v2 registry service provider. Whether this will be supported in the future
|
// served by the v2 registry service provider. Whether this will be supported in the future
|
||||||
// is to be determined.
|
// is to be determined.
|
||||||
func loginV2(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint, scope string) (string, error) {
|
func loginV2(authConfig *types.AuthConfig, registryEndpoint *Endpoint, scope string) (string, error) {
|
||||||
logrus.Debugf("attempting v2 login to registry endpoint %s", registryEndpoint)
|
logrus.Debugf("attempting v2 login to registry endpoint %s", registryEndpoint)
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -173,7 +173,7 @@ func loginV2(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint, scope
|
||||||
return "", fmt.Errorf("no successful auth challenge for %s - errors: %s", registryEndpoint, allErrors)
|
return "", fmt.Errorf("no successful auth challenge for %s - errors: %s", registryEndpoint, allErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryV2BasicAuthLogin(authConfig *cliconfig.AuthConfig, params map[string]string, registryEndpoint *Endpoint) error {
|
func tryV2BasicAuthLogin(authConfig *types.AuthConfig, params map[string]string, registryEndpoint *Endpoint) error {
|
||||||
req, err := http.NewRequest("GET", registryEndpoint.Path(""), nil)
|
req, err := http.NewRequest("GET", registryEndpoint.Path(""), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -194,7 +194,7 @@ func tryV2BasicAuthLogin(authConfig *cliconfig.AuthConfig, params map[string]str
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tryV2TokenAuthLogin(authConfig *cliconfig.AuthConfig, params map[string]string, registryEndpoint *Endpoint) error {
|
func tryV2TokenAuthLogin(authConfig *types.AuthConfig, params map[string]string, registryEndpoint *Endpoint) error {
|
||||||
token, err := getToken(authConfig.Username, authConfig.Password, params, registryEndpoint)
|
token, err := getToken(authConfig.Username, authConfig.Password, params, registryEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -221,7 +221,7 @@ func tryV2TokenAuthLogin(authConfig *cliconfig.AuthConfig, params map[string]str
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveAuthConfig matches an auth configuration to a server address or a URL
|
// ResolveAuthConfig matches an auth configuration to a server address or a URL
|
||||||
func ResolveAuthConfig(authConfigs map[string]cliconfig.AuthConfig, index *IndexInfo) cliconfig.AuthConfig {
|
func ResolveAuthConfig(authConfigs map[string]types.AuthConfig, index *IndexInfo) types.AuthConfig {
|
||||||
configKey := index.GetAuthConfigKey()
|
configKey := index.GetAuthConfigKey()
|
||||||
// First try the happy case
|
// First try the happy case
|
||||||
if c, found := authConfigs[configKey]; found || index.Official {
|
if c, found := authConfigs[configKey]; found || index.Official {
|
||||||
|
@ -250,5 +250,5 @@ func ResolveAuthConfig(authConfigs map[string]cliconfig.AuthConfig, index *Index
|
||||||
}
|
}
|
||||||
|
|
||||||
// When all else fails, return an empty auth config
|
// When all else fails, return an empty auth config
|
||||||
return cliconfig.AuthConfig{}
|
return types.AuthConfig{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEncodeAuth(t *testing.T) {
|
func TestEncodeAuth(t *testing.T) {
|
||||||
newAuthConfig := &cliconfig.AuthConfig{Username: "ken", Password: "test", Email: "test@example.com"}
|
newAuthConfig := &types.AuthConfig{Username: "ken", Password: "test", Email: "test@example.com"}
|
||||||
authStr := cliconfig.EncodeAuth(newAuthConfig)
|
authStr := cliconfig.EncodeAuth(newAuthConfig)
|
||||||
decAuthConfig := &cliconfig.AuthConfig{}
|
decAuthConfig := &types.AuthConfig{}
|
||||||
var err error
|
var err error
|
||||||
decAuthConfig.Username, decAuthConfig.Password, err = cliconfig.DecodeAuth(authStr)
|
decAuthConfig.Username, decAuthConfig.Password, err = cliconfig.DecodeAuth(authStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,7 +30,7 @@ func buildAuthConfigs() map[string]cliconfig.AuthConfig {
|
||||||
authConfigs := map[string]cliconfig.AuthConfig{}
|
authConfigs := map[string]cliconfig.AuthConfig{}
|
||||||
|
|
||||||
for _, registry := range []string{"testIndex", IndexServer} {
|
for _, registry := range []string{"testIndex", IndexServer} {
|
||||||
authConfigs[registry] = cliconfig.AuthConfig{
|
authConfigs[registry] = types.AuthConfig{
|
||||||
Username: "docker-user",
|
Username: "docker-user",
|
||||||
Password: "docker-pass",
|
Password: "docker-pass",
|
||||||
Email: "docker@docker.io",
|
Email: "docker@docker.io",
|
||||||
|
@ -78,24 +78,24 @@ func TestResolveAuthConfigIndexServer(t *testing.T) {
|
||||||
func TestResolveAuthConfigFullURL(t *testing.T) {
|
func TestResolveAuthConfigFullURL(t *testing.T) {
|
||||||
authConfigs := buildAuthConfigs()
|
authConfigs := buildAuthConfigs()
|
||||||
|
|
||||||
registryAuth := cliconfig.AuthConfig{
|
registryAuth := types.AuthConfig{
|
||||||
Username: "foo-user",
|
Username: "foo-user",
|
||||||
Password: "foo-pass",
|
Password: "foo-pass",
|
||||||
Email: "foo@example.com",
|
Email: "foo@example.com",
|
||||||
}
|
}
|
||||||
localAuth := cliconfig.AuthConfig{
|
localAuth := types.AuthConfig{
|
||||||
Username: "bar-user",
|
Username: "bar-user",
|
||||||
Password: "bar-pass",
|
Password: "bar-pass",
|
||||||
Email: "bar@example.com",
|
Email: "bar@example.com",
|
||||||
}
|
}
|
||||||
officialAuth := cliconfig.AuthConfig{
|
officialAuth := types.AuthConfig{
|
||||||
Username: "baz-user",
|
Username: "baz-user",
|
||||||
Password: "baz-pass",
|
Password: "baz-pass",
|
||||||
Email: "baz@example.com",
|
Email: "baz@example.com",
|
||||||
}
|
}
|
||||||
authConfigs[IndexServer] = officialAuth
|
authConfigs[IndexServer] = officialAuth
|
||||||
|
|
||||||
expectedAuths := map[string]cliconfig.AuthConfig{
|
expectedAuths := map[string]types.AuthConfig{
|
||||||
"registry.example.com": registryAuth,
|
"registry.example.com": registryAuth,
|
||||||
"localhost:8000": localAuth,
|
"localhost:8000": localAuth,
|
||||||
"registry.com": localAuth,
|
"registry.com": localAuth,
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/distribution/registry/client/transport"
|
"github.com/docker/distribution/registry/client/transport"
|
||||||
"github.com/docker/docker/cliconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -23,7 +22,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func spawnTestRegistrySession(t *testing.T) *Session {
|
func spawnTestRegistrySession(t *testing.T) *Session {
|
||||||
authConfig := &cliconfig.AuthConfig{}
|
authConfig := &types.AuthConfig{}
|
||||||
endpoint, err := NewEndpoint(makeIndex("/v1/"), nil, APIVersionUnknown)
|
endpoint, err := NewEndpoint(makeIndex("/v1/"), nil, APIVersionUnknown)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/distribution/registry/client/auth"
|
"github.com/docker/distribution/registry/client/auth"
|
||||||
"github.com/docker/docker/cliconfig"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Service is a registry service. It tracks configuration data such as a list
|
// Service is a registry service. It tracks configuration data such as a list
|
||||||
|
@ -28,7 +27,7 @@ func NewService(options *Options) *Service {
|
||||||
// Auth contacts the public registry with the provided credentials,
|
// Auth contacts the public registry with the provided credentials,
|
||||||
// and returns OK if authentication was successful.
|
// and returns OK if authentication was successful.
|
||||||
// It can be used to verify the validity of a client's credentials.
|
// It can be used to verify the validity of a client's credentials.
|
||||||
func (s *Service) Auth(authConfig *cliconfig.AuthConfig) (string, error) {
|
func (s *Service) Auth(authConfig *types.AuthConfig) (string, error) {
|
||||||
addr := authConfig.ServerAddress
|
addr := authConfig.ServerAddress
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
// Use the official registry address if not specified.
|
// Use the official registry address if not specified.
|
||||||
|
@ -72,7 +71,7 @@ func splitReposSearchTerm(reposName string) (string, string) {
|
||||||
|
|
||||||
// Search queries the public registry for images matching the specified
|
// Search queries the public registry for images matching the specified
|
||||||
// search terms, and returns the results.
|
// search terms, and returns the results.
|
||||||
func (s *Service) Search(term string, authConfig *cliconfig.AuthConfig, headers map[string][]string) (*SearchResults, error) {
|
func (s *Service) Search(term string, authConfig *types.AuthConfig, headers map[string][]string) (*SearchResults, error) {
|
||||||
if err := validateNoSchema(term); err != nil {
|
if err := validateNoSchema(term); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/cliconfig"
|
|
||||||
"github.com/docker/docker/pkg/httputils"
|
"github.com/docker/docker/pkg/httputils"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -39,13 +38,13 @@ type Session struct {
|
||||||
indexEndpoint *Endpoint
|
indexEndpoint *Endpoint
|
||||||
client *http.Client
|
client *http.Client
|
||||||
// TODO(tiborvass): remove authConfig
|
// TODO(tiborvass): remove authConfig
|
||||||
authConfig *cliconfig.AuthConfig
|
authConfig *types.AuthConfig
|
||||||
id string
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
type authTransport struct {
|
type authTransport struct {
|
||||||
http.RoundTripper
|
http.RoundTripper
|
||||||
*cliconfig.AuthConfig
|
*types.AuthConfig
|
||||||
|
|
||||||
alwaysSetBasicAuth bool
|
alwaysSetBasicAuth bool
|
||||||
token []string
|
token []string
|
||||||
|
@ -67,7 +66,7 @@ type authTransport struct {
|
||||||
// If the server sends a token without the client having requested it, it is ignored.
|
// 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.
|
// This RoundTripper also has a CancelRequest method important for correct timeout handling.
|
||||||
func AuthTransport(base http.RoundTripper, authConfig *cliconfig.AuthConfig, alwaysSetBasicAuth bool) http.RoundTripper {
|
func AuthTransport(base http.RoundTripper, authConfig *types.AuthConfig, alwaysSetBasicAuth bool) http.RoundTripper {
|
||||||
if base == nil {
|
if base == nil {
|
||||||
base = http.DefaultTransport
|
base = http.DefaultTransport
|
||||||
}
|
}
|
||||||
|
@ -162,7 +161,7 @@ func (tr *authTransport) CancelRequest(req *http.Request) {
|
||||||
|
|
||||||
// NewSession creates a new session
|
// NewSession creates a new session
|
||||||
// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
|
// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
|
||||||
func NewSession(client *http.Client, authConfig *cliconfig.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
|
func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
|
||||||
r = &Session{
|
r = &Session{
|
||||||
authConfig: authConfig,
|
authConfig: authConfig,
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -743,12 +742,12 @@ func (r *Session) SearchRepositories(term string) (*SearchResults, error) {
|
||||||
|
|
||||||
// GetAuthConfig returns the authentication settings for a session
|
// GetAuthConfig returns the authentication settings for a session
|
||||||
// TODO(tiborvass): remove this once registry client v2 is vendored
|
// TODO(tiborvass): remove this once registry client v2 is vendored
|
||||||
func (r *Session) GetAuthConfig(withPasswd bool) *cliconfig.AuthConfig {
|
func (r *Session) GetAuthConfig(withPasswd bool) *types.AuthConfig {
|
||||||
password := ""
|
password := ""
|
||||||
if withPasswd {
|
if withPasswd {
|
||||||
password = r.authConfig.Password
|
password = r.authConfig.Password
|
||||||
}
|
}
|
||||||
return &cliconfig.AuthConfig{
|
return &types.AuthConfig{
|
||||||
Username: r.authConfig.Username,
|
Username: r.authConfig.Username,
|
||||||
Password: password,
|
Password: password,
|
||||||
Email: r.authConfig.Email,
|
Email: r.authConfig.Email,
|
||||||
|
|
Loading…
Reference in a new issue