mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 18:10:30 +08:00
fbce298f2b
SelfHostedProvider implements Provider trait for offline license verification
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
use crate::{CraftContext, LicenseInfo, error::LicenseError};
|
|
|
|
#[derive(Debug)]
|
|
pub struct LicenseStatus {
|
|
pub licensed: bool,
|
|
pub not_after: Option<i64>,
|
|
pub features: HashMap<String, bool>,
|
|
pub device_count: u32,
|
|
pub max_devices: u32,
|
|
pub heartbeat_due: Option<i64>,
|
|
}
|
|
|
|
pub struct ActivateResponse {
|
|
pub success: bool,
|
|
pub device_id: String,
|
|
pub license_payload: Vec<u8>,
|
|
}
|
|
|
|
pub struct HeartbeatResponse {
|
|
pub valid: bool,
|
|
pub lease_until: Option<i64>,
|
|
pub update_available: bool,
|
|
pub new_license_payload: Option<Vec<u8>>,
|
|
}
|
|
|
|
pub trait Provider: Send + Sync {
|
|
fn initialize(&mut self, ctx: &CraftContext, config_json: &str) -> Result<(), LicenseError>;
|
|
fn activate(&self, ctx: &CraftContext, license_key: &str) -> Result<ActivateResponse, LicenseError>;
|
|
fn check_license(&self, ctx: &CraftContext) -> Result<LicenseStatus, LicenseError>;
|
|
fn heartbeat(&self, ctx: &CraftContext) -> Result<HeartbeatResponse, LicenseError>;
|
|
fn has_feature(&self, ctx: &CraftContext, name: &str) -> bool;
|
|
fn release(&mut self) -> Result<(), LicenseError>;
|
|
fn get_license_info(&self, ctx: &CraftContext) -> LicenseInfo;
|
|
fn close(&mut self);
|
|
}
|