Skip to content

Commit

Permalink
Merge pull request #59 from Senetas/credentials
Browse files Browse the repository at this point in the history
Allow using credentials stores
  • Loading branch information
triarius authored Dec 13, 2018
2 parents b8925ec + 34a91e0 commit 916f6ca
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 295 deletions.
14 changes: 8 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@

[[constraint]]
name = "github.com/docker/cli"
version = "18.6.0-ce-rc1"
version = "v18.09.0"

[[constraint]]
branch = "master"
name = "github.com/docker/distribution"

[[constraint]]
branch = "master"
name = "github.com/docker/docker-credential-helpers"

[[constraint]]
name = "github.com/davecgh/go-spew"
version = "1.1.0"
Expand Down
46 changes: 26 additions & 20 deletions registry/auth/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package auth
import (
"net/http"

"github.com/davecgh/go-spew/spew"
"github.com/docker/cli/cli/config"
"github.com/docker/docker/api/types"
dregistry "github.com/docker/docker/registry"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)

// Credentials represents a username password pair
Expand All @@ -30,22 +30,17 @@ type Credentials interface {
}

type credentials struct {
username string
password string
types.AuthConfig
}

// NewCreds creates a struct that satisfies Credentials from
// a username and password (typically entered at the command like)
// NewCreds creates a new Credentials with a username and password
func NewCreds(username, password string) Credentials {
return &credentials{username: username, password: password}
}

func (c *credentials) SetAuth(req *http.Request) *http.Request {
req.SetBasicAuth(c.username, c.password)
q := req.URL.Query()
q.Set("account", c.username)
req.URL.RawQuery = q.Encode()
return req
return &credentials{
types.AuthConfig{
Username: username,
Password: password,
},
}
}

// NewDefaultCreds creates a credentials struct from the credentials in
Expand All @@ -58,13 +53,24 @@ func NewDefaultCreds(repoInfo *dregistry.RepositoryInfo) (creds Credentials, err
return
}

authConfig := dregistry.ResolveAuthConfig(confFile.AuthConfigs, repoInfo.Index)
serverAddress := dregistry.IndexServer
store := confFile.GetCredentialsStore(serverAddress)

log.Debug().Msgf("%s", spew.Sdump(authConfig))

creds = &credentials{username: authConfig.Username, password: authConfig.Password}
authConfig, err := store.Get(serverAddress)
if err != nil {
err = errors.WithStack(err)
return
}

log.Debug().Msgf("username = %s, password = %s", authConfig.Username, authConfig.Password)
creds = NewCreds(authConfig.Username, authConfig.Password)

return
}

func (c *credentials) SetAuth(req *http.Request) *http.Request {
req.SetBasicAuth(c.Username, c.Password)
q := req.URL.Query()
q.Set("account", c.Username)
req.URL.RawQuery = q.Encode()
return req
}
4 changes: 2 additions & 2 deletions vendor/github.com/docker/cli/cli/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/docker/cli/opts/envfile.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions vendor/github.com/docker/cli/opts/file.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 25 additions & 40 deletions vendor/github.com/docker/cli/opts/opts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/docker/cli/opts/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions vendor/github.com/docker/cli/opts/port.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 916f6ca

Please sign in to comment.