MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Run

Method Run

app/cli/pkg/action/attestation_reset.go:47–81  ·  view source on GitHub ↗
(ctx context.Context, attestationID, trigger, reason string)

Source from the content-addressed store, hash-verified

45}
46
47func (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
83func parseTrigger(in string) pb.AttestationServiceCancelRequest_TriggerType {
84 switch in {

Callers 1

newAttestationResetCmdFunction · 0.95

Calls 9

CancelMethod · 0.95
newCrafterFunction · 0.85
parseTriggerFunction · 0.85
AlreadyInitializedMethod · 0.80
LoadCraftingStateMethod · 0.80
ResetMethod · 0.65
GetWorkflowRunIdMethod · 0.45
GetWorkflowMethod · 0.45
GetAttestationMethod · 0.45

Tested by

no test coverage detected