From c5d240f0d0f5b92fbeaaea5e7a7ee86604e0cbe6 Mon Sep 17 00:00:00 2001 From: "alessandro.pinna" Date: Tue, 1 Feb 2022 14:50:14 +0100 Subject: [PATCH] runconfig: fix missing generation of dockerregistryauth auth field --- internal/runconfig/runconfig.go | 3 + internal/runconfig/runconfig_test.go | 198 +++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) diff --git a/internal/runconfig/runconfig.go b/internal/runconfig/runconfig.go index 86440c4..442e7c4 100644 --- a/internal/runconfig/runconfig.go +++ b/internal/runconfig/runconfig.go @@ -237,6 +237,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string Type: rstypes.DockerRegistryAuthType(auth.Type), Username: genValue(auth.Username, variables), Password: genValue(auth.Password, variables), + Auth: auth.Auth, } } } @@ -248,6 +249,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string Type: rstypes.DockerRegistryAuthType(auth.Type), Username: genValue(auth.Username, variables), Password: genValue(auth.Password, variables), + Auth: auth.Auth, } } } @@ -259,6 +261,7 @@ func GenRunConfigTasks(uuid util.UUIDGenerator, c *config.Config, runName string Type: rstypes.DockerRegistryAuthType(auth.Type), Username: genValue(auth.Username, variables), Password: genValue(auth.Password, variables), + Auth: auth.Auth, } } } diff --git a/internal/runconfig/runconfig_test.go b/internal/runconfig/runconfig_test.go index b54a320..d49e2dd 100644 --- a/internal/runconfig/runconfig_test.go +++ b/internal/runconfig/runconfig_test.go @@ -1093,6 +1093,204 @@ func TestGenRunConfig(t *testing.T) { }, }, }, + { + name: "test runconfig generation encodedauth global", + in: &config.Config{ + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWU6cGFzc3dvcmQ=", + }, + }, + Runs: []*config.Run{ + &config.Run{ + Name: "run01", + Tasks: []*config.Task{ + &config.Task{ + Name: "task01", + Runtime: &config.Runtime{ + Type: "pod", + Arch: "", + Containers: []*config.Container{ + &config.Container{ + Image: "image01", + }, + }, + }, + + Depends: []*config.Depend{}, + WorkingDir: "", + Shell: "", + User: "", + }, + }, + }, + }, + }, + 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: "dXNlcm5hbWU6cGFzc3dvcmQ=", + }, + }, + Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"), + Containers: []*rstypes.Container{ + { + Image: "image01", + Volumes: []rstypes.Volume{}, + Environment: map[string]string{}, + }, + }, + }, + Environment: map[string]string{}, + Skip: false, + Steps: rstypes.Steps{}, + Shell: "/bin/sh -e", + }, + }, + }, + { + name: "test global encodedauth override by run auth", + in: &config.Config{ + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWU6cGFzc3dvcmQy", + }, + }, + Runs: []*config.Run{ + &config.Run{ + Name: "run01", + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWUxOnBhc3N3b3JkMQ==", + }, + }, + Tasks: []*config.Task{ + &config.Task{ + Name: "task01", + Runtime: &config.Runtime{ + Type: "pod", + Arch: "", + Containers: []*config.Container{ + &config.Container{ + Image: "image01", + }, + }, + }, + + Depends: []*config.Depend{}, + WorkingDir: "", + Shell: "", + User: "", + }, + }, + }, + }, + }, + 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: "dXNlcm5hbWUxOnBhc3N3b3JkMQ==", + }, + }, + Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"), + Containers: []*rstypes.Container{ + { + Image: "image01", + Volumes: []rstypes.Volume{}, + Environment: map[string]string{}, + }, + }, + }, + Environment: map[string]string{}, + Skip: false, + Steps: rstypes.Steps{}, + Shell: "/bin/sh -e", + }, + }, + }, + { + name: "test global run encodedauth override by task auth", + in: &config.Config{ + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWU6cGFzc3dvcmQy", + }, + }, + Runs: []*config.Run{ + &config.Run{ + Name: "run01", + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWUxOnBhc3N3b3JkMQ==", + }, + }, + Tasks: []*config.Task{ + &config.Task{ + Name: "task01", + DockerRegistriesAuth: map[string]*config.DockerRegistryAuth{ + "index.docker.io": { + Type: config.DockerRegistryAuthTypeEncodedAuth, + Auth: "dXNlcm5hbWUyOnBhc3N3b3JkMg==", + }, + }, + Runtime: &config.Runtime{ + Type: "pod", + Arch: "", + Containers: []*config.Container{ + &config.Container{ + Image: "image01", + }, + }, + }, + + Depends: []*config.Depend{}, + WorkingDir: "", + Shell: "", + User: "", + }, + }, + }, + }, + }, + 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: "dXNlcm5hbWUyOnBhc3N3b3JkMg==", + }, + }, + Runtime: &rstypes.Runtime{Type: rstypes.RuntimeType("pod"), + Containers: []*rstypes.Container{ + { + Image: "image01", + Volumes: []rstypes.Volume{}, + Environment: map[string]string{}, + }, + }, + }, + Environment: map[string]string{}, + Skip: false, + Steps: rstypes.Steps{}, + Shell: "/bin/sh -e", + }, + }, + }, } for _, tt := range tests {