Skip to content

Commit 7d76e4c

Browse files
authored
chore: dump attestation bundle for "attestation" output format (#1800)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent dfe10b1 commit 7d76e4c

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

app/cli/cmd/output.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424

2525
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
2626
"github.com/jedib0t/go-pretty/v6/table"
27+
"google.golang.org/protobuf/encoding/protojson"
28+
"google.golang.org/protobuf/proto"
2729
)
2830

2931
const formatJSON = "json"
@@ -72,6 +74,22 @@ func encodeJSON(v interface{}) error {
7274
return encodeJSONToWriter(v, os.Stdout)
7375
}
7476

77+
func encodeProtoJSON(v proto.Message) error {
78+
options := protojson.MarshalOptions{
79+
Multiline: true,
80+
Indent: " ",
81+
}
82+
output, err := options.Marshal(v)
83+
if err != nil {
84+
return fmt.Errorf("failed to encode output: %w", err)
85+
}
86+
_, err = fmt.Fprint(os.Stdout, string(output))
87+
if err != nil {
88+
return fmt.Errorf("failed to write output: %w", err)
89+
}
90+
return nil
91+
}
92+
7593
func encodeJSONToWriter(v interface{}, w io.Writer) error {
7694
encoder := json.NewEncoder(w)
7795
encoder.SetIndent("", " ")

app/cli/cmd/workflow_workflow_run_describe.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import (
3030
"github.com/jedib0t/go-pretty/v6/text"
3131
"github.com/muesli/reflow/wrap"
3232
"github.com/secure-systems-lab/go-securesystemslib/dsse"
33+
protobundle "github.com/sigstore/protobuf-specs/gen/pb-go/bundle/v1"
3334
"github.com/spf13/cobra"
35+
"google.golang.org/protobuf/encoding/protojson"
3436
)
3537

3638
const formatStatement = "statement"
@@ -291,7 +293,16 @@ func encodeAttestationOutput(run *action.WorkflowRunItemFull, writer io.Writer)
291293
case formatStatement:
292294
return encodeJSON(run.Attestation.Statement())
293295
case formatAttestation:
294-
return encodeJSON(run.Attestation.Envelope)
296+
if run.Attestation.Bundle != nil {
297+
var bundle protobundle.Bundle
298+
err = protojson.Unmarshal(run.Attestation.Bundle, &bundle)
299+
if err != nil {
300+
return fmt.Errorf("unmarshaling attestation: %w", err)
301+
}
302+
return encodeProtoJSON(&bundle)
303+
} else {
304+
return encodeJSON(run.Attestation.Envelope)
305+
}
295306
case formatPayloadPAE:
296307
return encodePAE(run, writer)
297308
default:

app/cli/internal/action/workflow_run_describe.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type WorkflowRunItemFull struct {
4949

5050
type WorkflowRunAttestationItem struct {
5151
Envelope *dsse.Envelope `json:"envelope"`
52+
Bundle []byte `json:"bundle"`
5253
statement *intoto.Statement
5354
Materials []*Material `json:"materials,omitempty"`
5455
EnvVars []*EnvVar `json:"envvars,omitempty"`
@@ -217,6 +218,7 @@ func (action *WorkflowRunDescribe) Run(ctx context.Context, opts *WorkflowRunDes
217218

218219
item.Attestation = &WorkflowRunAttestationItem{
219220
Envelope: envelope,
221+
Bundle: attestation.GetBundle(),
220222
statement: statement,
221223
EnvVars: envVars,
222224
Materials: materials,

0 commit comments

Comments
 (0)