mirror of https://github.com/k3s-io/k3s
Merge pull request #9058 from deads2k/serialize-with-auth
serialize dockercfg with matching auth fieldpull/6/head
commit
988a413acf
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue