diff --git a/src/api/licenses.rs b/src/api/licenses.rs index 270cd70..ae424fc 100644 --- a/src/api/licenses.rs +++ b/src/api/licenses.rs @@ -170,7 +170,7 @@ impl Licenses { /// Get a license's activation code /// - /// Available until the license is activated or revoked. + /// Available until the license is activated or revoked; for an ephemeral license, until revoked. /// /// `GET /api/v1/licenses/{license_id}/activation-code`. /// diff --git a/src/models/issue_license_request.rs b/src/models/issue_license_request.rs index fec1527..e14a1ea 100644 --- a/src/models/issue_license_request.rs +++ b/src/models/issue_license_request.rs @@ -6,6 +6,12 @@ pub struct IssueLicenseRequest { /// Customer ID or alias pub customer_id: String, + /// Ephemeral, for CI and other short-lived installations: the activation code can be used + /// any number of times, each activation gets a license of this many hours (1 to 24) for the + /// installation activating, and nothing is refreshed. Not with `offline` or `validity_days`. + #[serde(skip_serializing_if = "Option::is_none")] + pub ephemeral_hours: Option, + /// Offline only. The installation's id as it reports it, up to 255 characters without /// spaces: the license names it (`aud`) and stays bound to it. Without one, the license is /// not tied to an installation. @@ -38,6 +44,7 @@ impl IssueLicenseRequest { pub fn new(customer_id: impl Into) -> Self { Self { customer_id: customer_id.into(), + ephemeral_hours: None, instance_id: None, offline: None, subscription_id: None, @@ -46,6 +53,13 @@ impl IssueLicenseRequest { } } + /// Sets `ephemeral_hours`. + #[must_use] + pub fn ephemeral_hours(mut self, ephemeral_hours: impl Into) -> Self { + self.ephemeral_hours = Some(ephemeral_hours.into()); + self + } + /// Sets `instance_id`. #[must_use] pub fn instance_id(mut self, instance_id: impl Into) -> Self { diff --git a/src/models/issue_license_response.rs b/src/models/issue_license_response.rs index 56af47e..ea03c93 100644 --- a/src/models/issue_license_response.rs +++ b/src/models/issue_license_response.rs @@ -7,6 +7,7 @@ use super::license::License; #[non_exhaustive] pub struct IssueLicenseResponse { /// Online: one-time code the customer enters in their installation to activate the license. + /// Ephemeral: the reusable code, e.g. a CI secret. #[serde(skip_serializing_if = "Option::is_none")] pub activation_code: Option, diff --git a/src/models/license.rs b/src/models/license.rs index 311a302..f40e7d8 100644 --- a/src/models/license.rs +++ b/src/models/license.rs @@ -18,6 +18,10 @@ pub struct License { pub customer_name: String, + /// Ephemeral: each activation of the reusable code gets a license of this many hours. + #[serde(skip_serializing_if = "Option::is_none")] + pub ephemeral_hours: Option, + /// Whether the activation code can still be retrieved: only until activation or revocation. pub has_activation_code: bool, @@ -77,6 +81,7 @@ impl License { created_at, customer_id: customer_id.into(), customer_name: customer_name.into(), + ephemeral_hours: None, has_activation_code, id: id.into(), instance_id: None, diff --git a/tests/api/licenses.rs b/tests/api/licenses.rs index 9d05682..5cd2d9f 100644 --- a/tests/api/licenses.rs +++ b/tests/api/licenses.rs @@ -6,7 +6,7 @@ async fn list() { let (client, requests) = mock( 200, Some("application/json"), - r#"{"data":[{"auto_issued":false,"created_at":"2023-12-31T23:59:59.999-05:30","customer_id":"customer_id_2","customer_name":"sample","has_activation_code":false,"id":"license_id_0","offline":false,"revoked_immediately":false,"status":"REVOKED","validity_days":-123456789}]}"#, + r#"{"data":[{"auto_issued":false,"created_at":"2023-12-31T23:59:59.999-05:30","customer_id":"customer_id_2","customer_name":"sample","has_activation_code":true,"id":"license_id_78","offline":false,"revoked_immediately":false,"status":"PENDING","validity_days":2147483647}]}"#, ); client.licenses().list(None).await.unwrap(); assert_eq!(*requests.lock().unwrap(), ["GET /api/v1/licenses"]); @@ -17,7 +17,7 @@ async fn create() { let (client, requests) = mock( 200, Some("application/json"), - r#"{"license":{"auto_issued":false,"created_at":"2023-12-31T23:59:59.999-05:30","customer_id":"customer_id_37","customer_name":"sample","has_activation_code":true,"id":"license_id_40","offline":true,"revoked_immediately":true,"status":"PENDING","validity_days":123456789}}"#, + r#"{"license":{"auto_issued":false,"created_at":"2023-12-31T23:59:59.999-05:30","customer_id":"customer_id_37","customer_name":"sample","has_activation_code":true,"id":"license_id_32","offline":true,"revoked_immediately":false,"status":"REVOKED","validity_days":2147483647}}"#, ); client .licenses() @@ -34,7 +34,7 @@ async fn retrieve() { let (client, requests) = mock( 200, Some("application/json"), - r#"{"auto_issued":false,"created_at":"2024-03-15T10:30:45.123+02:00","customer_id":"customer_id_79","customer_name":"sample","has_activation_code":false,"id":"license_id_90","offline":false,"revoked_immediately":true,"status":"PENDING","validity_days":-123456789}"#, + r#"{"auto_issued":false,"created_at":"2024-03-15T10:30:45.123+02:00","customer_id":"customer_id_79","customer_name":"sample","has_activation_code":true,"id":"license_id_13","offline":true,"revoked_immediately":false,"status":"PENDING","validity_days":-2147483648}"#, ); client.licenses().retrieve("license_id").await.unwrap(); assert_eq!( @@ -85,7 +85,7 @@ async fn revoke() { let (client, requests) = mock( 200, Some("application/json"), - r#"{"auto_issued":false,"created_at":"2024-03-15T10:30:45.123+02:00","customer_id":"customer_id_79","customer_name":"sample","has_activation_code":false,"id":"license_id_90","offline":false,"revoked_immediately":true,"status":"PENDING","validity_days":-123456789}"#, + r#"{"auto_issued":false,"created_at":"2024-03-15T10:30:45.123+02:00","customer_id":"customer_id_79","customer_name":"sample","has_activation_code":true,"id":"license_id_13","offline":true,"revoked_immediately":false,"status":"PENDING","validity_days":-2147483648}"#, ); client .licenses()