Merge pull request #296 from alessandro-sorint/docker-auth

config: add ability to take the docker registry encoded auth from a variable
This commit is contained in:
Simone Gotti 2022-03-01 15:32:04 +01:00 committed by GitHub
commit 6b286d774d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 11 deletions

View File

@ -77,8 +77,8 @@ type DockerRegistryAuth struct {
Username Value `json:"username"` Username Value `json:"username"`
Password Value `json:"password"` Password Value `json:"password"`
// encoded auth string // encoded auth
Auth string `json:"auth"` Auth Value `json:"auth"`
// future auths like aws ecr auth // future auths like aws ecr auth
} }

View File

@ -237,7 +237,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string
Type: rstypes.DockerRegistryAuthType(auth.Type), Type: rstypes.DockerRegistryAuthType(auth.Type),
Username: genValue(auth.Username, variables), Username: genValue(auth.Username, variables),
Password: genValue(auth.Password, variables), Password: genValue(auth.Password, variables),
Auth: auth.Auth, Auth: genValue(auth.Auth, variables),
} }
} }
} }
@ -249,7 +249,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string
Type: rstypes.DockerRegistryAuthType(auth.Type), Type: rstypes.DockerRegistryAuthType(auth.Type),
Username: genValue(auth.Username, variables), Username: genValue(auth.Username, variables),
Password: genValue(auth.Password, variables), Password: genValue(auth.Password, variables),
Auth: auth.Auth, Auth: genValue(auth.Auth, variables),
} }
} }
} }
@ -261,7 +261,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string
Type: rstypes.DockerRegistryAuthType(auth.Type), Type: rstypes.DockerRegistryAuthType(auth.Type),
Username: genValue(auth.Username, variables), Username: genValue(auth.Username, variables),
Password: genValue(auth.Password, variables), Password: genValue(auth.Password, variables),
Auth: auth.Auth, Auth: genValue(auth.Auth, variables),
} }
} }
} }

View File

@ -1099,7 +1099,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWU6cGFzc3dvcmQ=", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWU6cGFzc3dvcmQ="},
}, },
}, },
Runs: []*config.Run{ Runs: []*config.Run{
@ -1159,7 +1159,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWU6cGFzc3dvcmQy", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWU6cGFzc3dvcmQy"},
}, },
}, },
Runs: []*config.Run{ Runs: []*config.Run{
@ -1168,7 +1168,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWUxOnBhc3N3b3JkMQ==", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWUxOnBhc3N3b3JkMQ=="},
}, },
}, },
Tasks: []*config.Task{ Tasks: []*config.Task{
@ -1225,7 +1225,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWU6cGFzc3dvcmQy", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWU6cGFzc3dvcmQy"},
}, },
}, },
Runs: []*config.Run{ Runs: []*config.Run{
@ -1234,7 +1234,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWUxOnBhc3N3b3JkMQ==", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWUxOnBhc3N3b3JkMQ=="},
}, },
}, },
Tasks: []*config.Task{ Tasks: []*config.Task{
@ -1243,7 +1243,7 @@ func TestGenRunConfig(t *testing.T) {
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": { "index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth, Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: "dXNlcm5hbWUyOnBhc3N3b3JkMg==", Auth: config.Value{Type: config.ValueTypeString, Value: "dXNlcm5hbWUyOnBhc3N3b3JkMg=="},
}, },
}, },
Runtime: &config.Runtime{ Runtime: &config.Runtime{
@ -1291,6 +1291,73 @@ func TestGenRunConfig(t *testing.T) {
}, },
}, },
}, },
{
name: "test runconfig generation with encoded value type",
in: &config.Config{
Runs: []*config.Run{
&config.Run{
Name: "run01",
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: config.Value{Type: config.ValueTypeString, Value: "yourregistryusername:password2"},
},
},
Tasks: []*config.Task{
&config.Task{
Name: "task01",
DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{
"index.docker.io": {
Type: config.DockerRegistryAuthTypeEncodedAuth,
Auth: config.Value{Type: config.ValueTypeFromVariable, Value: "auth"},
},
},
Runtime: &config.Runtime{
Type: "pod",
Containers: []*config.Container{
&config.Container{
Image: "image01",
User: "",
},
},
},
Depends: []*config.Depend{},
IgnoreFailure: false,
Approval: false,
},
},
},
},
},
variables: map[string]string{
"auth": "eW91cnJlZ2lzdHJ5dXNlcm5hbWU6cGFzc3dvcmQy",
},
out: map[string]*rstypes.RunConfigTask{
uuid.New("task01").String(): &rstypes.RunConfigTask{
ID: uuid.New("task01").String(),
Name: "task01", Depends: map[string]*rstypes.RunConfigTaskDepend{},
DockerRegistriesAuth: map[string]rstypes.DockerRegistryAuth{
"index.docker.io": {
Type: rstypes.DockerRegistryAuthTypeEncodedAuth,
Auth: "eW91cnJlZ2lzdHJ5dXNlcm5hbWU6cGFzc3dvcmQy",
},
},
Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"),
Containers: []*rstypes.Container{
{
Image: "image01",
Environment: map[string]string{},
Volumes: []rstypes.Volume{},
},
},
},
Shell: "/bin/sh -e",
Environment: map[string]string{},
Steps: rstypes.Steps{},
Skip: false,
},
},
},
} }
for _, tt := range tests { for _, tt := range tests {