use gatewarden::{GatewardenConfig, GatewardenError, LicenseManager};
use std::time::Duration;
const KEYGEN_ACCOUNT_ID: &str = "00000000-0000-0000-0000-000000000000";
const KEYGEN_PUBLIC_KEY: &str = "0000000000000000000000000000000000000000000000000000000000000000";
fn main() {
let license_key = std::env::var("LICENSE_KEY").expect("Set LICENSE_KEY environment variable");
let config = GatewardenConfig {
app_name: "example-app",
feature_name: "pro",
account_id: KEYGEN_ACCOUNT_ID,
public_key_hex: KEYGEN_PUBLIC_KEY,
required_entitlements: &["PRO_FEATURE"],
user_agent_product: "example-app",
cache_namespace: "example-app",
offline_grace: Duration::from_secs(24 * 60 * 60), };
let manager = match LicenseManager::new(config) {
Ok(m) => m,
Err(e) => {
eprintln!("Configuration error: {}", e);
std::process::exit(1);
}
};
match manager.validate_key(&license_key) {
Ok(result) => {
if result.valid {
println!("✓ License valid!");
println!(" Entitlements: {:?}", result.state.entitlements);
println!(" From cache: {}", result.from_cache);
if let Some(expires) = result.state.expires_at {
println!(" Expires: {}", expires);
}
} else {
println!("✗ License invalid");
}
}
Err(e) => {
match &e {
GatewardenError::InvalidLicense => {
eprintln!("License is invalid or expired");
}
GatewardenError::EntitlementMissing { code } => {
eprintln!("License missing required entitlement: {}", code);
}
GatewardenError::SignatureInvalid => {
eprintln!("SECURITY: Response signature verification failed!");
}
GatewardenError::KeygenTransport(_) => {
eprintln!("Network error - trying offline cache...");
}
_ => {
eprintln!("Validation error: {}", e);
}
}
std::process::exit(1);
}
}
}