pub struct UserIdentity {
pub id: String,
pub name: String,
pub tier: ServiceTier,
}Expand description
Per-request principal carried from transport into tool dispatch.
Why: Every inbound request (CLI, API call, TUI keystroke) arrives with some
notion of “who is asking”. Modeling it as a single UserIdentity value
means the tool dispatch layer doesn’t have to care which transport produced
the request, and unit tests can construct one without spinning up a transport.
What: id is the transport-native identifier; name is a human-readable
label for logging; tier is the privilege bucket enforced by can_access_tier.
Test: default_is_local_cli_all, plus indirect coverage via can_access_tier cases.
Fields§
§id: StringTransport-native identifier (e.g. "cli", "api", Slack "U…").
name: StringHuman-readable label, used only for logging.
tier: ServiceTierPrivilege tier enforced at dispatch.
Implementations§
Source§impl UserIdentity
impl UserIdentity
Sourcepub fn new(
id: impl Into<String>,
name: impl Into<String>,
tier: ServiceTier,
) -> Self
pub fn new( id: impl Into<String>, name: impl Into<String>, tier: ServiceTier, ) -> Self
Construct a new identity with a given tier.
Why: Transport layers need to mint identities with custom IDs per
inbound request without hand-rolling the struct literal.
What: Helper constructor; no validation beyond moving fields.
Test: new_constructs_with_fields.
Sourcepub fn can_access_tier(&self, restricted: &[ServiceTier]) -> bool
pub fn can_access_tier(&self, restricted: &[ServiceTier]) -> bool
Whether this identity may invoke a tool whose restricted_tiers list
is restricted.
Why: Tools express restrictions as an inverted list — they name the
tiers that are NOT allowed to call them — because that reads naturally
in config files (restricted_tiers = ["read_only"] blocks one tier).
An empty restriction list always permits access.
What: Returns true if restricted is empty, or if self.tier is not
present in restricted. Check is membership-based, NOT ordering-based.
Test: can_access_tier_empty_always_allows, can_access_tier_blocks_listed_tier,
can_access_tier_allows_other_tiers.
Trait Implementations§
Source§impl Clone for UserIdentity
impl Clone for UserIdentity
Source§fn clone(&self) -> UserIdentity
fn clone(&self) -> UserIdentity
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UserIdentity
impl Debug for UserIdentity
Source§impl Default for UserIdentity
impl Default for UserIdentity
Source§impl<'de> Deserialize<'de> for UserIdentity
impl<'de> Deserialize<'de> for UserIdentity
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for UserIdentity
impl RefUnwindSafe for UserIdentity
impl Send for UserIdentity
impl Sync for UserIdentity
impl Unpin for UserIdentity
impl UnsafeUnpin for UserIdentity
impl UnwindSafe for UserIdentity
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more