Skip to content

Commit e103df6

Browse files
authored
chore(attestations): store contract name and version in attestation and referrer API (#1679)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent c36f98f commit e103df6

File tree

13 files changed

+143
-76
lines changed

13 files changed

+143
-76
lines changed

app/cli/internal/action/attestation_init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
126126
Project: workflow.GetProject(),
127127
Team: workflow.GetTeam(),
128128
SchemaRevision: strconv.Itoa(int(contractVersion.GetRevision())),
129+
ContractName: workflow.ContractName,
129130
}
130131

131132
if opts.ProjectVersion != "" {

app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/attestation.v1.WorkflowMetadata.jsonschema.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/gen/jsonschema/attestation.v1.WorkflowMetadata.schema.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/service/workflow.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func bizWorkflowToPb(wf *biz.Workflow) *pb.WorkflowItem {
239239
Id: wf.ID.String(), Name: wf.Name, CreatedAt: timestamppb.New(*wf.CreatedAt),
240240
Project: wf.Project, Team: wf.Team, RunsCount: int32(wf.RunsCounter), Public: wf.Public,
241241
Description: wf.Description, ContractRevisionLatest: int32(wf.ContractRevisionLatest),
242+
ContractName: wf.ContractName,
242243
}
243244

244245
if wf.ContractID != uuid.Nil {

app/controlplane/pkg/biz/referrer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,12 @@ func extractReferrers(att *dsse.Envelope, repo ReferrerRepo) ([]*Referrer, error
280280
attestationReferrer.Annotations = predicate.GetAnnotations()
281281
attestationReferrer.Metadata = map[string]string{
282282
// workflow name, team and project
283-
"name": predicate.GetMetadata().Name,
284-
"team": predicate.GetMetadata().Team,
285-
"project": predicate.GetMetadata().Project,
286-
"organization": predicate.GetMetadata().Organization,
283+
"name": predicate.GetMetadata().Name,
284+
"team": predicate.GetMetadata().Team,
285+
"project": predicate.GetMetadata().Project,
286+
"organization": predicate.GetMetadata().Organization,
287+
"contractName": predicate.GetMetadata().ContractName,
288+
"contractVersion": predicate.GetMetadata().ContractVersion,
287289
}
288290

289291
// Create new referrers for each material

app/controlplane/pkg/biz/referrer_integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
243243
s.Equal(wantReferrerAtt.Kind, got.Kind)
244244
// It has metadata
245245
s.Equal(map[string]string{
246+
"contractName": "", "contractVersion": "",
246247
"name": "test-new-types",
247248
"project": "test",
248249
"team": "my-team",

app/controlplane/pkg/biz/referrer_test.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
109109
Kind: "ATTESTATION",
110110
Downloadable: true,
111111
Metadata: map[string]string{
112-
"name": "only-sbom",
113-
"organization": "",
114-
"team": "",
115-
"project": "foo",
112+
"contractName": "",
113+
"contractVersion": "",
114+
"name": "only-sbom",
115+
"organization": "",
116+
"team": "",
117+
"project": "foo",
116118
},
117119
Annotations: map[string]string{
118120
"branch": "stable",
@@ -158,10 +160,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
158160
},
159161
},
160162
Metadata: map[string]string{
161-
"name": "test",
162-
"organization": "",
163-
"team": "",
164-
"project": "bar",
163+
"contractName": "",
164+
"contractVersion": "",
165+
"name": "test",
166+
"organization": "",
167+
"team": "",
168+
"project": "bar",
165169
},
166170
Annotations: map[string]string{
167171
"version": "oss",
@@ -189,10 +193,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
189193
Kind: "ATTESTATION",
190194
Downloadable: true,
191195
Metadata: map[string]string{
192-
"name": "only-sbom",
193-
"organization": "",
194-
"team": "",
195-
"project": "foo",
196+
"contractName": "",
197+
"contractVersion": "",
198+
"name": "only-sbom",
199+
"organization": "",
200+
"team": "",
201+
"project": "foo",
196202
},
197203
Annotations: map[string]string{
198204
"branch": "stable",
@@ -248,10 +254,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
248254
Kind: "ATTESTATION",
249255
Downloadable: true,
250256
Metadata: map[string]string{
251-
"name": "test-new-types",
252-
"organization": "my-org",
253-
"team": "my-team",
254-
"project": "test",
257+
"contractName": "",
258+
"contractVersion": "",
259+
"name": "test-new-types",
260+
"organization": "my-org",
261+
"team": "my-team",
262+
"project": "test",
255263
},
256264
References: []*Referrer{
257265
{

pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go

Lines changed: 52 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/attestation/crafter/api/attestation/v1/crafting_state.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ message WorkflowMetadata {
230230
string workflow_id = 5 [(buf.validate.field).string.min_len = 1];
231231
string workflow_run_id = 6; // Not required since we might be doing a dry-run
232232
string schema_revision = 7 [(buf.validate.field).string.min_len = 1];
233+
// contract name (contract version is "schema_revision")
234+
string contract_name = 11 [(buf.validate.field).string.min_len = 1];
233235
// organization name
234236
string organization = 8 [(buf.validate.field).string.min_len = 1];
235237
}

0 commit comments

Comments
 (0)