(ctx context.Context, attestationID string, runtimeAnnotations map[string]string, bypassPolicyCheck bool)
| 94 | } |
| 95 | |
| 96 | func (action *AttestationPush) Run(ctx context.Context, attestationID string, runtimeAnnotations map[string]string, bypassPolicyCheck bool) (*AttestationResult, error) { |
| 97 | useRemoteState := attestationID != "" |
| 98 | // initialize the crafter. If attestation-id is provided we assume the attestation is performed using remote state |
| 99 | crafter, err := newCrafter(&newCrafterStateOpts{enableRemoteState: useRemoteState, localStatePath: action.localStatePath}, action.CPConnection, action.opts...) |
| 100 | if err != nil { |
| 101 | return nil, fmt.Errorf("failed to load crafter: %w", err) |
| 102 | } |
| 103 | |
| 104 | if initialized, err := crafter.AlreadyInitialized(ctx, attestationID); err != nil { |
| 105 | return nil, fmt.Errorf("checking if attestation is already initialized: %w", err) |
| 106 | } else if !initialized { |
| 107 | return nil, ErrAttestationNotInitialized |
| 108 | } |
| 109 | |
| 110 | // Retrieve attestation status |
| 111 | statusAction, err := NewAttestationStatus(&AttestationStatusOpts{ |
| 112 | ActionsOpts: action.ActionsOpts, UseAttestationRemoteState: useRemoteState, isPushed: true, LocalStatePath: action.localStatePath, |
| 113 | }) |
| 114 | |
| 115 | if err != nil { |
| 116 | return nil, fmt.Errorf("creating status action: %w", err) |
| 117 | } |
| 118 | |
| 119 | attestationStatus, err := statusAction.Run(ctx, attestationID) |
| 120 | if err != nil { |
| 121 | return nil, fmt.Errorf("creating running status action: %w", err) |
| 122 | } |
| 123 | |
| 124 | if err := crafter.LoadCraftingState(ctx, attestationID); err != nil { |
| 125 | action.Logger.Err(err).Msg("loading existing attestation") |
| 126 | return nil, err |
| 127 | } |
| 128 | |
| 129 | // Annotations |
| 130 | craftedAnnotations := make(map[string]string, 0) |
| 131 | // 1 - Set annotations that come from the contract |
| 132 | for _, v := range crafter.CraftingState.GetAnnotations() { |
| 133 | craftedAnnotations[v.Name] = v.Value |
| 134 | } |
| 135 | |
| 136 | // 2 - Populate annotation values from the ones provided at runtime |
| 137 | // a) we do not allow overriding values that come from the contract |
| 138 | // b) we allow runtime annotations not specified in the contract |
| 139 | for kr, vr := range runtimeAnnotations { |
| 140 | if v, found := craftedAnnotations[kr]; found && v != "" { |
| 141 | // NOTE: we do not allow overriding values that come from the contract |
| 142 | action.Logger.Info().Str("annotation", kr).Msg("contract annotation can't be changed, skipping") |
| 143 | } else { |
| 144 | // Set it only if it's not set |
| 145 | craftedAnnotations[kr] = vr |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // Make sure all the annotation values are now set |
| 150 | // This is in fact validated below but by manually checking we can provide a better error message |
| 151 | for k, v := range craftedAnnotations { |
| 152 | var missingAnnotations []string |
| 153 | if v == "" { |
no test coverage detected