diff options
author | Till! <till@users.noreply.github.com> | 2021-11-27 19:05:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-27 19:05:56 +0100 |
commit | 5bdb9ed0fd203c2f50e191bca90831b2a8f96cbc (patch) | |
tree | 595e2042c2a0c2b03e7caecc7a3d8031e63122a3 /pkg/model | |
parent | Add more steps context support (#887) (diff) | |
download | forgejo-act-5bdb9ed0fd203c2f50e191bca90831b2a8f96cbc.tar.xz forgejo-act-5bdb9ed0fd203c2f50e191bca90831b2a8f96cbc.zip |
container credentials (#868)
* Chore: add a snapshot target
* Update: support credentials for private containers
Resolves: #788
* fix: rework container credentials
Signed-off-by: hackercat <me@hackerc.at>
* fix: check if Credentials are not nil
* fix: return on missing credentials key
Co-authored-by: hackercat <me@hackerc.at>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'pkg/model')
-rw-r--r-- | pkg/model/workflow.go | 19 | ||||
-rw-r--r-- | pkg/model/workflow_test.go | 30 |
2 files changed, 40 insertions, 9 deletions
diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index 5b664b5..eb6e486 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -295,15 +295,16 @@ func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool { // ContainerSpec is the specification of the container to use for the job type ContainerSpec struct { - Image string `yaml:"image"` - Env map[string]string `yaml:"env"` - Ports []string `yaml:"ports"` - Volumes []string `yaml:"volumes"` - Options string `yaml:"options"` - Entrypoint string - Args string - Name string - Reuse bool + Image string `yaml:"image"` + Env map[string]string `yaml:"env"` + Ports []string `yaml:"ports"` + Volumes []string `yaml:"volumes"` + Options string `yaml:"options"` + Credentials map[string]string `yaml:"credentials"` + Entrypoint string + Args string + Name string + Reuse bool } // Step is the structure of one step in a job diff --git a/pkg/model/workflow_test.go b/pkg/model/workflow_test.go index 914e89c..86b4380 100644 --- a/pkg/model/workflow_test.go +++ b/pkg/model/workflow_test.go @@ -99,6 +99,36 @@ jobs: assert.Contains(t, workflow.Jobs["test2"].Container().Env["foo"], "bar") } +func TestReadWorkflow_ObjectContainer(t *testing.T) { + yaml := ` +name: local-action-docker-url + +jobs: + test: + container: + image: r.example.org/something:latest + credentials: + username: registry-username + password: registry-password + env: + HOME: /home/user + runs-on: ubuntu-latest + steps: + - uses: ./actions/docker-url +` + + workflow, err := ReadWorkflow(strings.NewReader(yaml)) + assert.NoError(t, err, "read workflow should succeed") + assert.Len(t, workflow.Jobs, 1) + + container := workflow.GetJob("test").Container() + + assert.Contains(t, container.Image, "r.example.org/something:latest") + assert.Contains(t, container.Env["HOME"], "/home/user") + assert.Contains(t, container.Credentials["username"], "registry-username") + assert.Contains(t, container.Credentials["password"], "registry-password") +} + func TestReadWorkflow_StepsTypes(t *testing.T) { yaml := ` name: invalid step definition |