pub struct Machine {
pub id: String,
pub fingerprint: String,
pub name: Option<String>,
pub platform: Option<String>,
pub hostname: Option<String>,
pub cores: Option<i32>,
pub require_heartbeat: bool,
pub heartbeat_status: String,
pub heartbeat_duration: Option<i32>,
pub created: DateTime<Utc>,
pub updated: DateTime<Utc>,
}Fields§
§id: String§fingerprint: String§name: Option<String>§platform: Option<String>§hostname: Option<String>§cores: Option<i32>§require_heartbeat: bool§heartbeat_status: String§heartbeat_duration: Option<i32>§created: DateTime<Utc>§updated: DateTime<Utc>Implementations§
source§impl Machine
impl Machine
pub async fn deactivate(&self) -> Result<(), Error>
sourcepub async fn checkout(
&self,
options: &MachineCheckoutOpts,
) -> Result<MachineFile, Error>
pub async fn checkout( &self, options: &MachineCheckoutOpts, ) -> Result<MachineFile, Error>
Examples found in repository?
examples/checkout_machine.rs (line 30)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
async fn main() -> Result<(), Error> {
dotenv().ok();
config::set_config(KeygenConfig {
api_url: env::var("KEYGEN_API_URL").expect("KEYGEN_API_URL must be set"),
account: env::var("KEYGEN_ACCOUNT").expect("KEYGEN_ACCOUNT must be set"),
product: env::var("KEYGEN_PRODUCT").expect("KEYGEN_PRODUCT must be set"),
license_key: Some(env::var("KEYGEN_LICENSE_KEY").expect("KEYGEN_LICENSE_KEY must be set")),
public_key: Some(env::var("KEYGEN_PUBLIC_KEY").expect("KEYGEN_PUBLIC_KEY must be set")),
..KeygenConfig::default()
});
let config = config::get_config();
let fingerprint = machine_uid::get().unwrap_or("".into());
if let Ok(license) = keygen_rs::validate(&[fingerprint.clone()], &[]).await {
let machine = license.machine(&fingerprint).await?;
let options = MachineCheckoutOpts {
ttl: Some(chrono::Duration::days(7).num_seconds()),
include: None,
};
let machine_file = machine.checkout(&options).await?;
if machine_file.verify().is_ok() {
// the encryption secret for a machine file is the license key concatenated with the machine fingerprint
// https://keygen.sh/docs/api/cryptography/#cryptographic-lic-decrypt
let key = format!("{}{}", config.license_key.unwrap(), machine.fingerprint);
let dataset = machine_file.decrypt(&key)?;
println!("Machine checkout successful: {:?}", dataset);
}
} else {
println!("License validation failed");
};
Ok(())
}Trait Implementations§
source§impl<'de> Deserialize<'de> for Machine
impl<'de> Deserialize<'de> for Machine
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Machine
impl RefUnwindSafe for Machine
impl Send for Machine
impl Sync for Machine
impl Unpin for Machine
impl UnwindSafe for Machine
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)