celv2: Add require_touchid{,_only}_with_cooldown_minutes functions #742
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds two new functions to the CELv2 environment:
require_touchid_with_cooldown_minutes(int)andrequire_touchid_only_with_cooldown_minutes(int)- these functions return the respective return values and also cache the response for the specified number of minutes, so that the user doesn't have to keep authorizing the same application repeatedly. This cache is in-memory only and can store up to 100 records.This is implemented by changing the return value of CELv2 expressions to be a new proto message called
Result, which stores both the usual enum result and the cooldown minutes time. The usual enum constants (ALLOWLIST,BLOCKLIST, etc.) are now mapped to instances ofReturnwith just thevaluefield set, the new functions return the message with the extra field populated too. This is because values in a ternary expression must have matching types and we want to be able to support expressions likeeuid == 0 ? require_touchid_only_with_cooldown_minutes(10) : ALLOWLIST