@@ -187,46 +187,27 @@ func (t *Tool) CreateBranchPolicy(ctx context.Context, r *models.Repository, bra
187
187
return nil , fmt .Errorf ("getting backend: %w" , err )
188
188
}
189
189
190
- // Get the branch latest commit from the backend
191
- latestCommit , err := backend .GetLatestCommit (ctx , r , branches [0 ])
190
+ controls , err := t .impl .GetBranchControls (ctx , backend , r , branches [0 ])
192
191
if err != nil {
193
- return nil , fmt .Errorf ("could not get latest commit: %w" , err )
194
- }
195
-
196
- reader , err := t .impl .GetAttestationReader (nil )
197
- if err != nil {
198
- return nil , fmt .Errorf ("getting attestation reader" )
199
- }
200
-
201
- // Get the latest commit provenance attestation
202
- _ , predicate , err := reader .GetCommitProvenance (ctx , branches [0 ], latestCommit )
203
- if err != nil {
204
- return nil , fmt .Errorf ("could not get provenance for latest commit: %w" , err )
192
+ return nil , fmt .Errorf ("getting branch controls: %w" , err )
205
193
}
206
194
207
- controls := & slsa.Controls {}
208
- if predicate != nil {
209
- for _ , c := range predicate .GetControls () {
210
- controls .AddControl (c )
211
- }
212
- }
213
195
return t .createPolicy (r , branches [0 ], controls )
214
196
}
215
197
216
198
// This function will be moved to the policy package once we start integrating
217
199
// it with the global data models (if we do).
218
- func (t * Tool ) createPolicy (r * models.Repository , branch * models.Branch , controls * slsa.Controls ) (* policy.RepoPolicy , error ) {
200
+ func (t * Tool ) createPolicy (r * models.Repository , branch * models.Branch , controls * slsa.ControlSetStatus ) (* policy.RepoPolicy , error ) {
219
201
// Default to SLSA1 since unset date
220
202
eligibleSince := & time.Time {}
221
203
eligibleLevel := slsa .SlsaSourceLevel1
222
204
223
205
var err error
224
206
// Unless there is previous provenance metadata, then we can compute
225
207
// a higher level
226
-
227
208
if controls != nil {
228
- eligibleLevel = policy .ComputeEligibleSlsaLevel (* controls )
229
- eligibleSince , err = policy .ComputeEligibleSince (* controls , eligibleLevel )
209
+ eligibleLevel = policy .ComputeEligibleSlsaLevel (* controls . GetActiveControls () )
210
+ eligibleSince , err = policy .ComputeEligibleSince (* controls . GetActiveControls () , eligibleLevel )
230
211
if err != nil {
231
212
return nil , fmt .Errorf ("could not compute eligible_since: %w" , err )
232
213
}
0 commit comments