mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
reduce scope of DockerConfigEntryWithAuth
This commit is contained in:
parent
5458f05679
commit
72c0709f18
@ -147,9 +147,9 @@ func readDockerConfigFileFromBytes(contents []byte) (cfg DockerConfig, err error
|
||||
return
|
||||
}
|
||||
|
||||
// DockerConfigEntryWithAuth is used solely for deserializing the Auth field
|
||||
// dockerConfigEntryWithAuth is used solely for deserializing the Auth field
|
||||
// into a dockerConfigEntry during JSON deserialization.
|
||||
type DockerConfigEntryWithAuth struct {
|
||||
type dockerConfigEntryWithAuth struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
@ -157,7 +157,7 @@ type DockerConfigEntryWithAuth struct {
|
||||
}
|
||||
|
||||
func (ident *DockerConfigEntry) UnmarshalJSON(data []byte) error {
|
||||
var tmp DockerConfigEntryWithAuth
|
||||
var tmp dockerConfigEntryWithAuth
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -195,8 +195,8 @@ func decodeDockerConfigFieldAuth(field string) (username, password string, err e
|
||||
return
|
||||
}
|
||||
|
||||
func (ident DockerConfigEntry) ConvertToDockerConfigCompatible() DockerConfigEntryWithAuth {
|
||||
ret := DockerConfigEntryWithAuth{ident.Username, ident.Password, ident.Email, ""}
|
||||
func (ident DockerConfigEntry) ConvertToDockerConfigCompatible() dockerConfigEntryWithAuth {
|
||||
ret := dockerConfigEntryWithAuth{ident.Username, ident.Password, ident.Email, ""}
|
||||
ret.Auth = encodeDockerConfigFieldAuth(ident.Username, ident.Password)
|
||||
|
||||
return ret
|
||||
|
@ -239,12 +239,8 @@ func TestPullWithNoSecrets(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPullWithSecrets(t *testing.T) {
|
||||
dockercfgAuth := credentialprovider.DockerConfigEntry{
|
||||
Username: "passed-user",
|
||||
Password: "passed-password",
|
||||
Email: "passed-email",
|
||||
}.ConvertToDockerConfigCompatible()
|
||||
dockerCfg := map[string]credentialprovider.DockerConfigEntryWithAuth{"index.docker.io/v1/": dockercfgAuth}
|
||||
// auth value is equivalent to: "username":"passed-user","password":"passed-password"
|
||||
dockerCfg := map[string]map[string]string{"index.docker.io/v1/": {"email": "passed-email", "auth": "cGFzc2VkLXVzZXI6cGFzc2VkLXBhc3N3b3Jk"}}
|
||||
dockercfgContent, err := json.Marshal(dockerCfg)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user