intersectAllow returns the set of permit entries that satisfy both the scope element and the database allow list.
(scopeElem AllowListElement, dbList []AllowListElement)
| 242 | // intersectAllow returns the set of permit entries that satisfy both the scope |
| 243 | // element and the database allow list. |
| 244 | func 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 | |
| 274 | func typeMatches(scopeType, dbType string) bool { |
| 275 | return scopeType == dbType || scopeType == policy.WildcardSymbol || dbType == policy.WildcardSymbol |
no test coverage detected