1use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::apis::ResponseContent;
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum CreatePolicyError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeletePolicyError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetPolicyError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ListPoliciesError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum UpdatePolicyError {
49 UnknownValue(serde_json::Value),
50}
51
52pub async fn create_policy(
53 configuration: &configuration::Configuration,
54 workspace: &str,
55 org: &str,
56 create_policy_request: crate::models::CreatePolicyRequest,
57) -> Result<crate::models::Policy, Error<CreatePolicyError>> {
58 let local_var_configuration = configuration;
59
60 let local_var_client = &local_var_configuration.client;
61
62 let local_var_uri_str = format!(
63 "{}/workspaces/{workspace}/orgs/{org}/access/policies",
64 local_var_configuration.base_path,
65 workspace = crate::apis::urlencode(workspace),
66 org = crate::apis::urlencode(org)
67 );
68 let mut local_var_req_builder =
69 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
70
71 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
72 local_var_req_builder =
73 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74 }
75 local_var_req_builder = local_var_req_builder.json(&create_policy_request);
76
77 let local_var_req = local_var_req_builder.build()?;
78 let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80 let local_var_status = local_var_resp.status();
81 let local_var_content = local_var_resp.text().await?;
82
83 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
84 serde_json::from_str(&local_var_content).map_err(Error::from)
85 } else {
86 let local_var_entity: Option<CreatePolicyError> =
87 serde_json::from_str(&local_var_content).ok();
88 let local_var_error = ResponseContent {
89 status: local_var_status,
90 content: local_var_content,
91 entity: local_var_entity,
92 };
93 Err(Error::ResponseError(local_var_error))
94 }
95}
96
97pub async fn delete_policy(
98 configuration: &configuration::Configuration,
99 workspace: &str,
100 org: &str,
101 policy_id: &str,
102) -> Result<(), Error<DeletePolicyError>> {
103 let local_var_configuration = configuration;
104
105 let local_var_client = &local_var_configuration.client;
106
107 let local_var_uri_str = format!(
108 "{}/workspaces/{workspace}/orgs/{org}/access/policies/{policyId}",
109 local_var_configuration.base_path,
110 workspace = crate::apis::urlencode(workspace),
111 org = crate::apis::urlencode(org),
112 policyId = crate::apis::urlencode(policy_id)
113 );
114 let mut local_var_req_builder =
115 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
116
117 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118 local_var_req_builder =
119 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
120 }
121
122 let local_var_req = local_var_req_builder.build()?;
123 let local_var_resp = local_var_client.execute(local_var_req).await?;
124
125 let local_var_status = local_var_resp.status();
126 let local_var_content = local_var_resp.text().await?;
127
128 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
129 Ok(())
130 } else {
131 let local_var_entity: Option<DeletePolicyError> =
132 serde_json::from_str(&local_var_content).ok();
133 let local_var_error = ResponseContent {
134 status: local_var_status,
135 content: local_var_content,
136 entity: local_var_entity,
137 };
138 Err(Error::ResponseError(local_var_error))
139 }
140}
141
142pub async fn get_policy(
143 configuration: &configuration::Configuration,
144 workspace: &str,
145 org: &str,
146 policy_id: &str,
147) -> Result<crate::models::Policy, Error<GetPolicyError>> {
148 let local_var_configuration = configuration;
149
150 let local_var_client = &local_var_configuration.client;
151
152 let local_var_uri_str = format!(
153 "{}/workspaces/{workspace}/orgs/{org}/access/policies/{policyId}",
154 local_var_configuration.base_path,
155 workspace = crate::apis::urlencode(workspace),
156 org = crate::apis::urlencode(org),
157 policyId = crate::apis::urlencode(policy_id)
158 );
159 let mut local_var_req_builder =
160 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
161
162 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
163 local_var_req_builder =
164 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165 }
166
167 let local_var_req = local_var_req_builder.build()?;
168 let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170 let local_var_status = local_var_resp.status();
171 let local_var_content = local_var_resp.text().await?;
172
173 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174 serde_json::from_str(&local_var_content).map_err(Error::from)
175 } else {
176 let local_var_entity: Option<GetPolicyError> =
177 serde_json::from_str(&local_var_content).ok();
178 let local_var_error = ResponseContent {
179 status: local_var_status,
180 content: local_var_content,
181 entity: local_var_entity,
182 };
183 Err(Error::ResponseError(local_var_error))
184 }
185}
186
187pub async fn list_policies(
188 configuration: &configuration::Configuration,
189 workspace: &str,
190 org: &str,
191) -> Result<Vec<crate::models::Policy>, Error<ListPoliciesError>> {
192 let local_var_configuration = configuration;
193
194 let local_var_client = &local_var_configuration.client;
195
196 let local_var_uri_str = format!(
197 "{}/workspaces/{workspace}/orgs/{org}/access/policies",
198 local_var_configuration.base_path,
199 workspace = crate::apis::urlencode(workspace),
200 org = crate::apis::urlencode(org)
201 );
202 let mut local_var_req_builder =
203 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
204
205 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
206 local_var_req_builder =
207 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
208 }
209
210 let local_var_req = local_var_req_builder.build()?;
211 let local_var_resp = local_var_client.execute(local_var_req).await?;
212
213 let local_var_status = local_var_resp.status();
214 let local_var_content = local_var_resp.text().await?;
215
216 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217 serde_json::from_str(&local_var_content).map_err(Error::from)
218 } else {
219 let local_var_entity: Option<ListPoliciesError> =
220 serde_json::from_str(&local_var_content).ok();
221 let local_var_error = ResponseContent {
222 status: local_var_status,
223 content: local_var_content,
224 entity: local_var_entity,
225 };
226 Err(Error::ResponseError(local_var_error))
227 }
228}
229
230pub async fn update_policy(
231 configuration: &configuration::Configuration,
232 workspace: &str,
233 org: &str,
234 policy_id: &str,
235 update_policy_request: crate::models::UpdatePolicyRequest,
236) -> Result<crate::models::Policy, Error<UpdatePolicyError>> {
237 let local_var_configuration = configuration;
238
239 let local_var_client = &local_var_configuration.client;
240
241 let local_var_uri_str = format!(
242 "{}/workspaces/{workspace}/orgs/{org}/access/policies/{policyId}",
243 local_var_configuration.base_path,
244 workspace = crate::apis::urlencode(workspace),
245 org = crate::apis::urlencode(org),
246 policyId = crate::apis::urlencode(policy_id)
247 );
248 let mut local_var_req_builder =
249 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
250
251 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
252 local_var_req_builder =
253 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
254 }
255 local_var_req_builder = local_var_req_builder.json(&update_policy_request);
256
257 let local_var_req = local_var_req_builder.build()?;
258 let local_var_resp = local_var_client.execute(local_var_req).await?;
259
260 let local_var_status = local_var_resp.status();
261 let local_var_content = local_var_resp.text().await?;
262
263 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
264 serde_json::from_str(&local_var_content).map_err(Error::from)
265 } else {
266 let local_var_entity: Option<UpdatePolicyError> =
267 serde_json::from_str(&local_var_content).ok();
268 let local_var_error = ResponseContent {
269 status: local_var_status,
270 content: local_var_content,
271 entity: local_var_entity,
272 };
273 Err(Error::ResponseError(local_var_error))
274 }
275}