Skip to main content

hanzo_client/apis/
authz_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_authz_health`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAuthzHealthError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_authz_readyz`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAuthzReadyzError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_authz_check`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostAuthzCheckError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// Reports that the authz process is up. Unauthenticated by design and never org-scoped: it answers while every tenant's enforcer is still cold, because a probe that needed a tenant would fail for reasons that have nothing to do with the process being alive.
41pub async fn get_authz_health(configuration: &configuration::Configuration, ) -> Result<(), Error<GetAuthzHealthError>> {
42
43    let uri_str = format!("{}/v1/authz/health", configuration.base_path);
44    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46    if let Some(ref user_agent) = configuration.user_agent {
47        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
48    }
49    if let Some(ref token) = configuration.bearer_access_token {
50        req_builder = req_builder.bearer_auth(token.to_owned());
51    };
52
53    let req = req_builder.build()?;
54    let resp = configuration.client.execute(req).await?;
55
56    let status = resp.status();
57
58    if !status.is_client_error() && !status.is_server_error() {
59        Ok(())
60    } else {
61        let content = resp.text().await?;
62        let entity: Option<GetAuthzHealthError> = serde_json::from_str(&content).ok();
63        Err(Error::ResponseError(ResponseContent { status, content, entity }))
64    }
65}
66
67/// Reports that the authz process is ready to serve decisions. Unauthenticated and not org-scoped, for the same reason health is: readiness is a property of this process, not of any one tenant's policy set.
68pub async fn get_authz_readyz(configuration: &configuration::Configuration, ) -> Result<(), Error<GetAuthzReadyzError>> {
69
70    let uri_str = format!("{}/v1/authz/readyz", configuration.base_path);
71    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
72
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76    if let Some(ref token) = configuration.bearer_access_token {
77        req_builder = req_builder.bearer_auth(token.to_owned());
78    };
79
80    let req = req_builder.build()?;
81    let resp = configuration.client.execute(req).await?;
82
83    let status = resp.status();
84
85    if !status.is_client_error() && !status.is_server_error() {
86        Ok(())
87    } else {
88        let content = resp.text().await?;
89        let entity: Option<GetAuthzReadyzError> = serde_json::from_str(&content).ok();
90        Err(Error::ResponseError(ResponseContent { status, content, entity }))
91    }
92}
93
94/// Answers one policy question — may this subject take this action on this object — against the CALLER'S OWN org policy set, and answers it with a bare allow/deny.  The org comes from the gateway-minted X-Org-Id and picks the per-org enforcer, so a decision is always rendered by that tenant's policies and never by another's. A request carrying no org is refused rather than answered from a shared or default set: collapsing tenants together is the one failure a policy engine must not have.  Body: {sub, obj, act}, all three required. The reply echoes them beside `allow` so a cached or logged decision carries the question it answered.
95pub async fn post_authz_check(configuration: &configuration::Configuration, ) -> Result<(), Error<PostAuthzCheckError>> {
96
97    let uri_str = format!("{}/v1/authz/check", configuration.base_path);
98    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
99
100    if let Some(ref user_agent) = configuration.user_agent {
101        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
102    }
103    if let Some(ref token) = configuration.bearer_access_token {
104        req_builder = req_builder.bearer_auth(token.to_owned());
105    };
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111
112    if !status.is_client_error() && !status.is_server_error() {
113        Ok(())
114    } else {
115        let content = resp.text().await?;
116        let entity: Option<PostAuthzCheckError> = serde_json::from_str(&content).ok();
117        Err(Error::ResponseError(ResponseContent { status, content, entity }))
118    }
119}
120