Skip to main content

headless/
headless.rs

1//! Drive the full licensing flow without a UI.
2//!
3//! ```sh
4//! # Point at your Keygen account and pass a key:
5//! KEYGEN_ACCOUNT=<uuid> RUSTIFY_DEMO_KEY=<license-key> \
6//!   cargo run -p rustify-licensing --example headless
7//! ```
8//!
9//! With no `RUSTIFY_DEMO_KEY` it just prints the (persisted) fingerprint and reports
10//! `Locked` — no network call.
11
12use rustify_licensing::adapters::headless::check_blocking;
13use rustify_licensing::{KeygenProvider, LicenseConfig, LicenseState, StorageConfig};
14
15fn main() {
16    let storage = StorageConfig {
17        path: std::env::temp_dir().join("rustify-demo-license.env"),
18        dev_shadow: None,
19        env_key_var: Some("RUSTIFY_DEMO_KEY".into()),
20    };
21    let config = LicenseConfig {
22        // Your Keygen account id (a public UUID). Set it here or via KEYGEN_ACCOUNT.
23        account_id: std::env::var("KEYGEN_ACCOUNT")
24            .unwrap_or_else(|_| "YOUR_KEYGEN_ACCOUNT_ID".into()),
25        api_base: "https://api.keygen.sh/v1".into(),
26        grace_secs: 14 * 24 * 60 * 60,
27        storage,
28        buy_url: "https://example.com/#pricing".into(),
29    };
30
31    let provider = KeygenProvider::from_config(&config);
32    let mut state = LicenseState::load(&config.storage);
33    println!("fingerprint: {}", state.fingerprint);
34
35    if state.key.trim().is_empty() {
36        println!("no key set — export RUSTIFY_DEMO_KEY=<license-key> to test → status: Locked");
37        return;
38    }
39
40    let status = check_blocking(&config, &provider, &mut state, |line| println!("  … {line}"));
41    println!("status: {status:?}");
42}