diff --git a/src/generator/common.rs b/src/generator/common.rs index ec4c6ab..c884c42 100644 --- a/src/generator/common.rs +++ b/src/generator/common.rs @@ -27,7 +27,7 @@ macro_rules! cargo_command { /// checks if project with name already exists, if yes asks for permission to overwrite pub fn check_for_overwrite(output_path: &Path, project_title: &str) { if output_path.exists() { - println!("\nA project with the name {} already exists in the current directory: {}. Do you want to overwrite it? \n\nā— WARNING: This will permanently delete all files in the directory! \n\nType 'y' to continue or anything else to exit.", project_title, output_path.to_string_lossy()); + println!("\nA project with the name {} already exists in the current directory: {}. Do you want to overwrite it? \n\nā— WARNING: Existing files within the folder will be permanently replaced by newly generated files. \n\nType 'y' to continue or anything else to exit.", project_title, output_path.to_string_lossy()); let mut input = String::new(); match std::io::stdin().read_line(&mut input) { Ok(_) => { @@ -35,7 +35,6 @@ pub fn check_for_overwrite(output_path: &Path, project_title: &str) { println!("Aborting generation..."); std::process::exit(0); } - std::fs::remove_dir_all(output_path).unwrap(); } Err(err) => { println!("āŒ Error reading input: {}", err); diff --git a/src/main.rs b/src/main.rs index c8bf353..793e5dd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,8 @@ fn main() { "fix", "--manifest-path", output_path.join("Cargo.toml"), - "--allow-dirty" + "--allow-dirty", + "--allow-staged" ); if args.doc { diff --git a/templates/src/handler/$$producer$$.rs.go b/templates/src/handler/$$producer$$.rs.go index 8933343..a99ad2f 100644 --- a/templates/src/handler/$$producer$$.rs.go +++ b/templates/src/handler/$$producer$$.rs.go @@ -41,7 +41,7 @@ use log::{debug, warn, error}; match serde_json::from_value::<{{ .payload.struct_reference }}>(payload) { Ok(deserialized_message) => { debug!("Received message {:#?}", deserialized_message); - let policy_reply = opa_eval(message); + let policy_reply = opa_eval(&deserialized_message); // TODO: Replace this with your own handler code {{ if eq .payload.model_type "enum"}} match deserialized_message { @@ -87,12 +87,12 @@ use log::{debug, warn, error}; {{ end }} match serde_json::from_value::<{{ .payload.struct_reference }}>(payload) { Ok(deserialized_message) => { + let policy_reply = opa_eval(&deserialized_message); {{ if eq .payload.model_type "enum"}} match deserialized_message { {{$enumName := .payload.unique_id}} {{ range .payload.related_models }} {{ $enumName }}::{{ .unique_id }}(payload) => { - let policy_reply = opa_eval(message); // TODO: Replace this with your own handler code debug!("Received message payload {{ .unique_id }} {:?}", payload); } diff --git a/templates/src/policy/mod.rs.go b/templates/src/policy/mod.rs.go index b17976e..32156d6 100644 --- a/templates/src/policy/mod.rs.go +++ b/templates/src/policy/mod.rs.go @@ -1,2 +1,2 @@ pub mod policy; -use policy::*; +use policy::*; \ No newline at end of file diff --git a/templates/src/policy/policy.rs.go b/templates/src/policy/policy.rs.go index 4656a86..4c57d92 100644 --- a/templates/src/policy/policy.rs.go +++ b/templates/src/policy/policy.rs.go @@ -2,12 +2,11 @@ use anyhow::{anyhow, Result}; use opa_wasm::Runtime; use reqwest::{self, Body, Client, IntoUrl, Response}; use serde::Serialize; -use std::{env, fs, path::Path}; +use std::env; use wasmtime::{Config, Engine, Module, Store}; -pub async fn opa_eval(input: I) -> Result +pub async fn opa_eval(input: &I) -> Result where - Body: From, I: Serialize, { if let Ok(enabled) = env::var("OPA_ENABLED") { @@ -18,7 +17,7 @@ where } if let Ok(url) = env::var("OPA_REMOTE_URL") { let url: String = url.parse().unwrap(); - return opa_eval_remote(url, input).await; + return opa_eval_remote(url, serde_json::to_string(&input)?).await; } if let Ok(path) = env::var("OPA_LOCAL_WASM_PATH") { let path: String = path.parse().unwrap();