Skip to content

Commit

Permalink
chore(attestations): store contract name and version in attestation a…
Browse files Browse the repository at this point in the history
…nd referrer API (chainloop-dev#1679)

Signed-off-by: Jose I. Paris <[email protected]>
  • Loading branch information
jiparis authored Dec 18, 2024
1 parent c36f98f commit e103df6
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 76 deletions.
1 change: 1 addition & 0 deletions app/cli/internal/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
Project: workflow.GetProject(),
Team: workflow.GetTeam(),
SchemaRevision: strconv.Itoa(int(contractVersion.GetRevision())),
ContractName: workflow.ContractName,
}

if opts.ProjectVersion != "" {
Expand Down
16 changes: 16 additions & 0 deletions app/controlplane/api/gen/frontend/attestation/v1/crafting_state.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/controlplane/internal/service/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func bizWorkflowToPb(wf *biz.Workflow) *pb.WorkflowItem {
Id: wf.ID.String(), Name: wf.Name, CreatedAt: timestamppb.New(*wf.CreatedAt),
Project: wf.Project, Team: wf.Team, RunsCount: int32(wf.RunsCounter), Public: wf.Public,
Description: wf.Description, ContractRevisionLatest: int32(wf.ContractRevisionLatest),
ContractName: wf.ContractName,
}

if wf.ContractID != uuid.Nil {
Expand Down
10 changes: 6 additions & 4 deletions app/controlplane/pkg/biz/referrer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ func extractReferrers(att *dsse.Envelope, repo ReferrerRepo) ([]*Referrer, error
attestationReferrer.Annotations = predicate.GetAnnotations()
attestationReferrer.Metadata = map[string]string{
// workflow name, team and project
"name": predicate.GetMetadata().Name,
"team": predicate.GetMetadata().Team,
"project": predicate.GetMetadata().Project,
"organization": predicate.GetMetadata().Organization,
"name": predicate.GetMetadata().Name,
"team": predicate.GetMetadata().Team,
"project": predicate.GetMetadata().Project,
"organization": predicate.GetMetadata().Organization,
"contractName": predicate.GetMetadata().ContractName,
"contractVersion": predicate.GetMetadata().ContractVersion,
}

// Create new referrers for each material
Expand Down
1 change: 1 addition & 0 deletions app/controlplane/pkg/biz/referrer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
s.Equal(wantReferrerAtt.Kind, got.Kind)
// It has metadata
s.Equal(map[string]string{
"contractName": "", "contractVersion": "",
"name": "test-new-types",
"project": "test",
"team": "my-team",
Expand Down
40 changes: 24 additions & 16 deletions app/controlplane/pkg/biz/referrer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
"contractName": "",
"contractVersion": "",
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
},
Annotations: map[string]string{
"branch": "stable",
Expand Down Expand Up @@ -158,10 +160,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
},
},
Metadata: map[string]string{
"name": "test",
"organization": "",
"team": "",
"project": "bar",
"contractName": "",
"contractVersion": "",
"name": "test",
"organization": "",
"team": "",
"project": "bar",
},
Annotations: map[string]string{
"version": "oss",
Expand Down Expand Up @@ -189,10 +193,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
"contractName": "",
"contractVersion": "",
"name": "only-sbom",
"organization": "",
"team": "",
"project": "foo",
},
Annotations: map[string]string{
"branch": "stable",
Expand Down Expand Up @@ -248,10 +254,12 @@ func (s *referrerTestSuite) TestExtractReferrers() {
Kind: "ATTESTATION",
Downloadable: true,
Metadata: map[string]string{
"name": "test-new-types",
"organization": "my-org",
"team": "my-team",
"project": "test",
"contractName": "",
"contractVersion": "",
"name": "test-new-types",
"organization": "my-org",
"team": "my-team",
"project": "test",
},
References: []*Referrer{
{
Expand Down
92 changes: 52 additions & 40 deletions pkg/attestation/crafter/api/attestation/v1/crafting_state.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ message WorkflowMetadata {
string workflow_id = 5 [(buf.validate.field).string.min_len = 1];
string workflow_run_id = 6; // Not required since we might be doing a dry-run
string schema_revision = 7 [(buf.validate.field).string.min_len = 1];
// contract name (contract version is "schema_revision")
string contract_name = 11 [(buf.validate.field).string.min_len = 1];
// organization name
string organization = 8 [(buf.validate.field).string.min_len = 1];
}
Expand Down
Loading

0 comments on commit e103df6

Please sign in to comment.