@@ -22,11 +22,8 @@ import (
2222 "strconv"
2323
2424 pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
25- v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2625 "github.com/chainloop-dev/chainloop/pkg/attestation/crafter"
2726 clientAPI "github.com/chainloop-dev/chainloop/pkg/attestation/crafter/api/attestation/v1"
28- "github.com/chainloop-dev/chainloop/pkg/policies"
29- "github.com/rs/zerolog"
3027)
3128
3229type AttestationInitOpts struct {
@@ -129,12 +126,6 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
129126
130127 action .Logger .Debug ().Msg ("workflow contract and metadata retrieved from the control plane" )
131128
132- // 3. enrich contract with group materials and policies
133- err = enrichContractMaterials (ctx , contractVersion .GetV1 (), client , & action .Logger )
134- if err != nil {
135- return "" , fmt .Errorf ("failed to apply materials from policy groups: %w" , err )
136- }
137-
138129 // Auto discover the runner context and enforce against the one in the contract if needed
139130 discoveredRunner , err := crafter .DiscoverAndEnforceRunner (contractVersion .GetV1 ().GetRunner ().GetType (), action .dryRun , action .Logger )
140131 if err != nil {
@@ -173,8 +164,7 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
173164 // NOTE: important to run this initialization here since workflowMeta is populated
174165 // with the workflowRunId that comes from the control plane
175166 initOpts := & crafter.InitOpts {
176- WfInfo : workflowMeta ,
177- SchemaV1 : contractVersion .GetV1 (),
167+ WfInfo : workflowMeta , SchemaV1 : contractVersion .GetV1 (),
178168 DryRun : action .dryRun ,
179169 AttestationID : attestationID ,
180170 Runner : discoveredRunner ,
@@ -196,44 +186,3 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
196186
197187 return attestationID , nil
198188}
199-
200- func enrichContractMaterials (ctx context.Context , schema * v1.CraftingSchema , client pb.AttestationServiceClient , logger * zerolog.Logger ) error {
201- contractMaterials := schema .GetMaterials ()
202- for _ , pgAtt := range schema .GetPolicyGroups () {
203- group , _ , err := policies .LoadPolicyGroup (ctx , pgAtt , & policies.LoadPolicyGroupOptions {
204- Client : client ,
205- Logger : logger ,
206- })
207- if err != nil {
208- return fmt .Errorf ("failed to load policy group: %w" , err )
209- }
210- logger .Debug ().Msgf ("adding materials from policy group '%s'" , group .GetMetadata ().GetName ())
211-
212- toAdd := getGroupMaterialsToAdd (group , contractMaterials , logger )
213- contractMaterials = append (contractMaterials , toAdd ... )
214- }
215-
216- schema .Materials = contractMaterials
217-
218- return nil
219- }
220-
221- // merge existing materials with group ones, taking the contract's one in case of conflict
222- func getGroupMaterialsToAdd (group * v1.PolicyGroup , fromContract []* v1.CraftingSchema_Material , logger * zerolog.Logger ) []* v1.CraftingSchema_Material {
223- toAdd := make ([]* v1.CraftingSchema_Material , 0 )
224- for _ , groupMaterial := range group .GetSpec ().GetPolicies ().GetMaterials () {
225- // check if material already exists in the contract and skip it in that case
226- ignore := false
227- for _ , mat := range fromContract {
228- if mat .GetName () == groupMaterial .GetName () {
229- logger .Warn ().Msgf ("material '%s' from policy group '%s' is also present in the contract and will be ignored" , mat .GetName (), group .GetMetadata ().GetName ())
230- ignore = true
231- }
232- }
233- if ! ignore {
234- toAdd = append (toAdd , groupMaterial )
235- }
236- }
237-
238- return toAdd
239- }
0 commit comments