use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{ManagementClient, Result};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ByokKeyEnvelope {
pub provider_name: String,
pub kek_id: String,
pub key_prefix: String,
#[serde(default)]
pub api_base: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
#[serde(default)]
pub last_used_at: Option<DateTime<Utc>>,
#[serde(default)]
pub last_failure_at: Option<DateTime<Utc>>,
#[serde(default)]
pub last_failure_kind: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ByokKeyListResponse {
pub data: Vec<ByokKeyEnvelope>,
}
#[derive(Debug, Clone, Serialize)]
pub struct UpsertByokKeyRequest {
pub provider_name: String,
pub ciphertext_b64: String,
pub kek_id: String,
pub key_prefix: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub api_base: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpsertByokKeyResponse {
pub provider_name: String,
pub kek_id: String,
pub key_prefix: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteByokKeyResponse {
pub deleted: bool,
}
impl ManagementClient {
pub async fn list_byok_keys(&self) -> Result<ByokKeyListResponse> {
self.get_json("/v1/byok/keys").await
}
pub async fn upsert_byok_key(
&self,
body: &UpsertByokKeyRequest,
) -> Result<UpsertByokKeyResponse> {
self.post_json("/v1/byok/keys", body).await
}
pub async fn delete_byok_key(&self, provider: &str) -> Result<DeleteByokKeyResponse> {
let path = format!("/v1/byok/keys/{provider}");
self.delete_json(&path).await
}
}