use anyhow::Result;
use crate::Client;
pub struct Policies {
pub client: Client,
}
impl Policies {
#[doc(hidden)]
pub fn new(client: Client) -> Self {
Policies { client }
}
pub async fn list(
&self,
type_: &str,
status: &str,
expand: &str,
) -> Result<Vec<crate::types::Policy>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !expand.is_empty() {
query_args.push(("expand".to_string(), expand.to_string()));
}
if !status.is_empty() {
query_args.push(("status".to_string(), status.to_string()));
}
if !type_.is_empty() {
query_args.push(("type".to_string(), type_.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/api/v1/policies?{}", query_);
self.client.get(&url, None).await
}
pub async fn list_all(
&self,
type_: &str,
status: &str,
expand: &str,
) -> Result<Vec<crate::types::Policy>> {
let mut query_args: Vec<(String, String)> = Default::default();
if !expand.is_empty() {
query_args.push(("expand".to_string(), expand.to_string()));
}
if !status.is_empty() {
query_args.push(("status".to_string(), status.to_string()));
}
if !type_.is_empty() {
query_args.push(("type".to_string(), type_.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/api/v1/policies?{}", query_);
self.client.get_all_pages(&url, None).await
}
pub async fn create_policy(
&self,
activate: bool,
body: &crate::types::Policy,
) -> Result<crate::types::Policy> {
let mut query_args: Vec<(String, String)> = Default::default();
if activate {
query_args.push(("activate".to_string(), activate.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!("/api/v1/policies?{}", query_);
self.client
.post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
pub async fn get_policy(&self, policy_id: &str, expand: &str) -> Result<crate::types::Policy> {
let mut query_args: Vec<(String, String)> = Default::default();
if !expand.is_empty() {
query_args.push(("expand".to_string(), expand.to_string()));
}
let query_ = serde_urlencoded::to_string(&query_args).unwrap();
let url = format!(
"/api/v1/policies/{}?{}",
crate::progenitor_support::encode_path(policy_id),
query_
);
self.client.get(&url, None).await
}
pub async fn update_policy(
&self,
policy_id: &str,
body: &crate::types::Policy,
) -> Result<crate::types::Policy> {
let url = format!(
"/api/v1/policies/{}",
crate::progenitor_support::encode_path(policy_id),
);
self.client
.put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
pub async fn delete_policy(&self, policy_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}",
crate::progenitor_support::encode_path(policy_id),
);
self.client.delete(&url, None).await
}
pub async fn activate_policy(&self, policy_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}/lifecycle/activate",
crate::progenitor_support::encode_path(policy_id),
);
self.client.post(&url, None).await
}
pub async fn deactivate_policy(&self, policy_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}/lifecycle/deactivate",
crate::progenitor_support::encode_path(policy_id),
);
self.client.post(&url, None).await
}
pub async fn list_policy_rules(
&self,
policy_id: &str,
) -> Result<Vec<crate::types::PolicyRule>> {
let url = format!(
"/api/v1/policies/{}/rules",
crate::progenitor_support::encode_path(policy_id),
);
self.client.get(&url, None).await
}
pub async fn list_all_policy_rules(
&self,
policy_id: &str,
) -> Result<Vec<crate::types::PolicyRule>> {
let url = format!(
"/api/v1/policies/{}/rules",
crate::progenitor_support::encode_path(policy_id),
);
self.client.get_all_pages(&url, None).await
}
pub async fn create_policy_rule(
&self,
policy_id: &str,
body: &crate::types::PolicyRule,
) -> Result<crate::types::PolicyRule> {
let url = format!(
"/api/v1/policies/{}/rules",
crate::progenitor_support::encode_path(policy_id),
);
self.client
.post(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
pub async fn get_policy_rule(
&self,
policy_id: &str,
rule_id: &str,
) -> Result<crate::types::PolicyRule> {
let url = format!(
"/api/v1/policies/{}/rules/{}",
crate::progenitor_support::encode_path(policy_id),
crate::progenitor_support::encode_path(rule_id),
);
self.client.get(&url, None).await
}
pub async fn update_policy_rule(
&self,
policy_id: &str,
rule_id: &str,
body: &crate::types::PolicyRule,
) -> Result<crate::types::PolicyRule> {
let url = format!(
"/api/v1/policies/{}/rules/{}",
crate::progenitor_support::encode_path(policy_id),
crate::progenitor_support::encode_path(rule_id),
);
self.client
.put(&url, Some(reqwest::Body::from(serde_json::to_vec(body)?)))
.await
}
pub async fn delete_policy_rule(&self, policy_id: &str, rule_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}/rules/{}",
crate::progenitor_support::encode_path(policy_id),
crate::progenitor_support::encode_path(rule_id),
);
self.client.delete(&url, None).await
}
pub async fn activate_policy_rule(&self, policy_id: &str, rule_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}/rules/{}/lifecycle/activate",
crate::progenitor_support::encode_path(policy_id),
crate::progenitor_support::encode_path(rule_id),
);
self.client.post(&url, None).await
}
pub async fn deactivate_policy_rule(&self, policy_id: &str, rule_id: &str) -> Result<()> {
let url = format!(
"/api/v1/policies/{}/rules/{}/lifecycle/deactivate",
crate::progenitor_support::encode_path(policy_id),
crate::progenitor_support::encode_path(rule_id),
);
self.client.post(&url, None).await
}
}