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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//! [`RenderClient`](struct.RenderClient.html) is the main entry point for this library.
//!
//! Library created with [`libninja`](https://www.libninja.com).
use ;
use crate*;
/// All this commented out code doesn't work because Render uses different tokens
/// for the GraphQL authentication (used by Render.com) and for the Rest API.
/// Hopefully Render.com implements REST API endpoints for creating & updating env-groups soon...
// #[derive(Clone, Debug, Serialize)]
// pub struct GqlRequest {
// pub operation_name: &'static str,
// pub variables: serde_json::Value,
// pub query: &'static str,
// }
// #[derive(Clone, Debug, Serialize, Deserialize)]
// pub struct EnvGroup {
// pub id: String,
// pub name: String,
// #[serde(rename = "ownerId")]
// pub owner_id: String,
// #[serde(rename = "created_at")]
// pub created_at: String,
// #[serde(rename = "updatedAt")]
// pub updated_at: String,
// #[serde(rename = "envVars")]
// pub env_vars: Vec<GqlEnvVar>,
// }
// #[derive(Clone, Debug, Serialize, Deserialize)]
// pub struct GqlEnvVar {
// pub id: String,
// pub key: String,
// pub value: String,
// #[serde(rename = "isFile")]
// pub is_file: bool,
// }
// impl From<(&str, &str)> for GqlEnvVar {
// fn from((key, value): (&str, &str)) -> Self {
// Self {
// id: "".to_string(),
// key: key.to_string(),
// value: value.to_string(),
// is_file: false,
// }
// }
// }
// const ENV_GROUPS_FOR_OWNER: &str = r#"
// query envGroupsForOwner($ownerId: String!) {
// envGroupsForOwner(ownerId: $ownerId) {
// ...envGroupFields
// __typename
// }
// }
//
// fragment envGroupFields on EnvGroup {
// id
// name
// ownerId
// created_at
// updatedAt
// envVars {
// ...envVarFields
// __typename
// }
// __typename
// }
//
// fragment envVarFields on EnvVar {
// id
// isFile
// key
// value
// __typename
// }"#;
//
//
// const CREATE_ENV_GROUP: &str = r#"
// mutation createEnvGroup($name: String!, $envVarInputs: [EnvVarInput!]!, $ownerId: String!) {
// createEnvGroup(name: $name, envVarInputs: $envVarInputs, ownerId: $ownerId) {
// ...envGroupFields
// __typename
// }
// }
//
// fragment envGroupFields on EnvGroup {
// id
// name
// ownerId
// createdAt
// updatedAt
// envVars {
// ...envVarFields
// __typename
// }
// __typename
// }
//
// fragment envVarFields on EnvVar {
// id
// isFile
// key
// value
// __typename
// }"#;
//
// const UPDATE_ENV_GROUP: &str = r#"
// mutation updateEnvGroupEnvVars($id: String!, $envVarInputs: [EnvVarInput!]!) {
// updateEnvGroupEnvVars(id: $id, envVarInputs: $envVarInputs) {
// ...envVarFields
// __typename
// }
// }
//
// fragment envVarFields on EnvVar {
// id
// isFile
// key
// value
// __typename
// }"#;
//
// const GET_ENV_GROUP: &str = r#"
// query envGroup($id: String!) {
// envGroup(id: $id) {
// ...envGroupFields
// __typename
// }
// }
//
// fragment envGroupFields on EnvGroup {
// id
// name
// ownerId
// createdAt
// updatedAt
// envVars {
// ...envVarFields
// __typename
// }
// __typename
// }
//
// fragment envVarFields on EnvVar {
// id
// isFile
// key
// value
// __typename
// }"#;
// impl RenderClient {
// pub async fn get_env_groups(&self, owner_id: &str) -> httpclient::Result<Vec<EnvGroup>> {
// let url = "https://api.render.com/graphql";
// let gql = GqlRequest {
// operation_name: "envGroupsForOwner",
// variables: serde_json::json!({
// "ownerId": owner_id,
// }),
// query: ENV_GROUPS_FOR_OWNER,
// };
// let req = self.client
// .post(url)
// .json(&gql);
// let res = self.authenticate(req)
//
// .await?;
// let mut res: serde_json::Value = res.json().map_err(Into::into)?;
// let groups: Vec<EnvGroup> = serde_json::from_value(res["data"]["envGroupsForOwner"].take())?;
// Ok(groups)
// }
//
// pub async fn create_env_var_group(&self, owner_id: &str, name: &str, vars: &[GqlEnvVar]) -> httpclient::Result<EnvGroup> {
// let url = "https://api.render.com/graphql";
// let gql = GqlRequest {
// operation_name: "createEnvGroup",
// variables: serde_json::json!({
// "ownerId": owner_id,
// "name": name,
// "envVarInputs": vars,
// }),
// query: CREATE_ENV_GROUP,
// };
// let req = self.client
// .post(url)
// .json(&gql);
// let res = self.authenticate(req)
//
// .await?;
// let mut res: serde_json::Value = res.json().map_err(Into::into)?;
// let group: EnvGroup = serde_json::from_value(res["data"]["createEnvGroup"].take())?;
// Ok(group)
// }
//
// pub async fn update_env_var_group(&self, group_id: &str, vars: &[GqlEnvVar]) -> httpclient::Result<EnvGroup> {
// let url = "https://api.render.com/graphql";
// let gql = GqlRequest {
// operation_name: "updateEnvGroup",
// variables: serde_json::json!({
// "envGroupId": group_id,
// "envVarInputs": vars,
// }),
// query: UPDATE_ENV_GROUP,
// };
// let req = self.client
// .post(url)
// .json(&gql);
// let res = self.authenticate(req)
//
// .await?;
// let mut res: serde_json::Value = res.json().map_err(Into::into)?;
// let group: EnvGroup = serde_json::from_value(res["data"]["updateEnvGroup"].take())?;
// Ok(group)
// }
// pub async fn get_env_group(&self, group_id: &str) -> httpclient::Result<EnvGroup> {
// let url = "https://api.render.com/graphql";
// let gql = GqlRequest {
// operation_name: "envGroup",
// variables: serde_json::json!({
// "id": group_id,
// }),
// query: GET_ENV_GROUP,
// };
// let req = self.client
// .post(url)
// .json(&gql);
// let res = self.authenticate(req)
//
// .await?;
// let mut res: serde_json::Value = res.json().map_err(Into::into)?;
// let group: EnvGroup = serde_json::from_value(res["data"]["envGroup"].take())?;
// Ok(group)
// }
// }