Skip to content

Commit c70fd6a

Browse files
authored
feat(cli): improve attestation push result in table format (#797)
Signed-off-by: Jose I. Paris <[email protected]>
1 parent c6d9c89 commit c70fd6a

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

app/cli/cmd/attestation_init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func newAttestationInitCmd() *cobra.Command {
7777
return newGracefulError(err)
7878
}
7979

80-
return encodeOutput(res, attestationStatusTableOutput)
80+
return encodeOutput(res, simpleStatusTable)
8181
},
8282
}
8383

app/cli/cmd/attestation_push.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ func newAttestationPushCmd() *cobra.Command {
8282
return newGracefulError(err)
8383
}
8484

85-
// NOTE: we are not moving yet to full table by default
86-
// to maintain backward compatibility
85+
// In JSON format, we encode the full attestation
8786
if flagOutputFormat == formatJSON {
8887
return encodeJSON(res)
8988
}
9089

91-
// default to mix of json and text to stdout and stderr by default
92-
// kept to maintain backward compatibility
93-
// TODO: in the future we'll render either a table or a proper report
94-
fmt.Println(res.Envelope)
90+
// In TABLE format, we render the attestation status
91+
if err := encodeOutput(res.Status, fullStatusTable); err != nil {
92+
return fmt.Errorf("failed to render output: %w", err)
93+
}
94+
9595
if res.Digest != "" {
9696
logger.Info().Msgf("Attestation Digest: %s", res.Digest)
9797
}

app/cli/cmd/attestation_status.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func newAttestationStatusCmd() *cobra.Command {
5151
return err
5252
}
5353

54-
return encodeOutput(res, attestationStatusTableOutput)
54+
return encodeOutput(res, simpleStatusTable)
5555
},
5656
}
5757

@@ -61,7 +61,15 @@ func newAttestationStatusCmd() *cobra.Command {
6161
return cmd
6262
}
6363

64-
func attestationStatusTableOutput(status *action.AttestationStatusResult) error {
64+
func simpleStatusTable(status *action.AttestationStatusResult) error {
65+
return attestationStatusTableOutput(status, false)
66+
}
67+
68+
func fullStatusTable(status *action.AttestationStatusResult) error {
69+
return attestationStatusTableOutput(status, true)
70+
}
71+
72+
func attestationStatusTableOutput(status *action.AttestationStatusResult, full bool) error {
6573
// General info table
6674
gt := newTableWriter()
6775
gt.AppendRow(table.Row{"Initialized At", status.InitializedAt.Format(time.RFC822)})
@@ -90,11 +98,11 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult) error
9098

9199
gt.Render()
92100

93-
if err := materialsTable(status); err != nil {
101+
if err := materialsTable(status, full); err != nil {
94102
return err
95103
}
96104

97-
if err := envVarsTable(status); err != nil {
105+
if err := envVarsTable(status, full); err != nil {
98106
return err
99107
}
100108

@@ -105,7 +113,7 @@ func attestationStatusTableOutput(status *action.AttestationStatusResult) error
105113
return nil
106114
}
107115

108-
func envVarsTable(status *action.AttestationStatusResult) error {
116+
func envVarsTable(status *action.AttestationStatusResult, full bool) error {
109117
if len(status.EnvVars) == 0 && len(status.RunnerContext.EnvVars) == 0 {
110118
return nil
111119
}
@@ -138,7 +146,7 @@ func envVarsTable(status *action.AttestationStatusResult) error {
138146

139147
return nil
140148
}
141-
func materialsTable(status *action.AttestationStatusResult) error {
149+
func materialsTable(status *action.AttestationStatusResult, full bool) error {
142150
if len(status.Materials) == 0 {
143151
return nil
144152
}

app/cli/internal/action/attestation_push.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type AttestationPushOpts struct {
3636
}
3737

3838
type AttestationResult struct {
39-
Digest string `json:"digest"`
40-
Envelope string `json:"envelope"`
39+
Digest string `json:"digest"`
40+
Envelope string `json:"envelope"`
41+
Status *AttestationStatusResult `json:"status"`
4142
}
4243

4344
type AttestationPush struct {
@@ -68,6 +69,16 @@ func (action *AttestationPush) Run(ctx context.Context, attestationID string, ru
6869
return nil, ErrAttestationNotInitialized
6970
}
7071

72+
// Retrieve attestation status
73+
statusAction, err := NewAttestationStatus(&AttestationStatusOpts{ActionsOpts: action.ActionsOpts})
74+
if err != nil {
75+
return nil, fmt.Errorf("creating status action: %w", err)
76+
}
77+
attestationStatus, err := statusAction.Run(ctx, attestationID)
78+
if err != nil {
79+
return nil, fmt.Errorf("creating running status action: %w", err)
80+
}
81+
7182
if err := action.c.LoadCraftingState(ctx, attestationID); err != nil {
7283
action.Logger.Err(err).Msg("loading existing attestation")
7384
return nil, err
@@ -137,7 +148,7 @@ func (action *AttestationPush) Run(ctx context.Context, attestationID string, ru
137148
return nil, fmt.Errorf("failed to encode output: %w", err)
138149
}
139150

140-
attestationResult := &AttestationResult{Envelope: rawEnvelope.String()}
151+
attestationResult := &AttestationResult{Envelope: rawEnvelope.String(), Status: attestationStatus}
141152

142153
action.Logger.Debug().Msg("render completed")
143154
if action.c.CraftingState.DryRun {

0 commit comments

Comments
 (0)