Skip to content

Commit

Permalink
Merge pull request #748 from gkvijay/registry_token
Browse files Browse the repository at this point in the history
Added registry token support for docker registry
  • Loading branch information
fsouza authored Sep 15, 2018
2 parents a7b85d6 + b00e80c commit 20aafb6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type AuthConfiguration struct {
// see https://godoc.org/github.com/docker/docker/api/types#AuthConfig
// It can be used in place of password not in conjunction with it
IdentityToken string `json:"identitytoken,omitempty"`

// RegistryToken can be supplied with the registrytoken
RegistryToken string `json:"registrytoken,omitempty"`
}

// AuthConfigurations represents authentication options to use for the
Expand All @@ -50,6 +53,7 @@ type dockerConfig struct {
Auth string `json:"auth"`
Email string `json:"email"`
IdentityToken string `json:"identitytoken"`
RegistryToken string `json:"registrytoken"`
}

// NewAuthConfigurationsFromFile returns AuthConfigurations from a path containing JSON
Expand Down Expand Up @@ -162,6 +166,11 @@ func authConfigs(confs map[string]dockerConfig) (*AuthConfigurations, error) {
authConfig.IdentityToken = conf.IdentityToken
}

// if registrytoken provided then zero the password and set it
if conf.RegistryToken != "" {
authConfig.Password = ""
authConfig.RegistryToken = conf.RegistryToken
}
c.Configs[reg] = authConfig
}

Expand Down
21 changes: 21 additions & 0 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ func TestAuthConfigIdentityToken(t *testing.T) {
}
}

func TestAuthConfigRegistryToken(t *testing.T) {
t.Parallel()
auth := base64.StdEncoding.EncodeToString([]byte("someuser:"))
read := strings.NewReader(fmt.Sprintf(`{"auths":{"docker.io":{"auth":"%s","registrytoken":"sometoken"}}}`, auth))
ac, err := NewAuthConfigurations(read)
if err != nil {
t.Fatal(err)
}

c, ok := ac.Configs["docker.io"]
if !ok {
t.Error("NewAuthConfigurations: Expected Configs to contain docker.io")
}
if got, want := c.Username, "someuser"; got != want {
t.Errorf(`AuthConfigurations.Configs["docker.io"].Username: wrong result. Want %q. Got %q`, want, got)
}
if got, want := c.RegistryToken, "sometoken"; got != want {
t.Errorf(`AuthConfigurations.Configs["docker.io"].RegistryToken: wrong result. Want %q. Got %q`, want, got)
}
}

func TestAuthCheck(t *testing.T) {
t.Parallel()
fakeRT := &FakeRoundTripper{status: http.StatusOK}
Expand Down

0 comments on commit 20aafb6

Please sign in to comment.