pub struct Realm {
pub id: u32,
pub name: String,
pub status: RealmStatus,
pub enabled: bool,
pub expires_at: Option<u64>,
pub created_at: u64,
pub updated_at: Option<u64>,
pub secret_current: String,
pub secret_previous: Option<(String, u64)>,
}Expand description
Realm 是用于分离不同应用程序资源的虚拟概念。
Fields§
§id: u32DB 自增主键,起点 2^25 = 33554432
name: String§status: RealmStatus§enabled: bool§expires_at: Option<u64>§created_at: u64§updated_at: Option<u64>§secret_current: StringSHA256 hash of current secret (必填)
secret_previous: Option<(String, u64)>(hash, valid_until) for previous secret during rotation grace window
Implementations§
Source§impl Realm
impl Realm
Sourcepub async fn create(
name: String,
secret_hash: String,
) -> Result<Self, RealmError>
pub async fn create( name: String, secret_hash: String, ) -> Result<Self, RealmError>
Create a new realm in the database.
secret_hash is the SHA256 hash of the realm secret (must be non-empty).
Returns the Realm with its auto-generated id.
Sourcepub async fn upsert_managed(
id: u32,
name: String,
status: RealmStatus,
enabled: bool,
expires_at: Option<u64>,
secret_current: String,
secret_previous: Option<(String, u64)>,
) -> Result<Self, RealmError>
pub async fn upsert_managed( id: u32, name: String, status: RealmStatus, enabled: bool, expires_at: Option<u64>, secret_current: String, secret_previous: Option<(String, u64)>, ) -> Result<Self, RealmError>
Upsert a superv-managed realm with an externally assigned id.
Sourcepub async fn save(&mut self) -> Result<(), RealmError>
pub async fn save(&mut self) -> Result<(), RealmError>
Save (UPDATE) an existing realm to the database.
Sourcepub async fn get(id: u32) -> Result<Option<Self>, RealmError>
pub async fn get(id: u32) -> Result<Option<Self>, RealmError>
Get a realm by its auto-increment id.
Sourcepub async fn get_by_name(name: &str) -> Result<Option<Self>, RealmError>
pub async fn get_by_name(name: &str) -> Result<Option<Self>, RealmError>
Get a realm by name.
Sourcepub async fn get_all() -> Result<Vec<Self>, RealmError>
pub async fn get_all() -> Result<Vec<Self>, RealmError>
Get all realms.
Sourcepub async fn soft_delete(id: u32) -> Result<bool, RealmError>
pub async fn soft_delete(id: u32) -> Result<bool, RealmError>
Disable a realm without physically removing it.
pub fn is_expired(&self) -> bool
pub fn is_active(&self) -> bool
Source§impl Realm
Realm 验证相关实现
impl Realm
Realm 验证相关实现
Sourcepub async fn validate_realm(
realm_id: u32,
) -> Result<Realm, RealmValidationError>
pub async fn validate_realm( realm_id: u32, ) -> Result<Realm, RealmValidationError>
验证 Realm 是否可用(存在、未过期、状态正常)
返回 Ok(Realm) 表示 Realm 可用 返回 Err(RealmValidationError) 表示 Realm 不可用或数据库错误
Sourcepub fn map_validation_error(err: RealmValidationError) -> (u32, String)
pub fn map_validation_error(err: RealmValidationError) -> (u32, String)
Map a RealmValidationError to the appropriate HTTP status code and a human-readable error string (for backward-compatible callers).
RealmUnavailable→ (403, reason)StoreError→ (500, message)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Realm
impl<'de> Deserialize<'de> for Realm
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 Realm
impl RefUnwindSafe for Realm
impl Send for Realm
impl Sync for Realm
impl Unpin for Realm
impl UnsafeUnpin for Realm
impl UnwindSafe for Realm
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request