Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed opa #106

Merged
merged 2 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/generator/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ 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(_) => {
if input.trim() != "y" {
println!("Aborting generation...");
std::process::exit(0);
}
std::fs::remove_dir_all(output_path).unwrap();
}
Err(err) => {
println!("❌ Error reading input: {}", err);
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ fn main() {
"fix",
"--manifest-path",
output_path.join("Cargo.toml"),
"--allow-dirty"
"--allow-dirty",
"--allow-staged"
);

if args.doc {
Expand Down
4 changes: 2 additions & 2 deletions templates/src/handler/$$producer$$.rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/src/policy/mod.rs.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod policy;
use policy::*;
use policy::*;
7 changes: 3 additions & 4 deletions templates/src/policy/policy.rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<I>(input: I) -> Result<serde_json::Value>
pub async fn opa_eval<I>(input: &I) -> Result<serde_json::Value>
where
Body: From<I>,
I: Serialize,
{
if let Ok(enabled) = env::var("OPA_ENABLED") {
Expand All @@ -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();
Expand Down