support username/password in config.json file

pull/3/head
Brad Rydzewski 4 years ago
parent 2f159843c1
commit 4453e4fd8d

@ -3,6 +3,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- support for username/password in docker config.json
- support for multiple external environment providers
- support for calendar version environment variables
- drain response body to ensure connection re-use

@ -25,7 +25,9 @@ type (
// auth stores the registry authentication string.
auth struct {
Auth string `json:"auth"`
Auth string `json:"auth"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
}
)
@ -38,7 +40,10 @@ func Parse(r io.Reader) ([]*drone.Registry, error) {
}
var auths []*drone.Registry
for k, v := range c.Auths {
username, password := decode(v.Auth)
username, password := v.Username, v.Password
if v.Auth != "" {
username, password = decode(v.Auth)
}
auths = append(auths, &drone.Registry{
Address: hostname(k),
Username: username,

@ -75,6 +75,24 @@ func TestParseFile(t *testing.T) {
}
}
func TestParseUsernamePassword(t *testing.T) {
got, err := ParseString(sample2)
if err != nil {
t.Error(err)
return
}
want := []*drone.Registry{
{
Address: "index.docker.io",
Username: "octocat",
Password: "correct-horse-battery-staple",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf(diff)
}
}
func TestParseFileErr(t *testing.T) {
_, err := ParseFile("./testdata/x.json")
if _, ok := err.(*os.PathError); !ok {
@ -125,3 +143,12 @@ var sample = `{
}
}
}`
var sample2 = `{
"auths": {
"https://index.docker.io/v1/": {
"username": "octocat",
"password": "correct-horse-battery-staple"
}
}
}`

Loading…
Cancel
Save