(principal string, policies []*schema.Policy, schemas []*schema.Schema)
| 287 | } |
| 288 | |
| 289 | func 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 | |
| 324 | func getMatchingPolicy(schemaUsed *schema.Schema, policies []*schema.Policy) []*schema.Policy { |
| 325 | var matchedPolicies []*schema.Policy |
no test coverage detected