OxL Reference

method DynHandle.setAs

set on behalf of p (a service acting for a user; the policy is evaluated for p).

Example:

oxl✓ checked in CI
dynamic Limits {
  rps: u32 = 100
}

policy Limits {
  allow set if caller.hasRole("Admin")
}

fn main() io {
  let l = Limits.get()
  let admin = Principal.User("ann", ["Admin"], Map.new(), false, none)
  let guest = Principal.User("bob", [], Map.new(), false, none)
  print("{l.rps.setAs(&admin, 200) is DynError}")
  print("{l.rps.setAs(&guest, 300) is DynError}")
  print("{l.rps.get()}")
}
Output
false
true
200
pub(api) fn setAs(p: &Principal, v: T, layer: DynScope = .Global) -> () | DynError where T: Serializable

Since. 1.0.0-beta

Parameters

NameType
p&Principal
vT
layerDynScope = .Global

Returns

()

Errors

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/dynconf.oxl:574

See also