Skip to content

Commit d1ced8a

Browse files
authored
Fix panic on repos without provenance (#146)
This commit fixes a panic when building a policy for repos without previous provenance metadata. When no metadata is found, now we default to SLSA1 instead of panicking. Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
1 parent 8e05e80 commit d1ced8a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sourcetool/pkg/policy/policy.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,18 @@ func CreateLocalPolicy(ctx context.Context, gh_connection *gh_control.GitHubConn
181181
return "", fmt.Errorf("could not get provenance for latest commit: %w", err)
182182
}
183183

184-
eligibleLevel, _ := computeEligibleSlsaLevel(provPred.Controls)
185-
eligibleSince, err := computeEligibleSince(provPred.Controls, eligibleLevel)
186-
if err != nil {
187-
return "", fmt.Errorf("could not compute eligible since: %w", err)
184+
// Default to SLSA1 since unset date
185+
var eligibleSince = &time.Time{}
186+
var eligibleLevel = slsa_types.SlsaSourceLevel1
187+
188+
// Unless there is previous provenance metadata, then we can compute
189+
// a higher level
190+
if provPred != nil {
191+
eligibleLevel, _ = computeEligibleSlsaLevel(provPred.Controls)
192+
eligibleSince, err = computeEligibleSince(provPred.Controls, eligibleLevel)
193+
if err != nil {
194+
return "", fmt.Errorf("could not compute eligible since: %w", err)
195+
}
188196
}
189197

190198
p := RepoPolicy{

0 commit comments

Comments
 (0)