You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tldr: Introduce `having` on lists/maps, which acts like a `where` filter that also checks that the resulting list is not empty.
```coffee
my.collection.having( some condition ).all( ... )
```
**Problem**
As explained by @LittleSalkin1806 in #6633 (comment)
> If the bucket has no tags at all, the where clause will return an empty list, the values will take values from no existing key (empty list) and the all function will evaluate to true because there are no elements that violate the condition. This can lead to false positives in the compliance checks.
I ran into this same problem way too often myself! I've been working on a function to address this problem.
The `where` clause behaves like a traiditional `filter` in JS/TS and is close to SQL, so we wanted to keep their behavior/meaning. However, there is clearly a need for the combination, because this pattern happens way too often:
```coffee
collection.where( condition ) != empty
collection.where( condition ).otherCalls...
```
Using @LittleSalkin1806 's example:
```coffee
aws.s3.bucket.tags.where(key.downcase == 'dtit:sec:infosecclass') != empty
aws.s3.bucket.tags.where(key.downcase == 'dtit:sec:infosecclass').values.map(downcase).in([...])
```
**Solution**
This PR introduces the `having` keyword. It acts like `where` that also makes sure that the list is not empty:
```coffee
collection.having( condition ).otherCalls...
```
or with the above example:
```coffee
aws.s3.bucket.tags.having(key.downcase == 'dtit:sec:infosecclass').values.map(downcase).in([ ... ])
```
If the filtered list is empty, the query fails. If it is non-empty, it
uses the filtered values and looks at the next condition.
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
0 commit comments