Skip to content

Commit

Permalink
API updates, improved error handling (#100)
Browse files Browse the repository at this point in the history
* Added unit tests for Postgres methods.

* Added find_redis_instances_by_name logic.

* feat: Added logic to find and delete Redis instances.

* Updated tests.

* Added CHANGELOG.md

* Updated commit message length.

* Updated documentation.
  • Loading branch information
irfanghat authored Aug 21, 2024
1 parent c864473 commit c89a3a2
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/commit-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ jobs:
uses: tim-actions/commit-message-checker-with-regex@v0.3.1
with:
commits: ${{ steps.get-pr-commits.outputs.commits }}
pattern: '^.+(\n.{0,82})*$'
error: 'Body line too long (max 82)'
pattern: '^.+(\n.{0,100})*$'
error: 'Body line too long (max 100)'
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

## [Unreleased]

### Added
- **Redis Management:**
- `delete_redis_instance`: Deletes a Redis instance by name.
- `find_redis_instance_by_name`: Finds Redis instances by name with an optional limit.

- **Macros:**
- `handle_response_data!`: A reusable macro to handle API responses, including success and error logging, JSON parsing, and handling of empty service lists.

### Changed
- Standardized response handling and logging for API interactions, reducing code duplication and improving clarity.

---

*Note: This changelog follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format and adheres to [Semantic Versioning](https://semver.org/).*
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
### Crate Information

- **Name:** render_cdk
- **Version:** 0.0.19
- **Version:** 0.0.20
- **License:** MIT

### Current Features
Expand All @@ -29,8 +29,8 @@ Work on the resource management module is currently under way. The API supports

- Services
- Deploys
- Custom domains
- Jobs
- Custom domains _(Coming Soon)_
- Jobs _(Coming Soon)_

The CDK will provide an abstraction that will make it easier to work with the Render cloud programmatically.

Expand All @@ -55,7 +55,7 @@ To use `render_cdk`, include the following in your `Cargo.toml`:

```toml
[dependencies]
render_cdk = "0.0.19"
render_cdk = "0.0.20"
```

* Examples can be found in the: [Technical Documentation](https://github.com/lexara-prime-ai/RENDER_CDK/blob/master/render_cdk/README.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2 class="section-title">

<pre>
<code class="language-toml">[dependencies]
render_cdk = "0.0.19"
render_cdk = "0.0.20"
</code>
</pre>
<p>Alternatively, running <strong>cargo add render_cdk</strong> at the root of your project will
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion render_cdk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion render_cdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "render_cdk"
version = "0.0.19"
version = "0.0.20"
edition = "2021"
authors = ["Irfan Ghat"]
description = "This crate provides a streamlined interface for interacting with Render, a platform that allows you to build, deploy, and scale your apps with ease."
Expand Down
95 changes: 56 additions & 39 deletions render_cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add `render_cdk` to your `Cargo.toml`:

```toml
[dependencies]
render_cdk = "0.0.19"
render_cdk = "0.0.20"
```

* _Alternatively_, running at the `cargo add render_cdk` **root** of your project will also add **render_cdk** to your project.
Expand All @@ -39,20 +39,20 @@ use tokio::main;

#[main]
async fn main() {
// List all deployed services, limiting the result to 10.
let services = ServiceManager::list_all_services("10").await;
// List all deployed services, limiting the result to 50.
let services = ServiceManager::list_all_services("50").await;

// List all services with the status "suspended", limiting the result to 50.
let services = ServiceManager::list_services_with_status("suspended", "50").await;

// Find a specific service by its name and type.
let services = ServiceManager::find_service_by_name_and_type("my_api", "web_service").await;

// Find services deployed in a specific region (e.g., Oregon), limiting the result to 10.
let services = ServiceManager::find_service_by_region("oregon", "10").await;
// Find services deployed in a specific region (e.g., Oregon), limiting the result to 50.
let services = ServiceManager::find_service_by_region("oregon", "50").await;

// Find services based on the environment they are deployed in, limiting the result to 10.
let services = ServiceManager::find_service_by_environment("image", "10").await;
// Find services based on the environment they are deployed in, limiting the result to 50.
let services = ServiceManager::find_service_by_environment("image", "50").await;

// Deleting a web service by name and type.
ServiceManager::delete_service("my_api", "web_service").await.unwrap();
Expand All @@ -64,25 +64,36 @@ async fn main() {
let databases = ServiceManager::list_postgres_instances(true, "50").await.unwrap();

// Find a specific Postgres database instance by name.
let database = ServiceManager::find_postgres_instance_by_name("my_database", true, "100").await.unwrap();
let database = ServiceManager::find_postgres_instance_by_name("my_database", true, "50").await.unwrap();

// Find Postgres database instances with a specific status (e.g., suspended), limiting the result to 50.
let suspended_databases = ServiceManager::find_postgres_instance_with_status("suspended", true, "50").await.unwrap();

// Find redis instances by name.
let redis_instances = ServiceManager::find_redis_instance_by_name("my_redis_instance", "50").await;
}
```

### 2. Retrieving Owner Information
### 2. Deleting Services

You can retrieve the owner ID of the current account with a simple API call.
You can delete services that are no longer needed as well.

```rust
use render_cdk::environment_management::prelude::*;
use render_cdk::service_management::ServiceManager;

#[tokio::main]
async fn main() {
// Retrieve the owner ID of the current Render account.
let owner = Info::get_owner_id().await;
println!("{}", owner);
// 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;
}
```

Expand All @@ -101,7 +112,21 @@ fn main() {
}
```

### 4. Deploying a Static Site
### 4. Deploying an Existing Configuration

If you already have a configuration file, you can deploy it directly using the `ServiceManager`.

```rust
use render_cdk::service_management::ServiceManager;

#[tokio::main]
async fn main() {
// Deploy services as specified in the configuration file.
ServiceManager::deploy_configuration("./samples/sample.conf").await.unwrap();
}
```

### 5. Deploying a Static Site

The following example demonstrates how to deploy a simple static site using a configuration template.

Expand Down Expand Up @@ -136,7 +161,7 @@ async fn main() {
- **publish_path**: The directory path where the static site will be published, e.g., `/public/`.
- **pull_request_previews_enabled**: Indicates whether pull request previews are enabled for this deployment.

### 5. Deploying a Web Service
### 6. Deploying a Web Service

Here’s an example of deploying a simple Node.js web service.

Expand Down Expand Up @@ -172,34 +197,18 @@ async fn main() {
}
```

### 6. Deploying an Existing Configuration
### 7. Retrieving Owner Information

If you already have a configuration file, you can deploy it directly using the `ServiceManager`.
Finally, you can retrieve the owner ID of the current account with a simple API call.

```rust
use render_cdk::service_management::ServiceManager;

#[tokio::main]
async fn main() {
// Deploy services as specified in the configuration file.
ServiceManager::deploy_configuration("./samples/sample.conf").await.unwrap();
}
```

### 7. Deleting Services

Finally, you can delete services that are no longer needed.

```rust
use render_cdk::service_management::ServiceManager;
use render_cdk::environment_management::prelude::*;

#[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;
// Retrieve the owner ID of the current Render account.
let owner = Info::get_owner_id().await;
println!("{}", owner);
}
```

Expand Down Expand Up @@ -266,8 +275,12 @@ cidrBlocks = [
- **user**: The user for the Postgres database.
- **enable_high_availability**: Boolean value to enable or disable high availability for the database.
- **plan**: The pricing plan for the Postgres instance. Options may include "starter", "standard", "premium", etc.


<br/>

> **_Note_**: The **free** plan will result in failed deployments.
<br/>
- **version**: The version of Postgres to be used.
- **cidrBlocks**: A list of CIDR blocks for controlling access to the database. This ensures that only allowed IP ranges can access the instance.
Expand All @@ -277,8 +290,12 @@ cidrBlocks = [

- **name**: The name of the Redis instance.
- **plan**: The pricing plan for the Redis instance. Options may include "starter", "standard", "premium", etc.

<br/>
> **_Note_**: The **free** plan will result in failed deployments.
<br/>
- **cidrBlocks**: A list of CIDR blocks for controlling access to the Redis instance, similar to the database configuration.

Expand Down
2 changes: 1 addition & 1 deletion render_cdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//! ```toml
//! [dependencies]
//! tokio = { version = "1.37.0", features = ["full"] }
//! render_cdk = "0.0.19"
//! render_cdk = "0.0.20"
//! ```
//!
//! ## Examples
Expand Down
Loading

0 comments on commit c89a3a2

Please sign in to comment.