MCPcopy Create free account
hub / github.com/cloudwan/gohan / filterSchemasForPolicy

Function filterSchemasForPolicy

cli/template.go:289–322  ·  view source on GitHub ↗
(principal string, policies []*schema.Policy, schemas []*schema.Schema)

Source from the content-addressed store, hash-verified

287}
288
289func filterSchemasForPolicy(principal string, policies []*schema.Policy, schemas []*schema.Schema) []*SchemaWithPolicy {
290 var schemasWithPolicy []*SchemaWithPolicy
291 allPoliciesNames := []string{"create", "read", "update", "delete"}
292 if principal == "" {
293 for _, schema := range schemas {
294 schemasWithPolicy = append(schemasWithPolicy, &SchemaWithPolicy{schema, allPoliciesNames})
295 }
296 return schemasWithPolicy
297 }
298 matchedPolicies := filterPolicies(principal, policies)
299 principalNobody := "Nobody"
300 nobodyPolicies := filterPolicies(principalNobody, policies)
301 if principal == principalNobody {
302 nobodyPolicies = nil
303 }
304 for _, schemaOriginal := range schemas {
305 matchedPolicies := getMatchingPolicy(schemaOriginal, matchedPolicies)
306 if len(matchedPolicies) == 0 {
307 continue
308 }
309 schemaCopy := *schemaOriginal
310 schemaCopy.Actions = filterActions(schemaOriginal, nobodyPolicies, matchedPolicies)
311 var matchedPoliciesNames []string
312 for _, policy := range matchedPolicies {
313 if policy.Action == "*" {
314 matchedPoliciesNames = allPoliciesNames
315 break
316 }
317 matchedPoliciesNames = append(matchedPoliciesNames, policy.Action)
318 }
319 schemasWithPolicy = append(schemasWithPolicy, &SchemaWithPolicy{&schemaCopy, matchedPoliciesNames})
320 }
321 return schemasWithPolicy
322}
323
324func getMatchingPolicy(schemaUsed *schema.Schema, policies []*schema.Policy) []*schema.Policy {
325 var matchedPolicies []*schema.Policy

Callers 2

template_test.goFile · 0.85
doTemplateFunction · 0.85

Calls 3

filterPoliciesFunction · 0.85
getMatchingPolicyFunction · 0.85
filterActionsFunction · 0.85

Tested by

no test coverage detected