qcs_api/apis/
endpoints_api.rs

1/*
2 * Rigetti QCS API
3 *
4 * # Introduction  This is the documentation for the Rigetti QCS HTTP API.  You can find out more about Rigetti at [https://rigetti.com](https://rigetti.com), and also interact with QCS via the web at [https://qcs.rigetti.com](https://qcs.rigetti.com).  This API is documented in **OpenAPI format** and so is compatible with the dozens of language-specific client generators available [here](https://github.com/OpenAPITools/openapi-generator) and elsewhere on the web.  # Principles  This API follows REST design principles where appropriate, and otherwise an HTTP RPC paradigm. We adhere to the Google [API Improvement Proposals](https://google.aip.dev/general) where reasonable to provide a consistent, intuitive developer experience. HTTP response codes match their specifications, and error messages fit a common format.  # Authentication  All access to the QCS API requires OAuth2 authentication provided by Okta. You can request access [here](https://www.rigetti.com/get-quantum). Once you have a user account, you can download your access token from QCS [here](https://qcs.rigetti.com/auth/token).   That access token is valid for 24 hours after issuance. The value of `access_token` within the JSON file is the token used for authentication (don't use the entire JSON file).  Authenticate requests using the `Authorization` header and a `Bearer` prefix:  ``` curl --header \"Authorization: Bearer eyJraW...Iow\" ```  # Quantum Processor Access  Access to the quantum processors themselves is not yet provided directly by this HTTP API, but is instead performed over ZeroMQ/[rpcq](https://gitlab.com/rigetti/rpcq). Until that changes, we suggest using [pyquil](https://gitlab.com/rigetti/pyquil) to build and execute quantum programs via the Legacy API.  # Legacy API  Our legacy HTTP API remains accessible at https://forest-server.qcs.rigetti.com, and it shares a source of truth with this API's services. You can use either service with the same user account and means of authentication. We strongly recommend using the API documented here, as the legacy API is on the path to deprecation.
5 *
6 * The version of the OpenAPI document: 2020-07-31
7 * Contact: support@rigetti.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`create_endpoint`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateEndpointError {
20    Status400(crate::models::Error),
21    Status404(crate::models::Error),
22    Status422(crate::models::ValidationError),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_endpoint`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteEndpointError {
30    Status403(crate::models::Error),
31    Status404(crate::models::Error),
32    Status422(crate::models::ValidationError),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_default_endpoint`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetDefaultEndpointError {
40    Status404(crate::models::Error),
41    Status422(crate::models::ValidationError),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`get_endpoint`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetEndpointError {
49    Status404(crate::models::Error),
50    Status422(crate::models::ValidationError),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`list_endpoints`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ListEndpointsError {
58    Status422(crate::models::ValidationError),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`restart_endpoint`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum RestartEndpointError {
66    Status403(crate::models::Error),
67    Status422(crate::models::ValidationError),
68    UnknownValue(serde_json::Value),
69}
70
71/// Create an endpoint associated with your user account.
72pub async fn create_endpoint(
73    configuration: &configuration::Configuration,
74    create_endpoint_parameters: crate::models::CreateEndpointParameters,
75) -> Result<crate::models::Endpoint, Error<CreateEndpointError>> {
76    let local_var_configuration = configuration;
77
78    let local_var_client = &local_var_configuration.client;
79
80    let local_var_uri_str = format!("{}/v1/endpoints", local_var_configuration.base_path);
81    let mut local_var_req_builder =
82        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
83
84    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85        local_var_req_builder =
86            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
87    }
88    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
89        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
90    };
91    local_var_req_builder = local_var_req_builder.json(&create_endpoint_parameters);
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<CreateEndpointError> =
103            serde_json::from_str(&local_var_content).ok();
104        let local_var_error = ResponseContent {
105            status: local_var_status,
106            content: local_var_content,
107            entity: local_var_entity,
108        };
109        Err(Error::ResponseError(local_var_error))
110    }
111}
112
113/// Delete an endpoint, releasing its resources. This operation is not reversible.
114pub async fn delete_endpoint(
115    configuration: &configuration::Configuration,
116    endpoint_id: &str,
117) -> Result<serde_json::Value, Error<DeleteEndpointError>> {
118    let local_var_configuration = configuration;
119
120    let local_var_client = &local_var_configuration.client;
121
122    let local_var_uri_str = format!(
123        "{}/v1/endpoints/{endpointId}",
124        local_var_configuration.base_path,
125        endpointId = crate::apis::urlencode(endpoint_id)
126    );
127    let mut local_var_req_builder =
128        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
129
130    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
131        local_var_req_builder =
132            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
133    }
134    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
135        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
136    };
137
138    let local_var_req = local_var_req_builder.build()?;
139    let local_var_resp = local_var_client.execute(local_var_req).await?;
140
141    let local_var_status = local_var_resp.status();
142    let local_var_content = local_var_resp.text().await?;
143
144    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145        serde_json::from_str(&local_var_content).map_err(Error::from)
146    } else {
147        let local_var_entity: Option<DeleteEndpointError> =
148            serde_json::from_str(&local_var_content).ok();
149        let local_var_error = ResponseContent {
150            status: local_var_status,
151            content: local_var_content,
152            entity: local_var_entity,
153        };
154        Err(Error::ResponseError(local_var_error))
155    }
156}
157
158/// Retrieve the endpoint set as \"default\" for the given Quantum Processor.  If no endpoint is set as the default, return \"not found.\"
159pub async fn get_default_endpoint(
160    configuration: &configuration::Configuration,
161    quantum_processor_id: &str,
162) -> Result<crate::models::Endpoint, Error<GetDefaultEndpointError>> {
163    let local_var_configuration = configuration;
164
165    let local_var_client = &local_var_configuration.client;
166
167    let local_var_uri_str = format!(
168        "{}/v1/quantumProcessors/{quantumProcessorId}/endpoints:getDefault",
169        local_var_configuration.base_path,
170        quantumProcessorId = crate::apis::urlencode(quantum_processor_id)
171    );
172    let mut local_var_req_builder =
173        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
174
175    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
176        local_var_req_builder =
177            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
178    }
179    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
180        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
181    };
182
183    let local_var_req = local_var_req_builder.build()?;
184    let local_var_resp = local_var_client.execute(local_var_req).await?;
185
186    let local_var_status = local_var_resp.status();
187    let local_var_content = local_var_resp.text().await?;
188
189    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
190        serde_json::from_str(&local_var_content).map_err(Error::from)
191    } else {
192        let local_var_entity: Option<GetDefaultEndpointError> =
193            serde_json::from_str(&local_var_content).ok();
194        let local_var_error = ResponseContent {
195            status: local_var_status,
196            content: local_var_content,
197            entity: local_var_entity,
198        };
199        Err(Error::ResponseError(local_var_error))
200    }
201}
202
203/// Retrieve a specific endpoint by its ID.
204pub async fn get_endpoint(
205    configuration: &configuration::Configuration,
206    endpoint_id: &str,
207) -> Result<crate::models::Endpoint, Error<GetEndpointError>> {
208    let local_var_configuration = configuration;
209
210    let local_var_client = &local_var_configuration.client;
211
212    let local_var_uri_str = format!(
213        "{}/v1/endpoints/{endpointId}",
214        local_var_configuration.base_path,
215        endpointId = crate::apis::urlencode(endpoint_id)
216    );
217    let mut local_var_req_builder =
218        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder =
222            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223    }
224    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
225        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226    };
227
228    let local_var_req = local_var_req_builder.build()?;
229    let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231    let local_var_status = local_var_resp.status();
232    let local_var_content = local_var_resp.text().await?;
233
234    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235        serde_json::from_str(&local_var_content).map_err(Error::from)
236    } else {
237        let local_var_entity: Option<GetEndpointError> =
238            serde_json::from_str(&local_var_content).ok();
239        let local_var_error = ResponseContent {
240            status: local_var_status,
241            content: local_var_content,
242            entity: local_var_entity,
243        };
244        Err(Error::ResponseError(local_var_error))
245    }
246}
247
248/// List all endpoints, optionally filtering by attribute.
249pub async fn list_endpoints(
250    configuration: &configuration::Configuration,
251    filter: Option<&str>,
252    page_size: Option<i32>,
253    page_token: Option<&str>,
254) -> Result<crate::models::ListEndpointsResponse, Error<ListEndpointsError>> {
255    let local_var_configuration = configuration;
256
257    let local_var_client = &local_var_configuration.client;
258
259    let local_var_uri_str = format!("{}/v1/endpoints", local_var_configuration.base_path);
260    let mut local_var_req_builder =
261        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
262
263    if let Some(ref local_var_str) = filter {
264        local_var_req_builder =
265            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
266    }
267    if let Some(ref local_var_str) = page_size {
268        local_var_req_builder =
269            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
270    }
271    if let Some(ref local_var_str) = page_token {
272        local_var_req_builder =
273            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
274    }
275    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276        local_var_req_builder =
277            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278    }
279    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
280        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
281    };
282
283    let local_var_req = local_var_req_builder.build()?;
284    let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286    let local_var_status = local_var_resp.status();
287    let local_var_content = local_var_resp.text().await?;
288
289    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
290        serde_json::from_str(&local_var_content).map_err(Error::from)
291    } else {
292        let local_var_entity: Option<ListEndpointsError> =
293            serde_json::from_str(&local_var_content).ok();
294        let local_var_error = ResponseContent {
295            status: local_var_status,
296            content: local_var_content,
297            entity: local_var_entity,
298        };
299        Err(Error::ResponseError(local_var_error))
300    }
301}
302
303/// Restart an entire endpoint or a single component within an endpoint.
304pub async fn restart_endpoint(
305    configuration: &configuration::Configuration,
306    endpoint_id: &str,
307    restart_endpoint_request: Option<crate::models::RestartEndpointRequest>,
308) -> Result<serde_json::Value, Error<RestartEndpointError>> {
309    let local_var_configuration = configuration;
310
311    let local_var_client = &local_var_configuration.client;
312
313    let local_var_uri_str = format!(
314        "{}/v1/endpoints/{endpointId}:restart",
315        local_var_configuration.base_path,
316        endpointId = crate::apis::urlencode(endpoint_id)
317    );
318    let mut local_var_req_builder =
319        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
320
321    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
322        local_var_req_builder =
323            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
324    }
325    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
326        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
327    };
328    local_var_req_builder = local_var_req_builder.json(&restart_endpoint_request);
329
330    let local_var_req = local_var_req_builder.build()?;
331    let local_var_resp = local_var_client.execute(local_var_req).await?;
332
333    let local_var_status = local_var_resp.status();
334    let local_var_content = local_var_resp.text().await?;
335
336    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
337        serde_json::from_str(&local_var_content).map_err(Error::from)
338    } else {
339        let local_var_entity: Option<RestartEndpointError> =
340            serde_json::from_str(&local_var_content).ok();
341        let local_var_error = ResponseContent {
342            status: local_var_status,
343            content: local_var_content,
344            entity: local_var_entity,
345        };
346        Err(Error::ResponseError(local_var_error))
347    }
348}