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
use std::collections::HashMap;
use serde_json::json;
use crate::{Endpoint, http::errors::ApiError};
use super::AppResource;
impl AppResource {
/// Returns all environment variables currently set on the application.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn list_envs(
&self,
) -> Result<HashMap<String, String>, ApiError> {
self.client
.request_endpoint(Endpoint::list_app_envs(&self.id))
.await?
.into_result_t()
}
/// Adds or updates the given environment variables without affecting any
/// keys that are not present in `envs`.
///
/// Returns the complete map of environment variables after the upsert.
///
/// # Errors
///
/// Returns [`ApiError::Api`] with
/// [`ApiErrorCode::RegexValidation`](crate::ApiErrorCode::RegexValidation)
/// if a key or value is rejected, or [`ApiError::Transport`] on network
/// failure.
pub async fn upsert_envs(
&self,
envs: &HashMap<String, String>,
) -> Result<HashMap<String, String>, ApiError> {
let endpoint = Endpoint::post_app_envs(&self.id);
let request = endpoint
.request_builder(&self.client.http_client, &self.client.base_url)
.json(&json!({"envs": envs}))
.build()?;
self.client.execute_request(request).await?.into_result_t()
}
/// Replaces all environment variables with exactly the given map.
///
/// Any variables that exist on the application but are absent from `envs`
/// will be deleted. Returns the resulting environment map.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn overwrite_envs(
&self,
envs: &HashMap<String, String>,
) -> Result<HashMap<String, String>, ApiError> {
let endpoint = Endpoint::overwrite_app_envs(&self.id);
let request = endpoint
.request_builder(&self.client.http_client, &self.client.base_url)
.json(&json!({"envs": envs}))
.build()?;
self.client.execute_request(request).await?.into_result_t()
}
/// Deletes the environment variables whose keys are listed in `envs`.
///
/// Keys that do not exist are silently ignored. Returns the environment
/// map after the deletions.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn delete_envs(
&self,
envs: &[String],
) -> Result<HashMap<String, String>, ApiError> {
let endpoint = Endpoint::delete_app_envs(&self.id);
let request = endpoint
.request_builder(&self.client.http_client, &self.client.base_url)
.json(&json!({"envs": envs}))
.build()?;
self.client.execute_request(request).await?.into_result_t()
}
}