Skip to content

Commit 7d7f23f

Browse files
authored
* opa works (#106)
* cargo fix now works * check_overwrite now doesn't delete entire dir but only warns about overwrite
1 parent a3c85b9 commit 7d7f23f

5 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/generator/common.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ macro_rules! cargo_command {
2727
/// checks if project with name already exists, if yes asks for permission to overwrite
2828
pub fn check_for_overwrite(output_path: &Path, project_title: &str) {
2929
if output_path.exists() {
30-
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());
30+
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());
3131
let mut input = String::new();
3232
match std::io::stdin().read_line(&mut input) {
3333
Ok(_) => {
3434
if input.trim() != "y" {
3535
println!("Aborting generation...");
3636
std::process::exit(0);
3737
}
38-
std::fs::remove_dir_all(output_path).unwrap();
3938
}
4039
Err(err) => {
4140
println!("❌ Error reading input: {}", err);

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ fn main() {
6565
"fix",
6666
"--manifest-path",
6767
output_path.join("Cargo.toml"),
68-
"--allow-dirty"
68+
"--allow-dirty",
69+
"--allow-staged"
6970
);
7071

7172
if args.doc {

templates/src/handler/$$producer$$.rs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use log::{debug, warn, error};
4141
match serde_json::from_value::<{{ .payload.struct_reference }}>(payload) {
4242
Ok(deserialized_message) => {
4343
debug!("Received message {:#?}", deserialized_message);
44-
let policy_reply = opa_eval(message);
44+
let policy_reply = opa_eval(&deserialized_message);
4545
// TODO: Replace this with your own handler code
4646
{{ if eq .payload.model_type "enum"}}
4747
match deserialized_message {
@@ -87,12 +87,12 @@ use log::{debug, warn, error};
8787
{{ end }}
8888
match serde_json::from_value::<{{ .payload.struct_reference }}>(payload) {
8989
Ok(deserialized_message) => {
90+
let policy_reply = opa_eval(&deserialized_message);
9091
{{ if eq .payload.model_type "enum"}}
9192
match deserialized_message {
9293
{{$enumName := .payload.unique_id}}
9394
{{ range .payload.related_models }}
9495
{{ $enumName }}::{{ .unique_id }}(payload) => {
95-
let policy_reply = opa_eval(message);
9696
// TODO: Replace this with your own handler code
9797
debug!("Received message payload {{ .unique_id }} {:?}", payload);
9898
}

templates/src/policy/mod.rs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod policy;
2-
use policy::*;
2+
use policy::*;

templates/src/policy/policy.rs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use anyhow::{anyhow, Result};
22
use opa_wasm::Runtime;
33
use reqwest::{self, Body, Client, IntoUrl, Response};
44
use serde::Serialize;
5-
use std::{env, fs, path::Path};
5+
use std::env;
66
use wasmtime::{Config, Engine, Module, Store};
77

8-
pub async fn opa_eval<I>(input: I) -> Result<serde_json::Value>
8+
pub async fn opa_eval<I>(input: &I) -> Result<serde_json::Value>
99
where
10-
Body: From<I>,
1110
I: Serialize,
1211
{
1312
if let Ok(enabled) = env::var("OPA_ENABLED") {
@@ -18,7 +17,7 @@ where
1817
}
1918
if let Ok(url) = env::var("OPA_REMOTE_URL") {
2019
let url: String = url.parse().unwrap();
21-
return opa_eval_remote(url, input).await;
20+
return opa_eval_remote(url, serde_json::to_string(&input)?).await;
2221
}
2322
if let Ok(path) = env::var("OPA_LOCAL_WASM_PATH") {
2423
let path: String = path.parse().unwrap();

0 commit comments

Comments
 (0)