-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lexara-prime-ai/dev
Dev
- Loading branch information
Showing
12 changed files
with
217 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub use crate::iaas::*; |
Oops, something went wrong.