-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_key_api.rs
130 lines (104 loc) · 5.4 KB
/
api_key_api.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* SeekStorm REST API documentation
*
* Search engine library & multi-tenancy server
*
* The version of the OpenAPI document: 0.12.11
* Contact: wolf.garbe@seekstorm.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for typed errors of method [`create_apikey_api`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateApikeyApiError {
Status401(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_apikey_api`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteApikeyApiError {
Status401(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_apikey_indices_info_api`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetApikeyIndicesInfoApiError {
Status400(),
Status401(),
Status404(),
UnknownValue(serde_json::Value),
}
/// Creates an API key and returns the Base64 encoded API key. Expects the Base64 encoded master API key in the header. Use the master API key displayed in the server console at startup. WARNING: make sure to set the MASTER_KEY_SECRET environment variable to a secret, otherwise your generated API keys will be compromised. For development purposes you may also use the SeekStorm server console command 'create' to create an demo API key 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA='.
pub async fn create_apikey_api(configuration: &configuration::Configuration, apikey: &str, create_apikey_api_request: models::CreateApikeyApiRequest) -> Result<String, Error<CreateApikeyApiError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_apikey = apikey;
let p_create_apikey_api_request = create_apikey_api_request;
let uri_str = format!("{}/api/v1/apikey", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("apikey", p_apikey.to_string());
req_builder = req_builder.json(&p_create_apikey_api_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<CreateApikeyApiError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Deletes an API and returns the number of remaining API keys. Expects the Base64 encoded master API key in the header. WARNING: This will delete all indices and documents associated with the API key.
pub async fn delete_apikey_api(configuration: &configuration::Configuration, apikey: &str) -> Result<i64, Error<DeleteApikeyApiError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_apikey = apikey;
let uri_str = format!("{}/api/v1/apikey", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("apikey", p_apikey.to_string());
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<DeleteApikeyApiError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get info about all indices associated with the specified API key
pub async fn get_apikey_indices_info_api(configuration: &configuration::Configuration, apikey: &str) -> Result<Vec<models::IndexResponseObject>, Error<GetApikeyIndicesInfoApiError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_apikey = apikey;
let uri_str = format!("{}/api/v1/apikey", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("apikey", p_apikey.to_string());
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetApikeyIndicesInfoApiError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}