Skip to content

Commit bbb8cab

Browse files
authored
fix(contracts): Store and show correct description for workflow contracts (#2567)
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent 882fa49 commit bbb8cab

14 files changed

+465
-365
lines changed

app/cli/cmd/workflow_contract_describe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func newWorkflowContractDescribeCmd() *cobra.Command {
3838
cmd := &cobra.Command{
3939
Use: "describe",
4040
Short: "Describe the information of the contract",
41-
RunE: func(cmd *cobra.Command, args []string) error {
41+
RunE: func(_ *cobra.Command, _ []string) error {
4242
res, err := action.NewWorkflowContractDescribe(ActionOpts).Run(name, revision)
4343
if err != nil {
4444
return err
@@ -81,15 +81,15 @@ func encodeContractOutput(run *action.WorkflowContractWithVersionItem) error {
8181

8282
func contractDescribeTableOutput(contractWithVersion *action.WorkflowContractWithVersionItem) error {
8383
revision := contractWithVersion.Revision
84-
8584
c := contractWithVersion.Contract
85+
8686
t := output.NewTableWriter()
8787
t.SetTitle("Contract")
8888
t.AppendRow(table.Row{"Name", c.Name})
8989
t.AppendSeparator()
9090
t.AppendRow(table.Row{"Scope", c.ScopedEntity.String()})
9191
t.AppendSeparator()
92-
t.AppendRow(table.Row{"Description", c.Description})
92+
t.AppendRow(table.Row{"Description", revision.Description}) // description is always provided through version
9393
t.AppendSeparator()
9494
t.AppendRow(table.Row{"Associated Workflows", stringifyAssociatedWorkflows(contractWithVersion)})
9595
t.AppendSeparator()

app/cli/pkg/action/workflow_contract_list.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ type WorkflowRef struct {
6161
}
6262

6363
type WorkflowContractVersionItem struct {
64-
ID string `json:"id"`
65-
Revision int `json:"revision"`
66-
CreatedAt *time.Time `json:"createdAt"`
67-
BodyV1 *schemav1.CraftingSchema `json:"bodyV1"`
68-
RawBody *ContractRawBody `json:"rawBody"`
64+
ID string `json:"id"`
65+
Revision int `json:"revision"`
66+
Description string `json:"description"`
67+
CreatedAt *time.Time `json:"createdAt"`
68+
BodyV1 *schemav1.CraftingSchema `json:"bodyV1"`
69+
RawBody *ContractRawBody `json:"rawBody"`
6970
}
7071

7172
type ContractRawBody struct {
@@ -123,8 +124,9 @@ func pbWorkflowContractItemToAction(in *pb.WorkflowContractItem) *WorkflowContra
123124
func pbWorkflowContractVersionItemToAction(in *pb.WorkflowContractVersionItem) *WorkflowContractVersionItem {
124125
return &WorkflowContractVersionItem{
125126
Revision: int(in.GetRevision()), ID: in.GetId(), BodyV1: in.GetV1(),
126-
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()),
127-
RawBody: &ContractRawBody{Body: string(in.RawContract.GetBody()), Format: in.RawContract.GetFormat().String()},
127+
Description: in.Description,
128+
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()),
129+
RawBody: &ContractRawBody{Body: string(in.RawContract.GetBody()), Format: in.RawContract.GetFormat().String()},
128130
}
129131
}
130132

app/controlplane/api/controlplane/v1/response_messages.pb.go

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

app/controlplane/api/controlplane/v1/response_messages.proto

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ message PolicyReference {
178178
message WorkflowContractItem {
179179
string id = 1;
180180
string name = 2;
181-
string description = 6;
181+
// deprecated: description now belongs to the version, as it's versioned since the introduction of new contracts v2
182+
string description = 6 [deprecated = true];
182183
google.protobuf.Timestamp created_at = 3;
183184
google.protobuf.Timestamp updated_at = 10;
184185
int32 latest_revision = 4;
@@ -222,9 +223,12 @@ message WorkflowContractVersionItem {
222223

223224
RawBody raw_contract = 5;
224225

225-
// The name of the contract used for this run
226+
// The name of the contract
226227
string contract_name = 6;
227228

229+
// The contract version description
230+
string description = 7;
231+
228232
message RawBody {
229233
bytes body = 1;
230234
Format format = 2 [(buf.validate.field).enum = {

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

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

app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractItem.jsonschema.json

Lines changed: 1 addition & 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/controlplane.v1.WorkflowContractItem.schema.json

Lines changed: 1 addition & 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/controlplane.v1.WorkflowContractVersionItem.jsonschema.json

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

app/controlplane/api/gen/jsonschema/controlplane.v1.WorkflowContractVersionItem.schema.json

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

app/controlplane/internal/service/attestation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (s *AttestationService) GetContract(ctx context.Context, req *cpAPI.Attesta
134134

135135
resp := &cpAPI.AttestationServiceGetContractResponse_Result{
136136
Workflow: bizWorkflowToPb(wf),
137-
Contract: bizWorkFlowContractVersionToPb(contractVersion.Version),
137+
Contract: bizWorkFlowContractVersionToPb(contractVersion.Version, contractVersion.Contract),
138138
}
139139

140140
return &cpAPI.AttestationServiceGetContractResponse{Result: resp}, nil

0 commit comments

Comments
 (0)