Enforce a scoped action grant
Implement authorize(request, grant, now) -> bool. Request must have exactly tenant, audience, action, resource, destination, units. Grant must have exactly tenant, audience, actions, resources, destinations, max_units, expires. Identity and names are nonempty strings; units and max_units are nonnegative integers excluding booleans; now/expires are integers. Grant scopes are lists of nonempty strings. Allow only matching tenant/audience, allowed action/resource/destination, units <= max_units, and now < expires. Return False on malformed data. This assumes the grant and identity context are already authenticated by a trusted caller; it is not token validation.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputrequest tenant A, action draft, resource D1, destination local, units 3; grant A allows draft/D1/local with max_units 5 and expires 100; now 99
OutputTrue
Inputsame request at now 100
OutputFalse
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor