Skip to content

Commit bfc5a84

Browse files
committed
standardize to always provide the description in the version
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
1 parent e08f80a commit bfc5a84

10 files changed

Lines changed: 323 additions & 310 deletions

File tree

app/cli/cmd/workflow_contract_describe.go

Lines changed: 2 additions & 8 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
@@ -83,19 +83,13 @@ func contractDescribeTableOutput(contractWithVersion *action.WorkflowContractWit
8383
revision := contractWithVersion.Revision
8484
c := contractWithVersion.Contract
8585

86-
// If available, show the description from the revision
87-
description := c.Description
88-
if revision.Description != "" {
89-
description = revision.Description
90-
}
91-
9286
t := output.NewTableWriter()
9387
t.SetTitle("Contract")
9488
t.AppendRow(table.Row{"Name", c.Name})
9589
t.AppendSeparator()
9690
t.AppendRow(table.Row{"Scope", c.ScopedEntity.String()})
9791
t.AppendSeparator()
98-
t.AppendRow(table.Row{"Description", description})
92+
t.AppendRow(table.Row{"Description", revision.Description}) // description is always provided through
9993
t.AppendSeparator()
10094
t.AppendRow(table.Row{"Associated Workflows", stringifyAssociatedWorkflows(contractWithVersion)})
10195
t.AppendSeparator()

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

Lines changed: 298 additions & 293 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: 2 additions & 1 deletion
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;

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

Lines changed: 5 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/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/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

app/controlplane/internal/service/workflowcontract.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz"
2525
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
2626
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/unmarshal"
27-
errors "github.com/go-kratos/kratos/v2/errors"
27+
"github.com/go-kratos/kratos/v2/errors"
2828
"github.com/google/uuid"
2929
"google.golang.org/protobuf/types/known/timestamppb"
3030
)
@@ -91,7 +91,7 @@ func (s *WorkflowContractService) Describe(ctx context.Context, req *pb.Workflow
9191

9292
result := &pb.WorkflowContractServiceDescribeResponse_Result{
9393
Contract: bizWorkFlowContractToPb(contractWithVersion.Contract),
94-
Revision: bizWorkFlowContractVersionToPb(contractWithVersion.Version),
94+
Revision: bizWorkFlowContractVersionToPb(contractWithVersion.Version, contractWithVersion.Contract),
9595
}
9696

9797
return &pb.WorkflowContractServiceDescribeResponse{Result: result}, nil
@@ -199,7 +199,7 @@ func (s *WorkflowContractService) Update(ctx context.Context, req *pb.WorkflowCo
199199

200200
result := &pb.WorkflowContractServiceUpdateResponse_Result{
201201
Contract: bizWorkFlowContractToPb(schemaWithVersion.Contract),
202-
Revision: bizWorkFlowContractVersionToPb(schemaWithVersion.Version),
202+
Revision: bizWorkFlowContractVersionToPb(schemaWithVersion.Version, schemaWithVersion.Contract),
203203
}
204204

205205
return &pb.WorkflowContractServiceUpdateResponse{Result: result}, nil
@@ -261,7 +261,7 @@ func bizWorkFlowContractToPb(schema *biz.WorkflowContract) *pb.WorkflowContractI
261261
return result
262262
}
263263

264-
func bizWorkFlowContractVersionToPb(schema *biz.WorkflowContractVersion) *pb.WorkflowContractVersionItem {
264+
func bizWorkFlowContractVersionToPb(schema *biz.WorkflowContractVersion, contract *biz.WorkflowContract) *pb.WorkflowContractVersionItem {
265265
formatTranslator := func(unmarshal.RawFormat) pb.WorkflowContractVersionItem_RawBody_Format {
266266
switch schema.Schema.Format {
267267
case unmarshal.RawFormatJSON:
@@ -288,8 +288,12 @@ func bizWorkFlowContractVersionToPb(schema *biz.WorkflowContractVersion) *pb.Wor
288288
},
289289
}
290290

291+
// Standardize the API to always provide description in the version.
292+
// Add description from the proper source (new schemav2 or legacy top level contract)
291293
if schema.Schema.Schemav2 != nil {
292294
item.Description = schema.Schema.Schemav2.GetMetadata().GetDescription()
295+
} else {
296+
item.Description = contract.Description
293297
}
294298

295299
return item

app/controlplane/internal/service/workflowrun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *WorkflowRunService) View(ctx context.Context, req *pb.WorkflowRunServic
183183

184184
wr := bizWorkFlowRunToPb(run)
185185
wr.Workflow = bizWorkflowToPb(run.Workflow)
186-
wr.ContractVersion = bizWorkFlowContractVersionToPb(contractAndVersion.Version)
186+
wr.ContractVersion = bizWorkFlowContractVersionToPb(contractAndVersion.Version, contractAndVersion.Contract)
187187
wr.ContractVersion.ContractName = contractAndVersion.Contract.Name
188188
res := &pb.WorkflowRunServiceViewResponse_Result{
189189
WorkflowRun: wr,

app/controlplane/pkg/biz/workflowcontract.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import (
3434
)
3535

3636
type WorkflowContract struct {
37-
ID uuid.UUID
38-
Name string
37+
ID uuid.UUID
38+
Name string
39+
// Deprecated: use description from the version instead
3940
Description string
4041
LatestRevision int
4142
LatestRevisionCreatedAt *time.Time
@@ -71,6 +72,7 @@ type Contract struct {
7172
// Detected format as provided by the user
7273
Format unmarshal.RawFormat
7374
// marshalled proto v1 contract
75+
// Deprecated: use Schemav2 instead
7476
Schema *schemav1.CraftingSchema
7577
// marshalled proto v2 contract
7678
Schemav2 *schemav1.CraftingSchemaV2

0 commit comments

Comments
 (0)