dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

#[allow(unused_imports)]
use super::types::*;

/// Delegated client for policies operations. Signed operations are split into
/// init/complete pairs so the challenge can be signed on the user side.
#[derive(Clone)]
pub struct DelegatedPoliciesClient {
    client: crate::client::Client,
}

impl DelegatedPoliciesClient {
    pub fn new(client: crate::client::Client) -> Self {
        DelegatedPoliciesClient { client }
    }

    /// Retrieve information about a specific policy.
    pub async fn get_policy(
        &self,
        policy_id: String,
    ) -> Result<GetPolicyResponse, crate::error::Error> {
        let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
        self.client
            .request::<GetPolicyResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Starts delegated signing for updatePolicy: returns the challenge to sign.
    /// Pass the signed assertion to update_policy_complete with the same arguments.
    pub async fn update_policy_init(
        &self,
        policy_id: String,
        body: UpdatePolicyRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for updatePolicy: submits the signed challenge
    /// and issues the request.
    pub async fn update_policy_complete(
        &self,
        policy_id: String,
        body: UpdatePolicyRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<serde_json::Value>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }

    /// Starts delegated signing for deletePolicy: returns the challenge to sign.
    /// Pass the signed assertion to delete_policy_complete with the same arguments.
    pub async fn delete_policy_init(
        &self,
        policy_id: String,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
        self.client
            .create_user_action_challenge(reqwest::Method::DELETE, &path, None)
            .await
    }

    /// Finishes delegated signing for deletePolicy: submits the signed challenge
    /// and issues the request.
    pub async fn delete_policy_complete(
        &self,
        policy_id: String,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<serde_json::Value>(
                reqwest::Method::DELETE,
                &path,
                None,
                &user_action,
            )
            .await
    }

    /// Starts delegated signing for createApprovalDecision: returns the challenge to sign.
    /// Pass the signed assertion to create_approval_decision_complete with the same arguments.
    pub async fn create_approval_decision_init(
        &self,
        approval_id: String,
        body: CreateApprovalDecisionRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!(
            "/v2/policy-approvals/{}/decisions",
            urlencoding::encode(&approval_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for createApprovalDecision: submits the signed challenge
    /// and issues the request.
    pub async fn create_approval_decision_complete(
        &self,
        approval_id: String,
        body: CreateApprovalDecisionRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<CreateApprovalDecisionResponse, crate::error::Error> {
        let path = format!(
            "/v2/policy-approvals/{}/decisions",
            urlencoding::encode(&approval_id)
        );
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<CreateApprovalDecisionResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }

    /// Retrieve the list of policies on your organization.
    pub async fn list_policies(
        &self,
        query: Option<ListPoliciesQuery>,
    ) -> Result<ListPoliciesResponse, crate::error::Error> {
        let mut path = String::from("/v2/policies");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.status {
                q.push(format!("status={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListPoliciesResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Starts delegated signing for createPolicy: returns the challenge to sign.
    /// Pass the signed assertion to create_policy_complete with the same arguments.
    pub async fn create_policy_init(
        &self,
        body: CreatePolicyRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = String::from("/v2/policies");
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for createPolicy: submits the signed challenge
    /// and issues the request.
    pub async fn create_policy_complete(
        &self,
        body: CreatePolicyRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = String::from("/v2/policies");
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<serde_json::Value>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }

    /// Retrieve information about a specific approval request.
    pub async fn get_approval(
        &self,
        approval_id: String,
    ) -> Result<GetApprovalResponse, crate::error::Error> {
        let path = format!("/v2/policy-approvals/{}", urlencoding::encode(&approval_id));
        self.client
            .request::<GetApprovalResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieve the list of pending approval requests.
    pub async fn list_approvals(
        &self,
        query: Option<ListApprovalsQuery>,
    ) -> Result<ListApprovalsResponse, crate::error::Error> {
        let mut path = String::from("/v2/policy-approvals");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.status {
                q.push(format!("status={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.initiator_id {
                q.push(format!(
                    "initiatorId={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.approver_id {
                q.push(format!(
                    "approverId={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListApprovalsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }
}