scute.local.decide_locally evaluates a check against a copy of the app's policy, with no network call. It gives the same answers as Scute's engine for everything the policy knows; the SDK's tests run the engine's shared conformance vectors. When it cannot decide, it answers "unknown" and you ask the API.
from scute.local import decide_locallyd = decide_locally( policy, roles=["clerk"], action="approve", resource={"type": "invoice", "attributes": {"amount": 4200}},)if d.decision == "unknown": d = scute.authz.check(user_id=user_id, action="approve", resource="invoice:42")Getting the policy#
The SDK has no method to fetch or verify the snapshot. Read it with the secret key from GET /v1/apps/:app_id/authz/snapshot. The answer has version and token, a JWT signed with the app's keys (verify it against /v1/auth/:app_id/.well-known/jwks.json). Its typ claim is scute-authz-snapshot and its policy claim is the policy to pass to decide_locally.
snapshot = scute.request("GET", scute.apps_path("/authz/snapshot"))# verify snapshot["token"] with the app's JWKS, then:policy = claims["policy"]Re-read it before the token's exp. The user's roles are not in the snapshot: pass the roles you hold for the user in roles.
Signature#
decide_locally(policy, *, roles, action, resource=None, user=None, context=None, now=None, strict=False) -> LocalDecisionConditions also see context.now, context.hour_utc and context.weekday_utc (monday to sunday), derived from now.
LocalDecision#
A frozen dataclass.
| Field | Type |
|---|---|
| decision | "allow", "deny", "allow_with_step_up", "allow_with_approval" or "unknown" |
| reason | str |
| permission | str or None |
| roles | tuple[str, ...]: the roles that granted it |
| allowed | property, True only for "allow" |
Reasons#
| Reason | Decision |
|---|---|
| role_grant | allow |
| verification_required | allow_with_step_up |
| approval_required | allow_with_approval |
| impersonating | deny: the permission is blocked while impersonating and context.impersonated is set |
| unknown_permission | deny: no such permission |
| permission_disabled | deny |
| condition_failed | deny |
| no_role_grants_permission | deny |
| needs_server | unknown |
When the answer is unknown#
decide_locally answers unknown with reason needs_server when:
- No role grants the permission, a key is given, and a role on objects of that type grants it (roles on one object live on the server).
- A condition reads an attribute you did not pass that may exist on the server (user.*, or resource.* when a key is given), and strict is False.
In both cases call scute.authz.check.
Conditions#
scute.local.evaluate_condition(condition, attrs, may_exist_elsewhere=None) evaluates one condition and returns True, False or "unknown". Operators: all, any, not, exists, eq, ne, lt, lte, gt, gte, in, contains, starts_with. Booleans are never equal to numbers, and None counts as missing.
from scute.local import evaluate_conditionevaluate_condition({"gt": [{"var": "resource.amount"}, 1000]}, {"resource": {"amount": 4200}}) # True