Skip to content

Commit

Permalink
Refactor arguments to parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Franssen <[email protected]>
  • Loading branch information
marcofranssen committed Nov 10, 2021
1 parent 6295f44 commit 764a86f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/github/provenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ func assertInvocation(assert *assert.Assertions, recipe intoto.Invocation) {
assert.Equal(0, recipe.DefinedInMaterial)
assert.Equal("", recipe.ConfigSource.EntryPoint)
assert.Nil(recipe.Environment)
assert.Nil(recipe.Arguments)
assert.Nil(recipe.Parameters)
}

func assertMetadata(assert *assert.Assertions, meta intoto.Metadata, gh github.Context, repoURL string) {
bft, err := time.Parse(time.RFC3339, meta.BuildFinishedOn)
assert.NoError(err)
assert.WithinDuration(time.Now().UTC(), bft, 1200*time.Millisecond)
assert.Equal(fmt.Sprintf("%s/%s/%s", repoURL, "actions/runs", gh.RunID), meta.BuildInvocationID)
assert.Equal(true, meta.Completeness.Arguments)
assert.Equal(true, meta.Completeness.Parameters)
assert.Equal(false, meta.Completeness.Environment)
assert.Equal(false, meta.Completeness.Materials)
assert.Equal(false, meta.Reproducible)
Expand Down
10 changes: 5 additions & 5 deletions lib/intoto/intoto.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func WithMetadata(buildInvocationID string) StatementOption {
return func(s *Statement) {
s.Predicate.Metadata = Metadata{
Completeness: Completeness{
Arguments: true,
Parameters: true,
Environment: false,
Materials: false,
},
Expand All @@ -69,7 +69,7 @@ func WithMetadata(buildInvocationID string) StatementOption {
}

// WithInvocation sets the Predicate Invocation and Materials
func WithInvocation(buildType, entryPoint string, environment json.RawMessage, arguments json.RawMessage, materials []Item) StatementOption {
func WithInvocation(buildType, entryPoint string, environment json.RawMessage, parameters json.RawMessage, materials []Item) StatementOption {
return func(s *Statement) {
s.Predicate.BuildType = buildType
s.Predicate.Invocation = Invocation{
Expand All @@ -78,7 +78,7 @@ func WithInvocation(buildType, entryPoint string, environment json.RawMessage, a
URI: materials[0].URI,
Digest: materials[0].Digest,
},
Arguments: arguments,
Parameters: parameters,
// Subject to change and simplify https://github.com/slsa-framework/slsa/issues/178
// Index in materials containing the recipe steps that are not implied by recipe.type. For example, if the recipe type were "make", then this would point to the source containing the Makefile, not the make program itself.
// Omit this field (or use null) if the recipe doesn't come from a material.
Expand Down Expand Up @@ -142,7 +142,7 @@ type Metadata struct {
type Invocation struct {
DefinedInMaterial int `json:"definedInMaterial"`
ConfigSource ConfigSource `json:"configSource"`
Arguments json.RawMessage `json:"arguments"`
Parameters json.RawMessage `json:"parameters"`
Environment json.RawMessage `json:"environment"`
}

Expand All @@ -156,7 +156,7 @@ type ConfigSource struct {

// Completeness Indicates that the builder claims certain fields in this message to be complete.
type Completeness struct {
Arguments bool `json:"arguments"`
Parameters bool `json:"parameters"`
Environment bool `json:"environment"`
Materials bool `json:"materials"`
}
Expand Down
15 changes: 8 additions & 7 deletions lib/intoto/intoto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestSLSAProvenanceStatement(t *testing.T) {
bft, err := time.Parse(time.RFC3339, m.BuildFinishedOn)
assert.NoError(err)
assert.WithinDuration(time.Now().UTC(), bft, 1200*time.Millisecond)
assert.Equal(Completeness{Arguments: true, Environment: false, Materials: false}, stmt.Predicate.Metadata.Completeness)
assert.Equal(Completeness{Parameters: true, Environment: false, Materials: false}, stmt.Predicate.Metadata.Completeness)
assert.False(m.Reproducible)

provenanceActionMaterial := []Item{
Expand All @@ -72,18 +72,18 @@ func TestSLSAProvenanceStatement(t *testing.T) {
provenanceActionMaterial,
),
)
assertStatement(assert, stmt, builderID, buildType, provenanceActionMaterial)
assertStatement(assert, stmt, builderID, buildType, provenanceActionMaterial, nil)
}

func assertStatement(assert *assert.Assertions, stmt *Statement, builderID, buildType string, material []Item) {
func assertStatement(assert *assert.Assertions, stmt *Statement, builderID, buildType string, material []Item, parameters json.RawMessage) {
i := stmt.Predicate.Invocation
assert.Equal(SlsaPredicateType, stmt.PredicateType)
assert.Equal(StatementType, stmt.Type)
assert.Len(stmt.Subject, 1)
assert.Equal(builderID, stmt.Predicate.Builder.ID)
assert.Equal(buildType, stmt.Predicate.BuildType)
assertConfigSource(assert, i.ConfigSource, stmt.Predicate.Materials)
assert.Nil(i.Arguments)
assert.Equal(parameters, i.Parameters)
assert.Equal(0, i.DefinedInMaterial)
assert.Equal(material, stmt.Predicate.Materials)
}
Expand All @@ -107,6 +107,7 @@ func TestSLSAProvenanceStatementJSON(t *testing.T) {
}
}
]`
parametersJSON := `{ "inputs": { "skip_integration": true } }`
var material []Item
err := json.Unmarshal([]byte(materialJSON), &material)
assert.NoError(err)
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestSLSAProvenanceStatementJSON(t *testing.T) {
"sha1": "a3bc1c27230caa1cc3c27961f7e9cab43cd208dc"
}
},
"parameters": null,
"parameters": %s,
"environment": null
},
"buildConfig": null,
Expand All @@ -152,10 +153,10 @@ func TestSLSAProvenanceStatementJSON(t *testing.T) {
"materials": %s
}
}
`, builderID, buildType, materialJSON)
`, builderID, buildType, parametersJSON, materialJSON)

var stmt Statement
err = json.Unmarshal([]byte(jsonStatement), &stmt)
assert.NoError(err)
assertStatement(assert, &stmt, builderID, buildType, material)
assertStatement(assert, &stmt, builderID, buildType, material, []byte(parametersJSON))
}

0 comments on commit 764a86f

Please sign in to comment.