hanzo_client/apis/
entitlement_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetEntitlementError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetEntitlementOrgsByOrgError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostEntitlementOrgsByOrgError {
36 UnknownValue(serde_json::Value),
37}
38
39
40pub async fn get_entitlement(configuration: &configuration::Configuration, ) -> Result<models::ProjectionView, Error<GetEntitlementError>> {
42
43 let uri_str = format!("{}/v1/entitlement", 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 let content_type = resp
58 .headers()
59 .get("content-type")
60 .and_then(|v| v.to_str().ok())
61 .unwrap_or("application/octet-stream");
62 let content_type = super::ContentType::from(content_type);
63
64 if !status.is_client_error() && !status.is_server_error() {
65 let content = resp.text().await?;
66 match content_type {
67 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
68 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProjectionView`"))),
69 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ProjectionView`")))),
70 }
71 } else {
72 let content = resp.text().await?;
73 let entity: Option<GetEntitlementError> = serde_json::from_str(&content).ok();
74 Err(Error::ResponseError(ResponseContent { status, content, entity }))
75 }
76}
77
78pub async fn get_entitlement_orgs_by_org(configuration: &configuration::Configuration, org: &str) -> Result<models::EntitlementsView, Error<GetEntitlementOrgsByOrgError>> {
80 let p_org = org;
82
83 let uri_str = format!("{}/v1/entitlement/orgs/{org}", configuration.base_path, org=crate::apis::urlencode(p_org));
84 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(ref token) = configuration.bearer_access_token {
90 req_builder = req_builder.bearer_auth(token.to_owned());
91 };
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97 let content_type = resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let content_type = super::ContentType::from(content_type);
103
104 if !status.is_client_error() && !status.is_server_error() {
105 let content = resp.text().await?;
106 match content_type {
107 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EntitlementsView`"))),
109 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EntitlementsView`")))),
110 }
111 } else {
112 let content = resp.text().await?;
113 let entity: Option<GetEntitlementOrgsByOrgError> = serde_json::from_str(&content).ok();
114 Err(Error::ResponseError(ResponseContent { status, content, entity }))
115 }
116}
117
118pub async fn post_entitlement_orgs_by_org(configuration: &configuration::Configuration, org: &str, mutate_req: models::MutateReq) -> Result<models::EntitlementsView, Error<PostEntitlementOrgsByOrgError>> {
120 let p_org = org;
122 let p_mutate_req = mutate_req;
123
124 let uri_str = format!("{}/v1/entitlement/orgs/{org}", configuration.base_path, org=crate::apis::urlencode(p_org));
125 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
126
127 if let Some(ref user_agent) = configuration.user_agent {
128 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129 }
130 if let Some(ref token) = configuration.bearer_access_token {
131 req_builder = req_builder.bearer_auth(token.to_owned());
132 };
133 req_builder = req_builder.json(&p_mutate_req);
134
135 let req = req_builder.build()?;
136 let resp = configuration.client.execute(req).await?;
137
138 let status = resp.status();
139 let content_type = resp
140 .headers()
141 .get("content-type")
142 .and_then(|v| v.to_str().ok())
143 .unwrap_or("application/octet-stream");
144 let content_type = super::ContentType::from(content_type);
145
146 if !status.is_client_error() && !status.is_server_error() {
147 let content = resp.text().await?;
148 match content_type {
149 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
150 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EntitlementsView`"))),
151 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EntitlementsView`")))),
152 }
153 } else {
154 let content = resp.text().await?;
155 let entity: Option<PostEntitlementOrgsByOrgError> = serde_json::from_str(&content).ok();
156 Err(Error::ResponseError(ResponseContent { status, content, entity }))
157 }
158}
159