MCPcopy Create free account
hub / github.com/github/gh-aw / computePolicyHash

Function computePolicyHash

pkg/workflow/cache_integrity.go:29–40  ·  view source on GitHub ↗

computePolicyHash computes a deterministic 8-character hex hash of the allow-only policy. Returns noPolicySentinel when the GitHub tool has no guard policy (i.e., min-integrity is unset). The hash is computed over the canonical form of all policy fields so that: - Same policy in different order → s

(github *GitHubToolConfig)

Source from the content-addressed store, hash-verified

27// - Any policy field change → new hash → cache miss (correct isolation)
28// - Workflows without policy → sentinel value "nopolicy" (consistent key format)
29func computePolicyHash(github *GitHubToolConfig) string {
30 if github == nil || github.MinIntegrity == "" {
31 cacheIntegrityLog.Print("No guard policy configured, using nopolicy sentinel")
32 return noPolicySentinel
33 }
34
35 canonical := buildCanonicalPolicy(github)
36 hash := sha256.Sum256([]byte(canonical))
37 result := hex.EncodeToString(hash[:])[:8]
38 cacheIntegrityLog.Printf("Computed policy hash: %s (min-integrity=%s)", result, github.MinIntegrity)
39 return result
40}
41
42// buildCanonicalPolicy builds the normalized string representation of the allow-only policy.
43// All fields are always present (empty if unset), sorted and deduplicated, so the result

Calls 3

buildCanonicalPolicyFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45