#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct LicenseResource {
pub id: uuid::Uuid,
#[serde(rename = "type")]
pub resource_type: String,
pub attributes: LicenseAttributes,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct LicenseAttributes {
pub name: Option<String>,
pub key: Option<String>,
pub status: String,
pub expiry: Option<chrono::DateTime<chrono::Utc>>,
pub suspended: bool,
pub protected: bool,
pub uses: i32,
pub scheme: Option<String>,
pub encrypted: bool,
pub strict: bool,
pub floating: bool,
pub max_machines: Option<i32>,
pub max_uses: Option<i32>,
pub max_users: Option<i32>,
pub last_validated_at: Option<chrono::DateTime<chrono::Utc>>,
pub last_check_in_at: Option<chrono::DateTime<chrono::Utc>>,
pub last_check_out_at: Option<chrono::DateTime<chrono::Utc>>,
pub machines_count: i32,
pub metadata: serde_json::Value,
pub created: chrono::DateTime<chrono::Utc>,
pub updated: chrono::DateTime<chrono::Utc>,
}
#[cfg(test)]
mod tests {
use super::*;
fn representative_license_json() -> serde_json::Value {
serde_json::json!({
"type": "licenses",
"id": "01926b3e-0000-7000-8000-000000000000",
"attributes": {
"name": "Acme Corp",
"key": "lic-abc123",
"status": "ACTIVE",
"expiry": null,
"suspended": false,
"protected": false,
"uses": 0,
"scheme": null,
"encrypted": false,
"strict": false,
"floating": false,
"max_machines": null,
"max_uses": null,
"max_users": null,
"last_validated_at": null,
"last_check_in_at": null,
"last_check_out_at": null,
"machines_count": 0,
"metadata": {},
"created": "2026-01-01T00:00:00Z",
"updated": "2026-01-01T00:00:00Z",
}
})
}
#[test]
fn deserializes_representative_license_resource() {
let resource: LicenseResource =
serde_json::from_value(representative_license_json()).unwrap();
assert_eq!(resource.resource_type, "licenses");
assert_eq!(resource.attributes.name, Some("Acme Corp".to_string()));
assert_eq!(resource.attributes.key, Some("lic-abc123".to_string()));
assert_eq!(resource.attributes.status, "ACTIVE");
assert!(!resource.attributes.suspended);
assert_eq!(resource.attributes.uses, 0);
}
#[test]
fn rejects_a_json_object_with_a_relationships_field_gracefully() {
let mut json = representative_license_json();
json["relationships"] = serde_json::json!({ "policy": { "data": null } });
let resource: Result<LicenseResource, _> = serde_json::from_value(json);
assert!(resource.is_ok());
}
}