Merge pull request #9058 from deads2k/serialize-with-auth

serialize dockercfg with matching auth field
pull/6/head
Quinton Hoole 2015-06-05 11:26:14 -07:00
commit 988a413acf
2 changed files with 8 additions and 10 deletions

View File

@ -175,6 +175,13 @@ func (ident *DockerConfigEntry) UnmarshalJSON(data []byte) error {
return err
}
func (ident DockerConfigEntry) MarshalJSON() ([]byte, error) {
toEncode := dockerConfigEntryWithAuth{ident.Username, ident.Password, ident.Email, ""}
toEncode.Auth = encodeDockerConfigFieldAuth(ident.Username, ident.Password)
return json.Marshal(toEncode)
}
// decodeDockerConfigFieldAuth deserializes the "auth" field from dockercfg into a
// username and a password. The format of the auth field is base64(<username>:<password>).
func decodeDockerConfigFieldAuth(field string) (username, password string, err error) {
@ -195,13 +202,6 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e
return
}
func (ident DockerConfigEntry) ConvertToDockerConfigCompatible() dockerConfigEntryWithAuth {
ret := dockerConfigEntryWithAuth{ident.Username, ident.Password, ident.Email, ""}
ret.Auth = encodeDockerConfigFieldAuth(ident.Username, ident.Password)
return ret
}
func encodeDockerConfigFieldAuth(username, password string) string {
fieldValue := username + ":" + password

View File

@ -184,9 +184,7 @@ func TestDockerConfigEntryJSONCompatibleEncode(t *testing.T) {
}
for i, tt := range tests {
toEncode := tt.input.ConvertToDockerConfigCompatible()
actual, err := json.Marshal(toEncode)
actual, err := json.Marshal(tt.input)
if err != nil {
t.Errorf("case %d: unexpected error: %v", i, err)
}