#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
#[derive(Clone, Copy)]
pub struct Settings<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for Settings<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Settings")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> Settings<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
#[must_use]
pub fn in_org(mut self, org_id: Uuid) -> Self {
self.scope.org_id = Some(org_id);
self
}
#[must_use]
pub fn for_tenant(mut self, tenant_id: Uuid) -> Self {
self.scope.tenant_id = Some(tenant_id);
self
}
pub async fn get_org(&self) -> Result<models::SecuritySettings, AxiamError> {
let org_id = self.scope.org(self.client, "settings.get_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.get_org",
verb: Verb::Get,
path_template: "/api/v1/organizations/{org_id}/settings",
path: format!("/api/v1/organizations/{org_id}/settings"),
query: &query,
};
self.client
.management_send::<_, models::SecuritySettings>(call, None::<&()>)
.await
}
pub async fn set_org(
&self,
body: &models::SetOrgSettings,
) -> Result<models::SecuritySettings, AxiamError> {
let org_id = self.scope.org(self.client, "settings.set_org")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.set_org",
verb: Verb::Put,
path_template: "/api/v1/organizations/{org_id}/settings",
path: format!("/api/v1/organizations/{org_id}/settings"),
query: &query,
};
self.client
.management_send::<_, models::SecuritySettings>(call, Some(body))
.await
}
pub async fn get_effective(&self) -> Result<models::SecuritySettings, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.get_effective",
verb: Verb::Get,
path_template: "/api/v1/settings",
path: "/api/v1/settings".to_string(),
query: &query,
};
self.client
.management_send::<_, models::SecuritySettings>(call, None::<&()>)
.await
}
pub async fn set_effective(
&self,
body: &models::TenantSettingsOverride,
) -> Result<models::SecuritySettings, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.set_effective",
verb: Verb::Put,
path_template: "/api/v1/settings",
path: "/api/v1/settings".to_string(),
query: &query,
};
self.client
.management_send::<_, models::SecuritySettings>(call, Some(body))
.await
}
pub async fn get_tenant_override(&self) -> Result<models::TenantSettingsOverride, AxiamError> {
let tenant_id = self
.scope
.tenant(self.client, "settings.get_tenant_override")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.get_tenant_override",
verb: Verb::Get,
path_template: "/api/v1/tenants/{tenant_id}/settings",
path: format!("/api/v1/tenants/{tenant_id}/settings"),
query: &query,
};
self.client
.management_send::<_, models::TenantSettingsOverride>(call, None::<&()>)
.await
}
pub async fn set_tenant_override(
&self,
body: &models::TenantSettingsOverride,
) -> Result<models::TenantSettingsOverride, AxiamError> {
let tenant_id = self
.scope
.tenant(self.client, "settings.set_tenant_override")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.set_tenant_override",
verb: Verb::Put,
path_template: "/api/v1/tenants/{tenant_id}/settings",
path: format!("/api/v1/tenants/{tenant_id}/settings"),
query: &query,
};
self.client
.management_send::<_, models::TenantSettingsOverride>(call, Some(body))
.await
}
pub async fn delete_tenant_override(&self) -> Result<(), AxiamError> {
let tenant_id = self
.scope
.tenant(self.client, "settings.delete_tenant_override")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "settings.delete_tenant_override",
verb: Verb::Delete,
path_template: "/api/v1/tenants/{tenant_id}/settings",
path: format!("/api/v1/tenants/{tenant_id}/settings"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
}