diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 66e2300..980a3ea 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -740,6 +740,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -758,6 +764,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.5.2" @@ -776,10 +812,13 @@ dependencies = [ "chrono", "dotenv", "futures", + "rand", "reqwest", "serde", + "serde_derive", "serde_json", "tokio", + "toml", "url", ] @@ -975,6 +1014,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -1162,6 +1210,40 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59a3a72298453f564e2b111fa896f8d07fabb36f51f06d7e875fc5e0b5a3ef1" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -1497,6 +1579,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.52.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index c1142ee..c1c853d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -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"] @@ -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" \ No newline at end of file +toml = "0.8.14" +url = "2.5.0" diff --git a/rust/src/iaas/interpreter.rs b/rust/src/iaas/interpreter.rs deleted file mode 100644 index 7940535..0000000 --- a/rust/src/iaas/interpreter.rs +++ /dev/null @@ -1,66 +0,0 @@ -use super::parser::*; - -#[derive(Debug)] -pub struct Interpreter; - -impl Interpreter { - pub fn new() -> Self { - Interpreter - } - - pub async fn interpret(&self, nodes: Vec) -> Vec { - let mut results = Vec::new(); - - for node in nodes { - match node { - ASTNode::ProviderBlock { name, properties } => { - results.push(self.interpret_provider_block(name, properties).await); - } - ASTNode::ResourceBlock { - name, - resource_type, - properties, - } => { - results.push( - self.interpret_resource_block(name, resource_type, properties) - .await, - ); - } - } - } - results - } - - pub async fn interpret_provider_block( - &self, - name: String, - properties: Vec<(String, ASTValue)>, - ) -> String { - let mut result = format!("Provider: {}", name); - - for (key, value) in properties { - match value { - ASTValue::StringLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), - ASTValue::NumberLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), - } - } - result - } - - pub async fn interpret_resource_block( - &self, - name: String, - resource_type: String, - properties: Vec<(String, ASTValue)>, - ) -> String { - let mut result = format!("Resource: {} {}", resource_type, name); - - for (key, value) in properties { - match value { - ASTValue::StringLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), - ASTValue::NumberLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), - } - } - result - } -} diff --git a/rust/src/iaas/lexer.rs b/rust/src/iaas/lexer.rs deleted file mode 100644 index 6adceb7..0000000 --- a/rust/src/iaas/lexer.rs +++ /dev/null @@ -1,141 +0,0 @@ -#![allow(unused)] - -#[derive(Debug)] -#[derive(PartialEq)] -pub enum Token { - Provider, - Resource, - Identifier(String), - StringLiteral(String), - NumberLiteral(i64), - Equals, - LeftBrace, - RightBrace, - EOF, -} - -#[derive(Debug)] -#[derive(PartialEq)] -pub struct Lexer<'l> { - pub input: &'l str, - pub position: usize, - pub current_char: Option, -} - -impl<'l> Lexer<'l> { - pub fn new(input: &'l str) -> Self { - let mut lexer = Self { - input, - position: 0, - current_char: None, - }; - - lexer - } - - pub fn advance(&mut self) { - if self.position < self.input.len() { - self.current_char = Some(self.input[self.position..].chars().next().unwrap()); - self.position += 1; - } else { - self.current_char = None; - } - } - - pub fn skip_whitespace(&mut self) { - while let Some(c) = self.current_char { - if c.is_whitespace() { - self.advance(); - } else { - break; - } - } - } - - pub fn peek_keyword(&self, keyword: &str) -> bool { - self.input[self.position - 1..].starts_with(keyword) - } - - pub fn consume_keyword(&mut self, keyword: &str) { - for _ in 0..keyword.len() { - self.advance(); - } - } - - pub fn read_identifier(&mut self) -> String { - let mut identifier = String::new(); - while let Some(c) = self.current_char { - if c.is_alphanumeric() || c == '_' { - identifier.push(c); - self.advance(); - } else { - break; - } - } - identifier - } - - pub fn read_string(&mut self) -> String { - self.advance(); - let mut string = String::new(); - while let Some(c) = self.current_char { - if c == '"' { - break; - } else { - string.push(c); - self.advance(); - } - } - self.advance(); - string - } - - pub fn read_number(&mut self) -> i64 { - let mut number = String::new(); - while let Some(c) = self.current_char { - if c.is_digit(10) { - number.push(c); - self.advance(); - } else { - break; - } - } - number.parse().unwrap() - } - - pub fn next_token(&mut self) -> Token { - self.skip_whitespace(); - - let token = match self.current_char { - Some('p') if self.peek_keyword("provider") => { - self.consume_keyword("provider"); - Token::Provider - } - - Some('r') if self.peek_keyword("resource") => { - self.consume_keyword("resource"); - Token::Resource - } - - Some(c) if c.is_alphabetic() => Token::Identifier(self.read_identifier()), - Some('"') => Token::StringLiteral(self.read_string()), - Some('=') => { - self.advance(); - Token::Equals - } - Some('{') => { - self.advance(); - Token::LeftBrace - } - Some('}') => { - self.advance(); - Token::RightBrace - } - Some(c) if c.is_digit(10) => Token::NumberLiteral(self.read_number()), - None => Token::EOF, - _ => panic!("Unexpected character: {:?}", self.current_char), - }; - - token - } -} diff --git a/rust/src/iaas/mod.rs b/rust/src/iaas/mod.rs index d35d0aa..296a703 100644 --- a/rust/src/iaas/mod.rs +++ b/rust/src/iaas/mod.rs @@ -1,4 +1 @@ -pub mod interpreter; -pub mod lexer; -pub mod parser; pub mod prelude; \ No newline at end of file diff --git a/rust/src/iaas/parser.rs b/rust/src/iaas/parser.rs deleted file mode 100644 index ece081b..0000000 --- a/rust/src/iaas/parser.rs +++ /dev/null @@ -1,129 +0,0 @@ -#![allow(unused)] - -use super::lexer::{Lexer, Token}; - -#[derive(Debug)] -pub enum ASTValue { - StringLiteral(String), - NumberLiteral(i64), -} - -#[derive(Debug)] -pub enum ASTNode { - ProviderBlock { - name: String, - properties: Vec<(String, ASTValue)>, - }, - ResourceBlock { - name: String, - resource_type: String, - properties: Vec<(String, ASTValue)>, - }, -} - -#[derive(Debug)] -pub struct Parser<'l> { - lexer: Lexer<'l>, - current_token: Token, -} - -impl<'l> Parser<'l> { - pub fn new(mut lexer: Lexer<'l>) -> Self { - let current_token = lexer.next_token(); - Self { - lexer, - current_token, - } - } - - pub fn next_token(&mut self) { - self.current_token = self.lexer.next_token(); - } - - pub fn parse_identifier(&mut self) -> String { - match self.current_token { - Token::Identifier(ref name) => { - let name = name.clone(); - self.next_token(); - name - } - _ => panic!("Expected identifier, found: {:?}", self.current_token), - } - } - - pub fn expect_token(&mut self, expected: Token) { - if self.current_token == expected { - self.next_token(); - } else { - panic!( - "Expected token {:?}, found {:?}", - expected, self.current_token - ); - } - } - - pub fn parse_properties(&mut self) -> Vec<(String, ASTValue)> { - let mut properties = Vec::new(); - while self.current_token != Token::RightBrace { - let key = self.parse_identifier(); - self.expect_token(Token::Equals); - let value = self.parse_value(); - properties.push((key, value)); - } - properties - } - - pub fn parse_value(&mut self) -> ASTValue { - match self.current_token { - Token::StringLiteral(ref value) => { - let value = value.clone(); - self.next_token(); - ASTValue::StringLiteral(value) - } - Token::NumberLiteral(value) => { - self.next_token(); - ASTValue::NumberLiteral(value) - } - _ => panic!("Expected value, found: {:?}", self.current_token), - } - } - - pub fn parse_provider_block(&mut self) -> ASTNode { - self.next_token(); - let name = self.parse_identifier(); - self.expect_token(Token::LeftBrace); - let properties = self.parse_properties(); - self.expect_token(Token::RightBrace); - ASTNode::ProviderBlock { name, properties } - } - - pub fn parse_resource_block(&mut self) -> ASTNode { - self.next_token(); - let resource_type = self.parse_identifier(); - let name = self.parse_identifier(); - self.expect_token(Token::LeftBrace); - let properties = self.parse_properties(); - self.expect_token(Token::RightBrace); - ASTNode::ResourceBlock { - name, - resource_type, - properties, - } - } - - pub fn parse(&mut self) -> Vec { - let mut nodes = Vec::new(); - while self.current_token != Token::EOF { - match self.current_token { - Token::Provider => { - nodes.push(self.parse_provider_block()); - } - Token::Resource => { - nodes.push(self.parse_resource_block()); - } - _ => panic!("Unexpected token: {:?}", self.current_token), - } - } - nodes - } -} diff --git a/rust/src/iaas/prelude.rs b/rust/src/iaas/prelude.rs index a643e62..45850dd 100644 --- a/rust/src/iaas/prelude.rs +++ b/rust/src/iaas/prelude.rs @@ -1 +1 @@ -pub use crate::iaas::{interpreter::*, lexer::*, parser::*}; +pub use crate::iaas::*; diff --git a/rust/src/iaas/samples/postgres.conf b/rust/src/iaas/samples/postgres.conf new file mode 100644 index 0000000..bef9448 --- /dev/null +++ b/rust/src/iaas/samples/postgres.conf @@ -0,0 +1,3 @@ +database { + name = "" +} \ No newline at end of file diff --git a/rust/src/iaas/samples/scratch.tf b/rust/src/iaas/samples/scratch.tf deleted file mode 100644 index 485b329..0000000 --- a/rust/src/iaas/samples/scratch.tf +++ /dev/null @@ -1,9 +0,0 @@ -provider "render" { - api_key = "rnd_xxxxXXXXxxxxXXXXxxxXX" -} - -resource "render_service" "example" { - name = "example-service" - environment = "production" - replicas = 3 -} diff --git a/rust/src/main.rs b/rust/src/main.rs index 655d1f5..c7f67e0 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -25,28 +25,9 @@ async fn main() { //////////////////////////////////////////////// /// /// 2. Using Terraform for resource provisioning - let input = r#" - provider "render" { - api_key = "rnd_xxxxXXXXxxxxXXXXxxxXX" - } - - resource "render_service" "example" { - name = "example-service" - environment = "production" - replicas = 3 - } - "#; + let input = ""; - let lexer = Lexer::new(input); - let mut parser = Parser::new(lexer); - let ast = parser.parse(); - let interpreter = Interpreter::new(); - let results = interpreter.interpret(ast).await; - for result in results { - println!("lol"); - println!("{}", result); - } } /// Checks for regression of service management functions