pub struct ApiKey {
pub key_id: String,
pub secret_hash: String,
pub service_account: String,
pub description: Option<String>,
pub created_at: SystemTime,
pub expires_at: Option<SystemTime>,
pub last_used_at: Option<SystemTime>,
pub revoked: bool,
pub allowed_ips: Vec<String>,
pub permissions: Vec<String>,
}Expand description
API Key for service authentication
§Security Note
This struct implements a custom Debug that redacts the secret_hash field to prevent accidental leakage to logs.
Fields§
§key_id: StringKey identifier (public, used for lookup)
secret_hash: StringHashed secret (never store plaintext)
service_account: StringService account this key belongs to
description: Option<String>Human-readable description
created_at: SystemTimeWhen the key was created
expires_at: Option<SystemTime>When the key expires (None = never)
last_used_at: Option<SystemTime>When the key was last used
revoked: boolWhether the key is revoked
allowed_ips: Vec<String>IP allowlist (empty = all IPs allowed)
permissions: Vec<String>Permissions granted to this key
Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn generate(
service_account: &str,
description: Option<&str>,
expires_in: Option<Duration>,
permissions: Vec<String>,
) -> ServiceAuthResult<(Self, String)>
pub fn generate( service_account: &str, description: Option<&str>, expires_in: Option<Duration>, permissions: Vec<String>, ) -> ServiceAuthResult<(Self, String)>
Generate a new API key
Sourcepub fn parse_key(key: &str) -> ServiceAuthResult<(String, String)>
pub fn parse_key(key: &str) -> ServiceAuthResult<(String, String)>
Parse an API key string and extract components
Sourcepub fn verify_secret(&self, secret: &str) -> bool
pub fn verify_secret(&self, secret: &str) -> bool
Verify a secret against this key
Sourcepub fn is_ip_allowed(&self, ip: &str) -> bool
pub fn is_ip_allowed(&self, ip: &str) -> bool
Check if IP is allowed
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ApiKey
impl<'de> Deserialize<'de> for ApiKey
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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