ContainsValue
less than a minute
The ContainsValue converter checks if a slice/array contains a specific value.
Syntax: ContainsValue(slice, value)
- slice: the array/list field to search
- value: the value to search for
Input
{
"_type": "log",
"body": "User permissions check",
"resource": {...},
"attributes": {
"user_roles": ["admin", "editor", "viewer"],
"required_role": "admin",
"invalid_role": "superuser"
}
}
Statement
set(attributes["has_admin"], ContainsValue(attributes["user_roles"], attributes["required_role"]))
set(attributes["has_superuser"], ContainsValue(attributes["user_roles"], attributes["invalid_role"]))
Output
{
"_type": "log",
"body": "User permissions check",
"resource": {...},
"attributes": {
"user_roles": ["admin", "editor", "viewer"],
"required_role": "admin",
"invalid_role": "superuser",
"has_admin": true,
"has_superuser": false
}
}
The ContainsValue function correctly identified whether the array contains the specified values.