pub struct LicenseValidator { /* private fields */ }Expand description
Validates PhyTrace license tokens
Supports:
- JWT token parsing and signature verification
- Expiry checking with configurable grace period
- Dev mode bypass for local development
- Online validation via PhyCloud endpoint
§Example
use phytrace_sdk::core::license::{LicenseValidator, LicenseStatus};
#[tokio::main]
async fn main() {
let validator = LicenseValidator::new(
Some("eyJhbG...".to_string()),
Some("https://api.phycloud.io".to_string()),
72,
);
let status = validator.validate();
match status {
LicenseStatus::Valid => println!("Full access"),
LicenseStatus::GracePeriod => println!("Grace period - events quarantined"),
LicenseStatus::DevMode => println!("Dev mode - no restrictions"),
_ => println!("License invalid"),
}
}Implementations§
Source§impl LicenseValidator
impl LicenseValidator
Sourcepub fn new(
license_token: Option<String>,
endpoint: Option<String>,
grace_period_hours: i64,
) -> Self
pub fn new( license_token: Option<String>, endpoint: Option<String>, grace_period_hours: i64, ) -> Self
Create a new license validator
§Arguments
license_token- JWT license token from PhyWare customer portalendpoint- PhyCloud endpoint for online validationgrace_period_hours- Hours to allow offline operation (default 72)
Sourcepub fn is_dev_mode(&self) -> bool
pub fn is_dev_mode(&self) -> bool
Return true if running in dev mode
Sourcepub async fn current_status(&self) -> LicenseStatus
pub async fn current_status(&self) -> LicenseStatus
Get the current license status
Sourcepub fn validate(&self) -> LicenseStatus
pub fn validate(&self) -> LicenseStatus
Validate the license token (synchronous, offline check)
Returns the validation status
Sourcepub async fn validate_online(&self) -> LicenseStatus
pub async fn validate_online(&self) -> LicenseStatus
Validate license against PhyCloud endpoint (async, online check)
This method should be called periodically (e.g., hourly) to:
- Verify tenant status hasn’t been revoked
- Check usage against limits
- Refresh token if nearing expiry
Sourcepub async fn get_license_metadata(&self) -> LicenseMetadata
pub async fn get_license_metadata(&self) -> LicenseMetadata
Get license metadata for event injection
Sourcepub fn require_valid(&self) -> Result<(), LicenseError>
pub fn require_valid(&self) -> Result<(), LicenseError>
Require a valid license, returning an error if not valid
Auto Trait Implementations§
impl !Freeze for LicenseValidator
impl !RefUnwindSafe for LicenseValidator
impl Send for LicenseValidator
impl Sync for LicenseValidator
impl Unpin for LicenseValidator
impl !UnwindSafe for LicenseValidator
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