Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default params in attestation invocation #449

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pkg/chains/formats/intotoite6/intotoite6.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,22 @@ func metadata(tr *v1beta1.TaskRun) *slsa.ProvenanceMetadata {
// which material the Task definition came from
func invocation(tr *v1beta1.TaskRun) slsa.ProvenanceInvocation {
i := slsa.ProvenanceInvocation{}
// get parameters
params := make(map[string]string)
for _, p := range tr.Spec.Params {
params[p.Name] = fmt.Sprintf("%v", p.Value)
}
// add params
params := make(map[string]v1beta1.ArrayOrString)

// get implicit parameters from defaults
if ts := tr.Status.TaskSpec; ts != nil {
for _, p := range ts.Params {
if p.Default != nil {
v := p.Default.StringVal
if v == "" {
v = fmt.Sprintf("%v", p.Default.ArrayVal)
}
params[p.Name] = v
params[p.Name] = *p.Default
}
}
}

// get explicit parameters
for _, p := range tr.Spec.Params {
params[p.Name] = p.Value
}

i.Parameters = params
return i
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/chains/formats/intotoite6/intotoite6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func TestCreatePayload1(t *testing.T) {
{URI: "git+https://git.test.com.git", Digest: slsa.DigestSet{"sha1": "abcd"}},
},
Invocation: slsa.ProvenanceInvocation{
Parameters: map[string]string{
"IMAGE": "{string test.io/test/image []}",
"CHAINS-GIT_COMMIT": "{string abcd []}",
"CHAINS-GIT_URL": "{string https://git.test.com []}",
"filename": "{string /bin/ls []}",
Parameters: map[string]v1beta1.ArrayOrString{
"IMAGE": {Type: "string", StringVal: "test.io/test/image"},
"CHAINS-GIT_COMMIT": {Type: "string", StringVal: "abcd"},
"CHAINS-GIT_URL": {Type: "string", StringVal: "https://git.test.com"},
"filename": {Type: "string", StringVal: "/bin/ls"},
},
},
Builder: slsa.ProvenanceBuilder{
Expand Down Expand Up @@ -134,7 +134,7 @@ func TestCreatePayload2(t *testing.T) {
ID: "test_builder-2",
},
Invocation: slsa.ProvenanceInvocation{
Parameters: map[string]string{},
Parameters: map[string]v1beta1.ArrayOrString{},
},
BuildType: "https://tekton.dev/attestations/chains@v2",
BuildConfig: BuildConfig{
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestMultipleSubjects(t *testing.T) {
ID: "test_builder-multiple",
},
Invocation: slsa.ProvenanceInvocation{
Parameters: map[string]string{},
Parameters: map[string]v1beta1.ArrayOrString{},
},
BuildConfig: BuildConfig{
Steps: []Step{
Expand Down
49 changes: 45 additions & 4 deletions pkg/chains/formats/intotoite6/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,58 @@ spec:
- name: my-array-param
value:
- "my"
- "array"`
- "array"
- name: my-empty-string-param
value: ""
- name: my-empty-array-param
value: []
status:
taskSpec:
params:
- name: my-param
default: ignored
- name: my-array-param
type: array
default:
- "also"
- "ignored"
- name: my-default-param
default: string-default-param
- name: my-default-array-param
type: array
default:
- "array"
- "default"
- "param"
- name: my-empty-string-param
default: "ignored"
- name: my-empty-array-param
type: array
default:
- "also"
- "ignored"
- name: my-default-empty-string-param
default: ""
- name: my-default-empty-array-param
type: array
default: []
`

var taskRun *v1beta1.TaskRun
if err := yaml.Unmarshal([]byte(taskrun), &taskRun); err != nil {
t.Fatal(err)
}

expected := slsa.ProvenanceInvocation{
Parameters: map[string]string{
"my-param": "{string string-param []}",
"my-array-param": "{array [my array]}",
Parameters: map[string]v1beta1.ArrayOrString{
"my-param": {Type: "string", StringVal: "string-param"},
"my-array-param": {Type: "array", ArrayVal: []string{"my", "array"}},
"my-default-param": {Type: "string", StringVal: "string-default-param"},
"my-default-array-param": {Type: "array", ArrayVal: []string{"array", "default", "param"}},
"my-empty-string-param": {Type: "string", StringVal: ""},
"my-empty-array-param": {Type: "array", ArrayVal: []string{}},
"my-default-empty-string-param": {Type: "string", StringVal: ""},
"my-default-empty-array-param": {Type: "array", ArrayVal: []string{}},
},
}

Expand Down