mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #9058 from deads2k/serialize-with-auth
serialize dockercfg with matching auth field
This commit is contained in:
commit
988a413acf
@ -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
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user