MCPcopy Index your code
hub / github.com/coder/coder / intersectAllow

Function intersectAllow

coderd/rbac/allowlist.go:244–272  ·  view source on GitHub ↗

intersectAllow returns the set of permit entries that satisfy both the scope element and the database allow list.

(scopeElem AllowListElement, dbList []AllowListElement)

Source from the content-addressed store, hash-verified

242// intersectAllow returns the set of permit entries that satisfy both the scope
243// element and the database allow list.
244func intersectAllow(scopeElem AllowListElement, dbList []AllowListElement) []AllowListElement {
245 // Scope element is wildcard -> intersection is db list.
246 if scopeElem.Type == policy.WildcardSymbol && scopeElem.ID == policy.WildcardSymbol {
247 return dbList
248 }
249
250 result := make([]AllowListElement, 0)
251 for _, dbElem := range dbList {
252 // DB entry wildcard -> keep scope element.
253 if dbElem.Type == policy.WildcardSymbol && dbElem.ID == policy.WildcardSymbol {
254 result = append(result, scopeElem)
255 continue
256 }
257
258 if !typeMatches(scopeElem.Type, dbElem.Type) {
259 continue
260 }
261
262 if !idMatches(scopeElem.ID, dbElem.ID) {
263 continue
264 }
265
266 result = append(result, AllowListElement{
267 Type: intersectType(scopeElem.Type, dbElem.Type),
268 ID: intersectID(scopeElem.ID, dbElem.ID),
269 })
270 }
271 return result
272}
273
274func typeMatches(scopeType, dbType string) bool {
275 return scopeType == dbType || scopeType == policy.WildcardSymbol || dbType == policy.WildcardSymbol

Callers 1

IntersectAllowListsFunction · 0.85

Calls 4

typeMatchesFunction · 0.85
idMatchesFunction · 0.85
intersectTypeFunction · 0.85
intersectIDFunction · 0.85

Tested by

no test coverage detected