@@ -28,13 +28,13 @@ import (
2828
2929type AttestationInitOpts struct {
3030 * ActionsOpts
31- Override , DryRun bool
31+ DryRun bool
3232}
3333
3434type AttestationInit struct {
3535 * ActionsOpts
36- override , dryRun bool
37- c * crafter.Crafter
36+ dryRun bool
37+ c * crafter.Crafter
3838}
3939
4040// ErrAttestationAlreadyExist means that there is an attestation in progress
@@ -48,20 +48,20 @@ func (e ErrRunnerContextNotFound) Error() string {
4848 return fmt .Sprintf ("The contract expects the attestation to be crafted in a runner of type %q but couldn't be detected" , e .RunnerType )
4949}
5050
51- func NewAttestationInit (cfg * AttestationInitOpts ) * AttestationInit {
51+ func NewAttestationInit (cfg * AttestationInitOpts ) (* AttestationInit , error ) {
52+ c , err := newCrafter (cfg .CPConnection , & cfg .Logger )
53+ if err != nil {
54+ return nil , fmt .Errorf ("failed to load crafter: %w" , err )
55+ }
56+
5257 return & AttestationInit {
5358 ActionsOpts : cfg .ActionsOpts ,
54- override : cfg .Override ,
55- c : crafter .NewCrafter (crafter .WithLogger (& cfg .Logger )),
59+ c : c ,
5660 dryRun : cfg .DryRun ,
57- }
61+ }, nil
5862}
5963
6064func (action * AttestationInit ) Run (contractRevision int ) error {
61- if initialized := action .c .AlreadyInitialized (); initialized && ! action .override {
62- return ErrAttestationAlreadyExist
63- }
64-
6565 action .Logger .Debug ().Msg ("Retrieving attestation definition" )
6666 client := pb .NewAttestationServiceClient (action .ActionsOpts .CPConnection )
6767 // get information of the workflow
@@ -92,6 +92,9 @@ func (action *AttestationInit) Run(contractRevision int) error {
9292 return ErrRunnerContextNotFound {runnerContext .String ()}
9393 }
9494
95+ // Identifier of this attestation instance
96+ var attestationID string
97+
9598 // Init in the control plane if needed including the runner context
9699 if ! action .dryRun {
97100 runResp , err := client .Init (
@@ -108,27 +111,29 @@ func (action *AttestationInit) Run(contractRevision int) error {
108111 workflowRun := runResp .GetResult ().GetWorkflowRun ()
109112 workflowMeta .WorkflowRunId = workflowRun .GetId ()
110113 action .Logger .Debug ().Str ("workflow-run-id" , workflowRun .GetId ()).Msg ("attestation initialized in the control plane" )
114+ attestationID = workflowRun .GetId ()
111115 }
112116
113117 // Initialize the local attestation crafter
114118 // NOTE: important to run this initialization here since workflowMeta is populated
115119 // with the workflowRunId that comes from the control plane
116120 initOpts := & crafter.InitOpts {
117121 WfInfo : workflowMeta , SchemaV1 : contractVersion .GetV1 (),
118- DryRun : action .dryRun ,
122+ DryRun : action .dryRun ,
123+ AttestationID : attestationID ,
119124 }
120125
121126 if err := action .c .Init (initOpts ); err != nil {
122127 return err
123128 }
124129
125130 // Load the env variables both the system populated and the user predefined ones
126- if err := action .c .ResolveEnvVars (); err != nil {
131+ if err := action .c .ResolveEnvVars (attestationID ); err != nil {
127132 if action .dryRun {
128133 return nil
129134 }
130135
131- _ = action .c .Reset ()
136+ _ = action .c .Reset (attestationID )
132137 return err
133138 }
134139
0 commit comments