MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / forPolicy

Method forPolicy

pkg/policies/runtime_inputs.go:40–55  ·  view source on GitHub ↗

forPolicy returns the runtime inputs that apply to a policy attachment identified by its metadata name and raw ref, together with the scope keys that matched. The returned map merges the global inputs with any scoped entries whose key matches the attachment (additively when they share an input name)

(name, ref string)

Source from the content-addressed store, hash-verified

38// entries whose key matches the attachment (additively when they share an
39// input name). Returns (nil, nil) when nothing applies. Nil-safe.
40func (ri *RuntimeInputs) forPolicy(name, ref string) (map[string]string, []string) {
41 if ri == nil || (len(ri.Global) == 0 && len(ri.Scoped) == 0) {
42 return nil, nil
43 }
44
45 effective := ri.Global
46 var matched []string
47 for scope, inputs := range ri.Scoped {
48 if policyScopeMatches(scope, name, ref) {
49 matched = append(matched, scope)
50 effective = MergeRuntimeInputs(effective, inputs)
51 }
52 }
53
54 return effective, matched
55}
56
57// policyScopeMatches reports whether a runtime-input scope key targets the
58// policy attachment identified by its metadata name and raw ref. A scope

Callers 2

Calls 2

policyScopeMatchesFunction · 0.85
MergeRuntimeInputsFunction · 0.85

Tested by 1