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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! Federation management endpoints.
//!
//! A federation groups several indices so they can be searched as one with
//! [`search_federation`](SearchcraftClient::search_federation). Federations are
//! created through the Searchcraft dashboard rather than this API.
use reqwest::Method;
use crate::client::SearchcraftClient;
use crate::config::Operation;
use crate::error;
use super::types::{Federation, FederationRequest, FederationStats};
impl SearchcraftClient {
/// Lists every federation visible to the key.
///
/// `GET /federation`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::Authentication`](crate::Error::Authentication)
/// if the key is rejected.
pub async fn list_federations(&self) -> error::Result<Vec<Federation>> {
self.transport
.request_data(Method::GET, "federation", Operation::Read, None::<&()>)
.await
}
/// Gets the configuration for a specific federation.
///
/// `GET /federation/{federation_name}`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// federation does not exist.
pub async fn get_federation(&self, federation_name: &str) -> error::Result<Federation> {
let path = format!("federation/{federation_name}");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
/// Lists the federations belonging to an organization.
///
/// `GET /federation/organization/{organization_id}`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// organization does not exist.
pub async fn list_federations_by_organization(
&self,
organization_id: &str,
) -> error::Result<Vec<Federation>> {
let path = format!("federation/organization/{organization_id}");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
/// Lists the index names that make up a federation.
///
/// `GET /federation/{federation_name}/indices`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// federation does not exist.
pub async fn list_federation_indices(
&self,
federation_name: &str,
) -> error::Result<Vec<String>> {
let path = format!("federation/{federation_name}/indices");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
/// Creates a federation.
///
/// `POST /federation`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::Validation`](crate::Error::Validation) if the request is
/// rejected — including when a federation of that name already exists.
pub async fn create_federation(
&self,
request: &FederationRequest,
) -> error::Result<serde_json::Value> {
self.transport
.request_data(Method::POST, "federation", Operation::Write, Some(request))
.await
}
/// Updates an existing federation.
///
/// `PUT /federation/{federation_name}`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::NotFound`](crate::Error::NotFound) if the federation does not
/// exist.
pub async fn update_federation(
&self,
federation_name: &str,
request: &FederationRequest,
) -> error::Result<serde_json::Value> {
let path = format!("federation/{federation_name}");
self.transport
.request_data(Method::PUT, &path, Operation::Write, Some(request))
.await
}
/// Deletes a federation.
///
/// The federated indices themselves are left in place.
///
/// `DELETE /federation/{federation_name}`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no
/// ingest key is configured, or
/// [`Error::NotFound`](crate::Error::NotFound) if the federation does not
/// exist.
pub async fn delete_federation(&self, federation_name: &str) -> error::Result<String> {
let path = format!("federation/{federation_name}");
self.transport
.request_data(Method::DELETE, &path, Operation::Write, None::<&()>)
.await
}
/// Gets document counts and disk usage for a federation, broken down by
/// index.
///
/// `GET /federation/{federation_name}/stats`
///
/// # Errors
///
/// Returns [`Error::Configuration`](crate::Error::Configuration) if no read
/// key is configured, or [`Error::NotFound`](crate::Error::NotFound) if the
/// federation does not exist.
pub async fn get_federation_stats(
&self,
federation_name: &str,
) -> error::Result<FederationStats> {
let path = format!("federation/{federation_name}/stats");
self.transport
.request_data(Method::GET, &path, Operation::Read, None::<&()>)
.await
}
}