Skip to content

Commit

Permalink
Merge pull request #23 from lexara-prime-ai/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
irfanghat authored Jul 12, 2024
2 parents a27d97f + d08f8ab commit 7fdfe43
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 157 deletions.
91 changes: 91 additions & 0 deletions rust/Cargo.lock

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

7 changes: 5 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.4"
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."
homepage = "https://github.com/lexara-prime-ai/RENDER_CDK"
homepage = "https://cdk-c1wu.onrender.com/"
repository = "https://github.com/lexara-prime-ai/RENDER_CDK"
readme = "README.md"
keywords = ["cloud", "web", "http", "api"]
Expand All @@ -19,8 +19,11 @@ base64 = "0.22.1"
chrono = "0.4.38"
dotenv = "0.15.0"
futures = "0.3.30"
rand = "0.8.5"
reqwest = { version = "0.12.4", features = ["json"] }
serde = { version = "1.0.202", features = ["derive"] }
serde_derive = "1.0.204"
serde_json = "1.0.117"
tokio = { version = "1.37.0", features = ["full"] }
url = "2.5.0"
toml = "0.8.14"
url = "2.5.0"
13 changes: 13 additions & 0 deletions rust/samples/sample.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# The following is a sample configuration file.
# This will be used to provision a
# managed postgres instance and managed redis instance.

[database]
name = ""
user = ""
enable_high_availability = false
plan = "free"
version = "11"

[redis]
plan = "free"
59 changes: 59 additions & 0 deletions rust/src/iaas/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#![allow(unused)]
use anyhow::Error;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::Deserialize;
use std::fs;
use toml;

use super::db::DatabaseConf;
use super::redis::RedisConf;

#[derive(Debug, Deserialize)]
pub struct Conf {
pub database: DatabaseConf,
pub redis: RedisConf,
}

impl Conf {
pub fn generate_random_string(&self, length: usize) -> String {
thread_rng()
.sample_iter(&Alphanumeric)
.take(length)
.map(char::from)
.collect()
}

pub fn populate_blank_values(config: &mut Conf) {
if config.database.name.as_deref() == Some("") {
config.database.name = Some(format!("db_{}", config.generate_random_string(10)));
}

if config.database.user.as_deref() == Some("") {
config.database.user = Some(format!("user_{}", config.generate_random_string(10)));
}
}

pub fn read_configuration_file() -> Result<Self, Error> {
let conf_path = "./samples/sample.conf";
let contents = fs::read_to_string(conf_path)
.expect(format!("Unable to read configuration: <{conf_path:?}>").as_str());

// Parse config. file.
let mut config: Conf = toml::from_str(&contents)
.expect(format!("Unable to parse configuration: <{conf_path:?}>").as_str());

// Populate any <black>/"" fields.
Self::populate_blank_values(&mut config);

////////////////////////
// Debug logs.
///////////////////////
// println!("[DEBUG] -> {:?}", config);

Ok(Self {
database: config.database,
redis: config.redis,
})
}
}
11 changes: 11 additions & 0 deletions rust/src/iaas/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![allow(unused)]
use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct DatabaseConf {
pub name: Option<String>,
pub user: Option<String>,
pub enable_high_availability: bool,
pub plan: String,
pub version: String,
}
138 changes: 0 additions & 138 deletions rust/src/iaas/lexer.rs

This file was deleted.

9 changes: 7 additions & 2 deletions rust/src/iaas/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
pub mod tf_parser;
pub mod lexer;
pub mod config;
pub mod db;
pub mod prelude;
pub mod redis;

pub use config::*;
pub use db::*;
1 change: 1 addition & 0 deletions rust/src/iaas/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use crate::iaas::*;
Loading

0 comments on commit 7fdfe43

Please sign in to comment.