Skip to content

Commit e32e7aa

Browse files
authored
feat: show digest during attestation (#333)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 8fadcc2 commit e32e7aa

File tree

10 files changed

+575
-237
lines changed

10 files changed

+575
-237
lines changed

app/cli/cmd/attestation_push.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ func newAttestationPushCmd() *cobra.Command {
7979
return newGracefulError(err)
8080
}
8181

82-
return encodeJSON(res)
82+
if err := encodeJSON(res.Envelope); err != nil {
83+
return err
84+
}
85+
86+
if res.Digest != "" {
87+
cmd.Printf("\nAttestation Digest: %s\n", res.Digest)
88+
}
89+
90+
return nil
8391
},
8492
}
8593

app/cli/internal/action/attestation_push.go

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ type AttestationPushOpts struct {
3232
KeyPath, CLIVersion, CLIDigest string
3333
}
3434

35+
type AttestationResult struct {
36+
Digest string `json:"digest"`
37+
Envelope *dsse.Envelope `json:"envelope"`
38+
}
39+
3540
type AttestationPush struct {
3641
*ActionsOpts
3742
c *crafter.Crafter
@@ -48,8 +53,7 @@ func NewAttestationPush(cfg *AttestationPushOpts) *AttestationPush {
4853
}
4954
}
5055

51-
// TODO: Return defined type
52-
func (action *AttestationPush) Run(runtimeAnnotations map[string]string) (interface{}, error) {
56+
func (action *AttestationPush) Run(runtimeAnnotations map[string]string) (*AttestationResult, error) {
5357
if initialized := action.c.AlreadyInitialized(); !initialized {
5458
return nil, ErrAttestationNotInitialized
5559
}
@@ -108,50 +112,56 @@ func (action *AttestationPush) Run(runtimeAnnotations map[string]string) (interf
108112
return nil, err
109113
}
110114

111-
res, err := renderer.Render()
115+
envelope, err := renderer.Render()
112116
if err != nil {
113117
return nil, err
114118
}
115119

120+
attestationResult := &AttestationResult{Envelope: envelope}
121+
116122
action.Logger.Debug().Msg("render completed")
117123
if action.c.CraftingState.DryRun {
118124
action.Logger.Info().Msg("dry-run completed, push skipped")
119125
// We are done, remove the existing att state
120126
if err := action.c.Reset(); err != nil {
121127
return nil, err
122128
}
123-
return res, nil
129+
130+
return attestationResult, nil
124131
}
125132

126-
if err := pushToControlPlane(action.ActionsOpts.CPConnection, res, action.c.CraftingState.Attestation.GetWorkflow().GetWorkflowRunId()); err != nil {
127-
return nil, err
133+
attestationResult.Digest, err = pushToControlPlane(action.ActionsOpts.CPConnection, envelope, action.c.CraftingState.Attestation.GetWorkflow().GetWorkflowRunId())
134+
if err != nil {
135+
return nil, fmt.Errorf("pushing to control plane: %w", err)
128136
}
129137

130-
action.Logger.Info().Msg("push completed of the following payload")
138+
action.Logger.Info().Msg("push completed")
131139

132140
// We are done, remove the existing att state
133141
if err := action.c.Reset(); err != nil {
134142
return nil, err
135143
}
136144

137-
return res, nil
145+
return attestationResult, nil
138146
}
139147

140-
func pushToControlPlane(conn *grpc.ClientConn, envelope *dsse.Envelope, workflowRunID string) error {
148+
func pushToControlPlane(conn *grpc.ClientConn, envelope *dsse.Envelope, workflowRunID string) (string, error) {
141149
encodedAttestation, err := encodeEnvelope(envelope)
142150
if err != nil {
143-
return err
151+
return "", fmt.Errorf("encoding attestation: %w", err)
144152
}
145153

146154
client := pb.NewAttestationServiceClient(conn)
147-
if _, err := client.Store(context.Background(), &pb.AttestationServiceStoreRequest{
155+
resp, err := client.Store(context.Background(), &pb.AttestationServiceStoreRequest{
148156
Attestation: encodedAttestation,
149157
WorkflowRunId: workflowRunID,
150-
}); err != nil {
151-
return err
158+
})
159+
160+
if err != nil {
161+
return "", fmt.Errorf("contacting the control plane: %w", err)
152162
}
153163

154-
return nil
164+
return resp.Result.Digest, nil
155165
}
156166

157167
func encodeEnvelope(e *dsse.Envelope) ([]byte, error) {

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

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

app/controlplane/api/controlplane/v1/workflow_run.pb.validate.go

Lines changed: 137 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/workflow_run.proto

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ message AttestationServiceStoreRequest {
7272
string workflow_run_id = 2 [(validate.rules).string = {min_len: 1}];
7373
}
7474

75-
message AttestationServiceStoreResponse {}
75+
message AttestationServiceStoreResponse {
76+
Result result = 1;
77+
78+
message Result {
79+
// attestation digest
80+
string digest = 2;
81+
}
82+
}
7683

7784
message AttestationServiceCancelRequest {
7885
string workflow_run_id = 1 [(validate.rules).string = {min_len: 1}];

0 commit comments

Comments
 (0)