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

Method Capabilities

pkg/policies/engine/rego/rego.go:304–341  ·  view source on GitHub ↗

Capabilities returns the capabilities of the environment based on the mode of operation defaulting to EnvironmentModeRestrictive if not provided.

()

Source from the content-addressed store, hash-verified

302// Capabilities returns the capabilities of the environment based on the mode of operation
303// defaulting to EnvironmentModeRestrictive if not provided.
304func (r *Engine) Capabilities() *ast.Capabilities {
305 capabilities := ast.CapabilitiesForThisVersion()
306 var enabledBuiltin []*ast.Builtin
307
308 switch r.operatingMode {
309 case EnvironmentModeRestrictive:
310 // Copy all builtins functions
311 localBuiltIns := make(map[string]*ast.Builtin, len(ast.BuiltinMap))
312 maps.Copy(localBuiltIns, ast.BuiltinMap)
313
314 // remove custom builtins self-declared non-restrictive
315 for k, builtin := range localBuiltIns {
316 if slices.Contains(builtin.Categories, builtins.NonRestrictiveBuiltin) {
317 delete(localBuiltIns, k)
318 }
319 }
320
321 // Remove not allowed builtins
322 for _, notAllowed := range builtinFuncNotAllowed {
323 delete(localBuiltIns, notAllowed.Name)
324 }
325
326 // Convert map to slice
327 enabledBuiltin = make([]*ast.Builtin, 0, len(localBuiltIns))
328 for _, builtin := range localBuiltIns {
329 enabledBuiltin = append(enabledBuiltin, builtin)
330 }
331
332 // Allow specific network domains
333 capabilities.AllowNet = r.AllowedHostnames
334
335 case EnvironmentModePermissive:
336 enabledBuiltin = capabilities.Builtins
337 }
338
339 capabilities.Builtins = enabledBuiltin
340 return capabilities
341}
342
343func regoResultSetToRawResults(res rego.ResultSet) map[string]interface{} {
344 raw := make(map[string]interface{})

Callers 2

VerifyMethod · 0.95
evaluateMatchingRuleMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected