pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct PoliciesClient {
client: crate::client::Client,
}
impl PoliciesClient {
pub fn new(client: crate::client::Client) -> Self {
PoliciesClient { client }
}
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
}
pub async fn update_policy(
&self,
policy_id: String,
body: UpdatePolicyRequest,
) -> Result<serde_json::Value, crate::error::Error> {
let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
let body = serde_json::to_value(&body)?;
self.client
.request::<serde_json::Value>(reqwest::Method::PUT, &path, Some(&body), true)
.await
}
pub async fn delete_policy(
&self,
policy_id: String,
) -> Result<serde_json::Value, crate::error::Error> {
let path = format!("/v2/policies/{}", urlencoding::encode(&policy_id));
self.client
.request::<serde_json::Value>(reqwest::Method::DELETE, &path, None, true)
.await
}
pub async fn create_approval_decision(
&self,
approval_id: String,
body: CreateApprovalDecisionRequest,
) -> Result<CreateApprovalDecisionResponse, crate::error::Error> {
let path = format!(
"/v2/policy-approvals/{}/decisions",
urlencoding::encode(&approval_id)
);
let body = serde_json::to_value(&body)?;
self.client
.request::<CreateApprovalDecisionResponse>(
reqwest::Method::POST,
&path,
Some(&body),
true,
)
.await
}
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
}
pub async fn create_policy(
&self,
body: CreatePolicyRequest,
) -> Result<serde_json::Value, crate::error::Error> {
let path = String::from("/v2/policies");
let body = serde_json::to_value(&body)?;
self.client
.request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
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
}
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
}
}