spiral-sdk 0.1.10

Rust SDK for Spiral resource and table APIs
Documentation
//! Workload identity handles.
use crate::ids::WorkloadId;
use crate::resources::workload::{
    CreateWorkloadKeyRequest, CreateWorkloadKeyResponse, CreateWorkloadPolicyRequest,
    CreateWorkloadPolicyResponse, Workload as WorkloadInfo, WorkloadKey, WorkloadPolicyResponse,
};
use crate::{Client, Error, List};

/// A workload identity bound to an authenticated connection.
#[derive(Debug, Clone)]
pub struct Workload {
    client: Client,
    id: WorkloadId,
}
impl Client {
    /// Select a workload without making a network request.
    pub fn workload(&self, id: impl Into<WorkloadId>) -> Workload {
        Workload {
            client: self.clone(),
            id: id.into(),
        }
    }
}
impl Workload {
    /// Stable workload identifier.
    pub fn id(&self) -> &WorkloadId {
        &self.id
    }
    /// Read workload metadata.
    pub async fn get(&self) -> Result<WorkloadInfo, Error> {
        Ok(self
            .client
            .workloads()
            .read_workload(self.id.to_string())
            .await?)
    }
    /// Deactivate the workload and revoke all of its credentials.
    pub async fn deactivate(&self) -> Result<(), Error> {
        Ok(self
            .client
            .workloads()
            .deactivate_workload(self.id.to_string())
            .await?)
    }
    /// List public authentication keys.
    pub fn keys(&self) -> List<'_, WorkloadKey> {
        self.client
            .workloads()
            .list_keys_list(self.id.to_string(), Default::default())
    }
    /// Register a public JWK with a key ID.
    pub async fn add_key(
        &self,
        request: CreateWorkloadKeyRequest,
    ) -> Result<CreateWorkloadKeyResponse, Error> {
        Ok(self
            .client
            .workloads()
            .add_key(self.id.to_string(), request)
            .await?)
    }
    /// Remove a public authentication key.
    pub async fn remove_key(&self, id: &str) -> Result<(), Error> {
        Ok(self
            .client
            .workloads()
            .remove_key(self.id.to_string(), id.to_owned())
            .await?)
    }
    /// List policies admitting external workload identities.
    pub fn policies(&self) -> List<'_, WorkloadPolicyResponse> {
        self.client
            .workloads()
            .list_policies_list(self.id.to_string(), Default::default())
    }
    /// Add an external identity trust policy.
    pub async fn create_policy(
        &self,
        request: CreateWorkloadPolicyRequest,
    ) -> Result<CreateWorkloadPolicyResponse, Error> {
        Ok(self
            .client
            .workloads()
            .create_policy(self.id.to_string(), request)
            .await?)
    }
}