Skip to content

Commit c5b6a1b

Browse files
authored
feat: custom annotations (#278)
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
1 parent 0264f95 commit c5b6a1b

32 files changed

+1184
-309
lines changed

app/cli/api/attestation/v1/crafting_state.pb.go

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

app/cli/api/attestation/v1/crafting_state.pb.validate.go

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

app/cli/api/attestation/v1/crafting_state.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ message Attestation {
4747
// leveraging a form of inline CAS
4848
bool inline_cas = 8;
4949

50+
// Annotations for the material
51+
map<string, string> annotations = 9 [(validate.rules).map.values.string.min_len = 1];
52+
5053
message KeyVal {
5154
string id = 1 [(validate.rules).string.min_len = 1];
5255
string value = 2 [(validate.rules).string.min_len = 1];

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
2525
"github.com/jedib0t/go-pretty/v6/table"
2626
"github.com/jedib0t/go-pretty/v6/text"
27+
"github.com/muesli/reflow/wrap"
2728
"github.com/spf13/cobra"
2829
)
2930

@@ -134,12 +135,21 @@ func predicateV1Table(att *action.WorkflowRunAttestationItem) {
134135
mt := newTableWriter()
135136
mt.SetTitle("Materials")
136137

137-
header := table.Row{"Name", "Type", "Value"}
138-
mt.AppendHeader(header)
139-
140138
for _, m := range materials {
141-
row := table.Row{m.Name, m.Type, m.Value}
142-
mt.AppendRow(row)
139+
mt.AppendRow(table.Row{"Name", m.Name})
140+
mt.AppendRow(table.Row{"Type", m.Type})
141+
mt.AppendRow(table.Row{"Value", wrap.String(m.Value, 100)})
142+
if m.Hash != "" {
143+
mt.AppendRow(table.Row{"Digest", m.Hash})
144+
}
145+
146+
if len(m.Annotations) > 0 {
147+
mt.AppendRow(table.Row{"Annotations", "------"})
148+
for _, a := range m.Annotations {
149+
mt.AppendRow(table.Row{"", fmt.Sprintf("%s: %s", a.Name, a.Value)})
150+
}
151+
}
152+
mt.AppendSeparator()
143153
}
144154

145155
mt.Render()

app/cli/internal/action/workflow_run_describe.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"errors"
2121
"fmt"
22+
"sort"
2223
"time"
2324

2425
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
@@ -51,12 +52,20 @@ type WorkflowRunAttestationItem struct {
5152
}
5253

5354
type Material struct {
55+
Name string `json:"name"`
56+
// filename, container image name, string value, ...
57+
Value string `json:"value"`
58+
Hash string `json:"hash"`
59+
Type string `json:"type"`
60+
Annotations []*Annotation `json:"annotations,omitempty"`
61+
}
62+
63+
type EnvVar struct {
5464
Name string `json:"name"`
5565
Value string `json:"value"`
56-
Type string `json:"type"`
5766
}
5867

59-
type EnvVar struct {
68+
type Annotation struct {
6069
Name string `json:"name"`
6170
Value string `json:"value"`
6271
}
@@ -120,7 +129,7 @@ func (action *WorkflowRunDescribe) Run(runID string, verify bool, publicKey stri
120129

121130
materials := make([]*Material, 0, len(attestation.GetMaterials()))
122131
for _, v := range attestation.GetMaterials() {
123-
materials = append(materials, &Material{Name: v.Name, Value: v.Value, Type: v.Type})
132+
materials = append(materials, materialPBToAction(v))
124133
}
125134

126135
item.Attestation = &WorkflowRunAttestationItem{
@@ -134,6 +143,30 @@ func (action *WorkflowRunDescribe) Run(runID string, verify bool, publicKey stri
134143
return item, nil
135144
}
136145

146+
func materialPBToAction(in *pb.AttestationItem_Material) *Material {
147+
m := &Material{
148+
Name: in.Name,
149+
Value: in.Value,
150+
Type: in.Type,
151+
Hash: in.Hash,
152+
}
153+
154+
// append annotations sorted
155+
if in.Annotations != nil {
156+
keys := make([]string, 0, len(in.Annotations))
157+
for k := range in.Annotations {
158+
keys = append(keys, k)
159+
}
160+
sort.Strings(keys)
161+
162+
for _, k := range keys {
163+
m.Annotations = append(m.Annotations, &Annotation{Name: k, Value: in.Annotations[k]})
164+
}
165+
}
166+
167+
return m
168+
}
169+
137170
func verifyEnvelope(ctx context.Context, e *dsse.Envelope, publicKey string) error {
138171
// Currently we only support basic cosign public key check
139172
// TODO: Add more verification methods

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

Lines changed: 161 additions & 131 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.pb.validate.go

Lines changed: 4 additions & 0 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ message AttestationItem {
6565

6666
message Material {
6767
string name = 1;
68+
// This might be the raw value, the container image name, the filename and so on
6869
string value = 2;
6970
// Material type, i.e ARTIFACT
7071
string type = 3;
72+
map<string, string> annotations = 4;
73+
string hash = 5;
7174
}
7275
}
7376

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

Lines changed: 132 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)