pub struct PolicyBuilder { /* private fields */ }Expand description
Builder for creating Policy instances with a fluent API
§Examples
use core_policy::{PolicyBuilder, PolicyRuleBuilder, Action, Resource};
let policy = PolicyBuilder::new("admin-policy")
.add_rule_with(|rule| {
rule.for_peer("12D3KooWAlice...")
.allow(Action::All)
.on(Resource::All)
})
.add_rule_with(|rule| {
rule.for_peer("12D3KooWBob...")
.allow(Action::Read)
.on(Resource::File("/docs/*".into()))
})
.with_metadata("owner", "alice")
.build()
.unwrap();Implementations§
Source§impl PolicyBuilder
impl PolicyBuilder
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Create a new policy builder with default validity (30 days)
Sourcepub fn with_timestamp(self, timestamp: u64) -> Self
pub fn with_timestamp(self, timestamp: u64) -> Self
Set the policy issuance timestamp (Unix seconds).
Required for valid time-based policies. If not set, defaults to 0.
Sourcepub const fn valid_for(self, duration_secs: u64) -> Self
pub const fn valid_for(self, duration_secs: u64) -> Self
Set policy validity duration in seconds
Sourcepub fn add_rule_with<F>(self, f: F) -> Self
pub fn add_rule_with<F>(self, f: F) -> Self
Add a rule using a builder function
Sourcepub fn add_rule(self, rule: PolicyRule) -> Self
pub fn add_rule(self, rule: PolicyRule) -> Self
Add a pre-constructed rule
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PolicyBuilder
impl RefUnwindSafe for PolicyBuilder
impl Send for PolicyBuilder
impl Sync for PolicyBuilder
impl Unpin for PolicyBuilder
impl UnwindSafe for PolicyBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more