()
| 24 | ) |
| 25 | |
| 26 | func newAttestationResetCmd() *cobra.Command { |
| 27 | var trigger, reason string |
| 28 | triggerFailed, triggerCanceled := action.AttestationResetTriggerFailed, action.AttestationResetTriggerCancelled |
| 29 | |
| 30 | cmd := &cobra.Command{ |
| 31 | Use: "reset", |
| 32 | Short: "mark current attestation process as canceled or failed", |
| 33 | Annotations: map[string]string{ |
| 34 | useAPIToken: "true", |
| 35 | supportsFederatedAuthAnnotation: "true", |
| 36 | }, |
| 37 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 38 | if trigger != triggerFailed && trigger != triggerCanceled { |
| 39 | return errors.New("--trigger value is invalid") |
| 40 | } |
| 41 | |
| 42 | return nil |
| 43 | }, |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | a, err := action.NewAttestationReset(&action.AttestationResetOpts{ActionsOpts: ActionOpts, LocalStatePath: attestationLocalStatePath}) |
| 46 | if err != nil { |
| 47 | return fmt.Errorf("failed to load action: %w", err) |
| 48 | } |
| 49 | |
| 50 | if err := a.Run(cmd.Context(), attestationID, trigger, reason); err != nil { |
| 51 | return newGracefulError(err) |
| 52 | } |
| 53 | |
| 54 | msg := "Attestation canceled" |
| 55 | if trigger == triggerFailed { |
| 56 | msg = "Attestation marked as failed" |
| 57 | } |
| 58 | |
| 59 | logger.Info().Msg(msg) |
| 60 | |
| 61 | return nil |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | cmd.Flags().StringVar(&trigger, "trigger", triggerFailed, fmt.Sprintf("trigger for the reset, valid options are %q and %q", triggerFailed, triggerCanceled)) |
| 66 | cmd.Flags().StringVar(&reason, "reason", "", "reset reason") |
| 67 | flagAttestationID(cmd) |
| 68 | |
| 69 | return cmd |
| 70 | } |
no test coverage detected