langfuse_client_base/apis/
scim_api.rs

1/*
2 * langfuse
3 *
4 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`scim_create_user`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ScimCreateUserError {
20    Status400(serde_json::Value),
21    Status401(serde_json::Value),
22    Status403(serde_json::Value),
23    Status404(serde_json::Value),
24    Status405(serde_json::Value),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`scim_delete_user`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ScimDeleteUserError {
32    Status400(serde_json::Value),
33    Status401(serde_json::Value),
34    Status403(serde_json::Value),
35    Status404(serde_json::Value),
36    Status405(serde_json::Value),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`scim_get_resource_types`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ScimGetResourceTypesError {
44    Status400(serde_json::Value),
45    Status401(serde_json::Value),
46    Status403(serde_json::Value),
47    Status404(serde_json::Value),
48    Status405(serde_json::Value),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`scim_get_schemas`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ScimGetSchemasError {
56    Status400(serde_json::Value),
57    Status401(serde_json::Value),
58    Status403(serde_json::Value),
59    Status404(serde_json::Value),
60    Status405(serde_json::Value),
61    UnknownValue(serde_json::Value),
62}
63
64/// struct for typed errors of method [`scim_get_service_provider_config`]
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum ScimGetServiceProviderConfigError {
68    Status400(serde_json::Value),
69    Status401(serde_json::Value),
70    Status403(serde_json::Value),
71    Status404(serde_json::Value),
72    Status405(serde_json::Value),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`scim_get_user`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum ScimGetUserError {
80    Status400(serde_json::Value),
81    Status401(serde_json::Value),
82    Status403(serde_json::Value),
83    Status404(serde_json::Value),
84    Status405(serde_json::Value),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`scim_list_users`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum ScimListUsersError {
92    Status400(serde_json::Value),
93    Status401(serde_json::Value),
94    Status403(serde_json::Value),
95    Status404(serde_json::Value),
96    Status405(serde_json::Value),
97    UnknownValue(serde_json::Value),
98}
99
100/// Create a new user in the organization (requires organization-scoped API key)
101#[bon::builder]
102pub async fn scim_create_user(
103    configuration: &configuration::Configuration,
104    scim_create_user_request: models::ScimCreateUserRequest,
105) -> Result<models::ScimUser, Error<ScimCreateUserError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_body_scim_create_user_request = scim_create_user_request;
108
109    let uri_str = format!("{}/api/public/scim/Users", configuration.base_path);
110    let mut req_builder = configuration
111        .client
112        .request(reqwest::Method::POST, &uri_str);
113
114    if let Some(ref user_agent) = configuration.user_agent {
115        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
116    }
117    if let Some(ref auth_conf) = configuration.basic_auth {
118        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
119    };
120    req_builder = req_builder.json(&p_body_scim_create_user_request);
121
122    let req = req_builder.build()?;
123    let resp = configuration.client.execute(req).await?;
124
125    let status = resp.status();
126    let content_type = resp
127        .headers()
128        .get("content-type")
129        .and_then(|v| v.to_str().ok())
130        .unwrap_or("application/octet-stream");
131    let content_type = super::ContentType::from(content_type);
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        match content_type {
136            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScimUser`"))),
138            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::ScimUser`")))),
139        }
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<ScimCreateUserError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent {
144            status,
145            content,
146            entity,
147        }))
148    }
149}
150
151/// Remove a user from the organization (requires organization-scoped API key). Note that this only removes the user from the organization but does not delete the user entity itself.
152#[bon::builder]
153pub async fn scim_delete_user(
154    configuration: &configuration::Configuration,
155    user_id: &str,
156) -> Result<serde_json::Value, Error<ScimDeleteUserError>> {
157    // add a prefix to parameters to efficiently prevent name collisions
158    let p_path_user_id = user_id;
159
160    let uri_str = format!(
161        "{}/api/public/scim/Users/{userId}",
162        configuration.base_path,
163        userId = crate::apis::urlencode(p_path_user_id)
164    );
165    let mut req_builder = configuration
166        .client
167        .request(reqwest::Method::DELETE, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref auth_conf) = configuration.basic_auth {
173        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180    let content_type = resp
181        .headers()
182        .get("content-type")
183        .and_then(|v| v.to_str().ok())
184        .unwrap_or("application/octet-stream");
185    let content_type = super::ContentType::from(content_type);
186
187    if !status.is_client_error() && !status.is_server_error() {
188        let content = resp.text().await?;
189        match content_type {
190            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
192            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
193        }
194    } else {
195        let content = resp.text().await?;
196        let entity: Option<ScimDeleteUserError> = serde_json::from_str(&content).ok();
197        Err(Error::ResponseError(ResponseContent {
198            status,
199            content,
200            entity,
201        }))
202    }
203}
204
205/// Get SCIM Resource Types (requires organization-scoped API key)
206#[bon::builder]
207pub async fn scim_get_resource_types(
208    configuration: &configuration::Configuration,
209) -> Result<models::ResourceTypesResponse, Error<ScimGetResourceTypesError>> {
210    let uri_str = format!("{}/api/public/scim/ResourceTypes", configuration.base_path);
211    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
212
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(ref auth_conf) = configuration.basic_auth {
217        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
218    };
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ResourceTypesResponse`"))),
236            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::ResourceTypesResponse`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<ScimGetResourceTypesError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent {
242            status,
243            content,
244            entity,
245        }))
246    }
247}
248
249/// Get SCIM Schemas (requires organization-scoped API key)
250#[bon::builder]
251pub async fn scim_get_schemas(
252    configuration: &configuration::Configuration,
253) -> Result<models::SchemasResponse, Error<ScimGetSchemasError>> {
254    let uri_str = format!("{}/api/public/scim/Schemas", configuration.base_path);
255    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
256
257    if let Some(ref user_agent) = configuration.user_agent {
258        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
259    }
260    if let Some(ref auth_conf) = configuration.basic_auth {
261        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
262    };
263
264    let req = req_builder.build()?;
265    let resp = configuration.client.execute(req).await?;
266
267    let status = resp.status();
268    let content_type = resp
269        .headers()
270        .get("content-type")
271        .and_then(|v| v.to_str().ok())
272        .unwrap_or("application/octet-stream");
273    let content_type = super::ContentType::from(content_type);
274
275    if !status.is_client_error() && !status.is_server_error() {
276        let content = resp.text().await?;
277        match content_type {
278            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
279            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SchemasResponse`"))),
280            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::SchemasResponse`")))),
281        }
282    } else {
283        let content = resp.text().await?;
284        let entity: Option<ScimGetSchemasError> = serde_json::from_str(&content).ok();
285        Err(Error::ResponseError(ResponseContent {
286            status,
287            content,
288            entity,
289        }))
290    }
291}
292
293/// Get SCIM Service Provider Configuration (requires organization-scoped API key)
294#[bon::builder]
295pub async fn scim_get_service_provider_config(
296    configuration: &configuration::Configuration,
297) -> Result<models::ServiceProviderConfig, Error<ScimGetServiceProviderConfigError>> {
298    let uri_str = format!(
299        "{}/api/public/scim/ServiceProviderConfig",
300        configuration.base_path
301    );
302    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
303
304    if let Some(ref user_agent) = configuration.user_agent {
305        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
306    }
307    if let Some(ref auth_conf) = configuration.basic_auth {
308        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
309    };
310
311    let req = req_builder.build()?;
312    let resp = configuration.client.execute(req).await?;
313
314    let status = resp.status();
315    let content_type = resp
316        .headers()
317        .get("content-type")
318        .and_then(|v| v.to_str().ok())
319        .unwrap_or("application/octet-stream");
320    let content_type = super::ContentType::from(content_type);
321
322    if !status.is_client_error() && !status.is_server_error() {
323        let content = resp.text().await?;
324        match content_type {
325            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
326            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ServiceProviderConfig`"))),
327            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::ServiceProviderConfig`")))),
328        }
329    } else {
330        let content = resp.text().await?;
331        let entity: Option<ScimGetServiceProviderConfigError> = serde_json::from_str(&content).ok();
332        Err(Error::ResponseError(ResponseContent {
333            status,
334            content,
335            entity,
336        }))
337    }
338}
339
340/// Get a specific user by ID (requires organization-scoped API key)
341#[bon::builder]
342pub async fn scim_get_user(
343    configuration: &configuration::Configuration,
344    user_id: &str,
345) -> Result<models::ScimUser, Error<ScimGetUserError>> {
346    // add a prefix to parameters to efficiently prevent name collisions
347    let p_path_user_id = user_id;
348
349    let uri_str = format!(
350        "{}/api/public/scim/Users/{userId}",
351        configuration.base_path,
352        userId = crate::apis::urlencode(p_path_user_id)
353    );
354    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
355
356    if let Some(ref user_agent) = configuration.user_agent {
357        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
358    }
359    if let Some(ref auth_conf) = configuration.basic_auth {
360        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
361    };
362
363    let req = req_builder.build()?;
364    let resp = configuration.client.execute(req).await?;
365
366    let status = resp.status();
367    let content_type = resp
368        .headers()
369        .get("content-type")
370        .and_then(|v| v.to_str().ok())
371        .unwrap_or("application/octet-stream");
372    let content_type = super::ContentType::from(content_type);
373
374    if !status.is_client_error() && !status.is_server_error() {
375        let content = resp.text().await?;
376        match content_type {
377            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
378            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScimUser`"))),
379            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::ScimUser`")))),
380        }
381    } else {
382        let content = resp.text().await?;
383        let entity: Option<ScimGetUserError> = serde_json::from_str(&content).ok();
384        Err(Error::ResponseError(ResponseContent {
385            status,
386            content,
387            entity,
388        }))
389    }
390}
391
392/// List users in the organization (requires organization-scoped API key)
393#[bon::builder]
394pub async fn scim_list_users(
395    configuration: &configuration::Configuration,
396    filter: Option<&str>,
397    start_index: Option<i32>,
398    count: Option<i32>,
399) -> Result<models::ScimUsersListResponse, Error<ScimListUsersError>> {
400    // add a prefix to parameters to efficiently prevent name collisions
401    let p_query_filter = filter;
402    let p_query_start_index = start_index;
403    let p_query_count = count;
404
405    let uri_str = format!("{}/api/public/scim/Users", configuration.base_path);
406    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
407
408    if let Some(ref param_value) = p_query_filter {
409        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
410    }
411    if let Some(ref param_value) = p_query_start_index {
412        req_builder = req_builder.query(&[("startIndex", &param_value.to_string())]);
413    }
414    if let Some(ref param_value) = p_query_count {
415        req_builder = req_builder.query(&[("count", &param_value.to_string())]);
416    }
417    if let Some(ref user_agent) = configuration.user_agent {
418        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
419    }
420    if let Some(ref auth_conf) = configuration.basic_auth {
421        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
422    };
423
424    let req = req_builder.build()?;
425    let resp = configuration.client.execute(req).await?;
426
427    let status = resp.status();
428    let content_type = resp
429        .headers()
430        .get("content-type")
431        .and_then(|v| v.to_str().ok())
432        .unwrap_or("application/octet-stream");
433    let content_type = super::ContentType::from(content_type);
434
435    if !status.is_client_error() && !status.is_server_error() {
436        let content = resp.text().await?;
437        match content_type {
438            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
439            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScimUsersListResponse`"))),
440            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::ScimUsersListResponse`")))),
441        }
442    } else {
443        let content = resp.text().await?;
444        let entity: Option<ScimListUsersError> = serde_json::from_str(&content).ok();
445        Err(Error::ResponseError(ResponseContent {
446            status,
447            content,
448            entity,
449        }))
450    }
451}