Commit 988a413a authored by Quinton Hoole's avatar Quinton Hoole

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

serialize dockercfg with matching auth field
parents 21db71db ac2c43fc
...@@ -175,6 +175,13 @@ func (ident *DockerConfigEntry) UnmarshalJSON(data []byte) error { ...@@ -175,6 +175,13 @@ func (ident *DockerConfigEntry) UnmarshalJSON(data []byte) error {
return err 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 // decodeDockerConfigFieldAuth deserializes the "auth" field from dockercfg into a
// username and a password. The format of the auth field is base64(<username>:<password>). // username and a password. The format of the auth field is base64(<username>:<password>).
func decodeDockerConfigFieldAuth(field string) (username, password string, err error) { func decodeDockerConfigFieldAuth(field string) (username, password string, err error) {
...@@ -195,13 +202,6 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e ...@@ -195,13 +202,6 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e
return 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 { func encodeDockerConfigFieldAuth(username, password string) string {
fieldValue := username + ":" + password fieldValue := username + ":" + password
......
...@@ -184,9 +184,7 @@ func TestDockerConfigEntryJSONCompatibleEncode(t *testing.T) { ...@@ -184,9 +184,7 @@ func TestDockerConfigEntryJSONCompatibleEncode(t *testing.T) {
} }
for i, tt := range tests { for i, tt := range tests {
toEncode := tt.input.ConvertToDockerConfigCompatible() actual, err := json.Marshal(tt.input)
actual, err := json.Marshal(toEncode)
if err != nil { if err != nil {
t.Errorf("case %d: unexpected error: %v", i, err) t.Errorf("case %d: unexpected error: %v", i, err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment