Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/cli/cmd/attestation_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ func newAttestationPushCmd() *cobra.Command {
return newGracefulError(err)
}

return encodeJSON(res)
if err := encodeJSON(res.Envelope); err != nil {
return err
}

if res.Digest != "" {
cmd.Printf("\nAttestation Digest: %s\n", res.Digest)
}

return nil
},
}

Expand Down
38 changes: 24 additions & 14 deletions app/cli/internal/action/attestation_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type AttestationPushOpts struct {
KeyPath, CLIVersion, CLIDigest string
}

type AttestationResult struct {
Digest string `json:"digest"`
Envelope *dsse.Envelope `json:"envelope"`
}

type AttestationPush struct {
*ActionsOpts
c *crafter.Crafter
Expand All @@ -48,8 +53,7 @@ func NewAttestationPush(cfg *AttestationPushOpts) *AttestationPush {
}
}

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

res, err := renderer.Render()
envelope, err := renderer.Render()
if err != nil {
return nil, err
}

attestationResult := &AttestationResult{Envelope: envelope}

action.Logger.Debug().Msg("render completed")
if action.c.CraftingState.DryRun {
action.Logger.Info().Msg("dry-run completed, push skipped")
// We are done, remove the existing att state
if err := action.c.Reset(); err != nil {
return nil, err
}
return res, nil

return attestationResult, nil
}

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

action.Logger.Info().Msg("push completed of the following payload")
action.Logger.Info().Msg("push completed")

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

return res, nil
return attestationResult, nil
}

func pushToControlPlane(conn *grpc.ClientConn, envelope *dsse.Envelope, workflowRunID string) error {
func pushToControlPlane(conn *grpc.ClientConn, envelope *dsse.Envelope, workflowRunID string) (string, error) {
encodedAttestation, err := encodeEnvelope(envelope)
if err != nil {
return err
return "", fmt.Errorf("encoding attestation: %w", err)
}

client := pb.NewAttestationServiceClient(conn)
if _, err := client.Store(context.Background(), &pb.AttestationServiceStoreRequest{
resp, err := client.Store(context.Background(), &pb.AttestationServiceStoreRequest{
Attestation: encodedAttestation,
WorkflowRunId: workflowRunID,
}); err != nil {
return err
})

if err != nil {
return "", fmt.Errorf("contacting the control plane: %w", err)
}

return nil
return resp.Result.Digest, nil
}

func encodeEnvelope(e *dsse.Envelope) ([]byte, error) {
Expand Down
436 changes: 257 additions & 179 deletions app/controlplane/api/controlplane/v1/workflow_run.pb.go

Large diffs are not rendered by default.

137 changes: 137 additions & 0 deletions app/controlplane/api/controlplane/v1/workflow_run.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion app/controlplane/api/controlplane/v1/workflow_run.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ message AttestationServiceStoreRequest {
string workflow_run_id = 2 [(validate.rules).string = {min_len: 1}];
}

message AttestationServiceStoreResponse {}
message AttestationServiceStoreResponse {
Result result = 1;

message Result {
// attestation digest
string digest = 2;
}
}

message AttestationServiceCancelRequest {
string workflow_run_id = 1 [(validate.rules).string = {min_len: 1}];
Expand Down
Loading