(ctx context.Context, attestationID, trigger, reason string)
| 45 | } |
| 46 | |
| 47 | func (action *AttestationReset) Run(ctx context.Context, attestationID, trigger, reason string) error { |
| 48 | // initialize the crafter. If attestation-id is provided we assume the attestation is performed using remote state |
| 49 | crafter, err := newCrafter(&newCrafterStateOpts{enableRemoteState: attestationID != "", localStatePath: action.localStatePath}, action.CPConnection, action.opts...) |
| 50 | if err != nil { |
| 51 | return fmt.Errorf("failed to load crafter: %w", err) |
| 52 | } |
| 53 | |
| 54 | if initialized, err := crafter.AlreadyInitialized(ctx, attestationID); err != nil { |
| 55 | return fmt.Errorf("checking if attestation is already initialized: %w", err) |
| 56 | } else if !initialized { |
| 57 | return ErrAttestationNotInitialized |
| 58 | } |
| 59 | |
| 60 | if err := crafter.LoadCraftingState(ctx, attestationID); err != nil { |
| 61 | action.Logger.Err(err).Msg("loading existing attestation") |
| 62 | return err |
| 63 | } |
| 64 | |
| 65 | if !crafter.CraftingState.DryRun { |
| 66 | client := pb.NewAttestationServiceClient(action.CPConnection) |
| 67 | if _, err := client.Cancel(context.Background(), &pb.AttestationServiceCancelRequest{ |
| 68 | WorkflowRunId: crafter.CraftingState.GetAttestation().GetWorkflow().GetWorkflowRunId(), |
| 69 | Reason: reason, |
| 70 | Trigger: parseTrigger(trigger), |
| 71 | }); err != nil { |
| 72 | if errors.IsNotFound(err) { |
| 73 | action.Logger.Warn().Msg("workflow run not found in the control plane") |
| 74 | } else { |
| 75 | return err |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return crafter.Reset(ctx, attestationID) |
| 81 | } |
| 82 | |
| 83 | func parseTrigger(in string) pb.AttestationServiceCancelRequest_TriggerType { |
| 84 | switch in { |
no test coverage detected