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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//! # Render CDK
//! Render CDK provides a streamlined interface for interacting with Render Cloud,
//! a platform that allows you to build, deploy, and scale your applications with ease.
//! This crate abstracts Render's API, facilitating effortless programmatic interaction
//! with Render's robust cloud infrastructure.
//!
//! [website]: https://cdk-c1wu.onrender.com/
//!
//! Reference documentation can be found on the [website].
//!
//! Render CDK comprises several modules that encapsulate
//! the functionalities of the Render API, enabling you to manage services, databases,
//! and other cloud resources through simple Rust code.
//!
//! ## Usage
//! Add `tokio` and `render_cdk` to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! tokio = { version = "1.37.0", features = ["full"] }
//! render_cdk = "0.0.21"
//! ```
//!
//! ## Examples
//! The following examples demonstrate various ways to interact with Render Cloud using this crate.
//!
//! ### 1. Querying for deployed services
//! Retrieve deployed services using different filters like status, region, environment, or by name.
//!
//! ```ignore
//! use render_cdk::resource_management::services::service_manager::ServiceManager;
//! use tokio::main;
//!
//! #[main]
//! async fn main() {
//! // List all services, limiting to 50 results
//! ServiceManager::list_all_services("50").await.unwrap();
//!
//! // List services by status (e.g., suspended)
//! ServiceManager::list_services_with_status("suspended", "50").await.unwrap();
//!
//! // Find a specific service by name and type
//! ServiceManager::find_service_by_name_and_type("whoami", "web_service").await.unwrap();
//!
//! // Find services by region
//! ServiceManager::find_service_by_region("oregon", "10").await.unwrap();
//!
//! // Find services by environment
//! ServiceManager::find_service_by_environment("image", "10").await.unwrap();
//! }
//! ```
//!
//! ### 2. Deleting a service
//! Delete a specific service, such as a web service or static site.
//!
//! ```ignore
//! use render_cdk::resource_management::services::service_manager::ServiceManager;
//! use tokio::main;
//!
//! #[main]
//! async fn main() {
//! // Delete a web service
//! ServiceManager::delete_service("test_web", "web_service").await.unwrap();
//!
//! // Delete a static site
//! ServiceManager::delete_service("test_static", "static").await.unwrap();
//! }
//! ```
//!
//! ### 3. Working with Postgres databases
//! Manage Postgres databases within your Render account, listing, searching, or filtering by status.
//!
//! ```ignore
//! use render_cdk::resource_management::services::service_manager::ServiceManager;
//! use tokio::main;
//!
//! #[main]
//! async fn main() {
//! // List all Postgres instances, limit results to 50
//! ServiceManager::list_postgres_instances(true, "50").await.unwrap();
//!
//! // Find a Postgres instance by name
//! ServiceManager::find_postgres_instance_by_name("agilecomet", true, "100").await.unwrap();
//!
//! // Find Postgres instances by status (e.g., suspended)
//! ServiceManager::find_postgres_instance_with_status("suspended", true, "50").await.unwrap();
//! }
//! ```
//!
//! ### 4. Deploying a static site
//! This example demonstrates how to deploy a simple static site using Render.
//!
//! ```ignore
//! use render_cdk::resource_management::templates::{Template, ServiceDetails};
//!
//! let static_site = Template {
//! type_: "static_site".to_owned(),
//! name: "test_static".to_owned(),
//! repo: "https://github.com/lexara-prime-ai/SAMPLE_STATIC_SITE".to_owned(),
//! auto_deploy: Some("yes".to_owned()),
//! root_dir: Some("./public".to_owned()),
//! service_details: Some(ServiceDetails {
//! publish_path: Some("./".to_owned()),
//! pull_request_previews_enabled: Some("yes".to_owned()),
//! ..Default::default()
//! }),
//! ..Default::default()
//! };
//!
//! // Deploy the static site
//! ServiceManager::create_service(static_site).await.unwrap();
//! ```
//!
//! ### 5. Deploying a web service (Node.js)
//! This example demonstrates deploying a web service, specifically a Node.js application.
//!
//! ```ignore
//! use render_cdk::resource_management::templates::{Template, ServiceDetails, EnvSpecificDetails};
//!
//! let web_service = Template {
//! type_: "web_service".to_owned(),
//! name: "test_web".to_owned(),
//! repo: "https://github.com/lexara-prime-ai/SAMPLE_WEB_SERVICE".to_owned(),
//! auto_deploy: Some("yes".to_owned()),
//! root_dir: Some("./".to_owned()),
//! service_details: Some(ServiceDetails {
//! region: Some("oregon".to_owned()),
//! plan: Some("starter".to_owned()),
//! runtime: Some("node".to_owned()),
//! num_instances: Some(1),
//! env_specific_details: Some(EnvSpecificDetails {
//! build_command: Some("yarn".to_owned()),
//! start_command: Some("npm start".to_owned()),
//! }),
//! pull_request_previews_enabled: Some("yes".to_owned()),
//! ..Default::default()
//! }),
//! ..Default::default()
//! };
//!
//! // Deploy the web service
//! ServiceManager::create_service(web_service).await.unwrap();
//! ```
//!
//! ### 6. Using configuration files for resource provisioning
//! You can use `.conf` files to provision resources on Render. The following example shows
//! how to load and deploy an existing configuration file.
//!
//! ```ignore
//! use render_cdk::iaas::config::Conf;
//! use tokio::main;
//!
//! #[main]
//! async fn main() {
//! // Read the configuration file
//! let config = Conf::read_configuration_file("./samples/sample.conf").unwrap();
//! println!("Loaded Configuration: {:?}", config);
//!
//! // Deploy the configuration
//! ServiceManager::deploy_configuration("./samples/sample.conf").await.unwrap();
//! }
//! ```
//! ## 7. Deploying services via .conf files.
//!
//! This method makes everything easier, the only thing you need to have setup is the
//! `.conf` file, your Render `API_KEY` and `OWNER_CREDENTIALS`
//! i.e the email that acts as the Service Principal on Render Cloud(Identity Access Management.)
//!
//! Here's a sample of a simple configuration file.
//!
//! ```toml
//! # The following is a sample configuration file.
//! # This will be used to provision a
//! # managed postgres instance and managed redis instance.
//! [database]
//! databaseName = ""
//! databaseUser = ""
//! enableHighAvailability = false
//! plan = "starter"
//! version = "12"
//! name = ""
//! # The following portion enables <public> access.
//! cidrBlocks = [
//! { cidrBlock = "0.0.0.0/0", description = "Everywhere" }
//! # { cidrBlock = "0.0.0.0/0", description = "Everywhere" },
//! # { cidrBlock = "0.0.0.0/0", description = "Everywhere" }
//! # Add more CIDR blocks here...
//! ]
//!
//! [redis]
//! # name = ""
//! # plan = "starter"
//! # cidrBlocks = [
//! # { cidrBlock = "0.0.0.0/0", description = "Everywhere" }
//! # # { cidrBlock = "0.0.0.0/0", description = "Everywhere" },
//! # # { cidrBlock = "0.0.0.0/0", description = "Everywhere" }
//! # # Add more CIDR blocks here...
//! # ]
//! ```
//!
//! ## 8. Deploying the configuration.
//! The above configuration can be deployed by running the following code snippet.
//!
//! ```ignore
//! use render_cdk::iaas::config::Conf;
//! use tokio::main;
//!
//! #[main]
//! async fn main() {
//! // Specify the patch to the .conf file...
//! let conf = Conf::read_configuration_file("./samples/sample.conf");
//! let result = Deploy::deploy_configuration("./samples/sample.conf")
//! .await
//! .unwrap();
//!
//! assert!(conf.is_ok());
//! assert!(result.is_ok());
//! }
//! ```
//!
//! ## 9. Deleting services.
//! This example demonstrates how to use the ServiceManager to delete various services.
//!
//! ```ignore
//! use render_cdk::service_management::ServiceManager;
//!
//! #[tokio::main]
//! async fn main() {
//! // Delete a static site deployment.
//! ServiceManager::delete_service("test_deployment", "static").await;
//!
//! // Delete a web service deployment.
//! ServiceManager::delete_service("test_deployment", "web_service").await;
//!
//! // Delete a postgres instance.
//! ServiceManager::delete_postgres_instance("test_postgres").await;
//!
//! // Delete a redis instance.
//! ServiceManager::delete_redis_instance("test_redis").await;
//! }
//!