Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/licenses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down
14 changes: 14 additions & 0 deletions src/models/issue_license_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>,

/// 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.
Expand Down Expand Up @@ -38,6 +44,7 @@ impl IssueLicenseRequest {
pub fn new(customer_id: impl Into<String>) -> Self {
Self {
customer_id: customer_id.into(),
ephemeral_hours: None,
instance_id: None,
offline: None,
subscription_id: None,
Expand All @@ -46,6 +53,13 @@ impl IssueLicenseRequest {
}
}

/// Sets `ephemeral_hours`.
#[must_use]
pub fn ephemeral_hours(mut self, ephemeral_hours: impl Into<i32>) -> Self {
self.ephemeral_hours = Some(ephemeral_hours.into());
self
}

/// Sets `instance_id`.
#[must_use]
pub fn instance_id(mut self, instance_id: impl Into<String>) -> Self {
Expand Down
1 change: 1 addition & 0 deletions src/models/issue_license_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

Expand Down
5 changes: 5 additions & 0 deletions src/models/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32>,

/// Whether the activation code can still be retrieved: only until activation or revocation.
pub has_activation_code: bool,

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/api/licenses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -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()
Expand All @@ -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!(
Expand Down Expand Up @@ -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()
Expand Down