Skip to content

Commit

Permalink
Removed State from the EFlintJsonReasoner
Browse files Browse the repository at this point in the history
  • Loading branch information
Lut99 committed Nov 6, 2024
1 parent 677e650 commit c5a137f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
9 changes: 5 additions & 4 deletions examples/eflint_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created:
// 10 Oct 2024, 13:54:17
// Last edited:
// 17 Oct 2024, 12:07:02
// 06 Nov 2024, 14:59:22
// Auto updated?
// Yes
//
Expand All @@ -18,11 +18,12 @@ use std::path::PathBuf;

use clap::Parser;
use console::style;
use eflint_json_reasoner::json::spec::Phrase;
use error_trace::trace;
use policy_reasoner::loggers::file::FileLogger;
use policy_reasoner::reasoners::eflint_json::json::spec::RequestPhrases;
use policy_reasoner::reasoners::eflint_json::reasons::EFlintSilentReasonHandler;
use policy_reasoner::reasoners::eflint_json::{EFlintJsonReasonerConnector, State};
use policy_reasoner::reasoners::eflint_json::EFlintJsonReasonerConnector;
use policy_reasoner::spec::auditlogger::SessionedAuditLogger;
use policy_reasoner::spec::reasonerconn::ReasonerConnector as _;
use policy_reasoner::spec::reasons::NoReason;
Expand Down Expand Up @@ -181,7 +182,7 @@ async fn main() {
};

// Create the reasoner
let conn = match EFlintJsonReasonerConnector::<EFlintSilentReasonHandler, (), ()>::new_async(
let conn = match EFlintJsonReasonerConnector::<EFlintSilentReasonHandler, Vec<Phrase>, ()>::new_async(
&args.address,
EFlintSilentReasonHandler,
&mut logger,
Expand All @@ -194,7 +195,7 @@ async fn main() {
std::process::exit(1);
},
};
let verdict: ReasonerResponse<NoReason> = match conn.consult(State { policy: policy.phrases, state: () }, (), &mut logger).await {
let verdict: ReasonerResponse<NoReason> = match conn.consult(policy.phrases, (), &mut logger).await {
Ok(res) => res,
Err(err) => {
error!("{}", trace!(("Failed to send message to reasoner at {:?}", args.address), err));
Expand Down
17 changes: 4 additions & 13 deletions lib/reasoners/eflint-json/src/reasonerconn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created:
// 09 Oct 2024, 15:52:06
// Last edited:
// 06 Nov 2024, 14:25:12
// 06 Nov 2024, 14:59:35
// Auto updated?
// Yes
//
Expand Down Expand Up @@ -130,15 +130,6 @@ impl spec::context::Context for Context {
fn kind(&self) -> &str { "eflint-json" }
}

/// Defines the eFLINT reasoner state to submit to it.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct State<S> {
/// The policy used.
pub policy: Vec<Phrase>,
/// The rest of the state that is appended to the end of the request.
pub state: S,
}




Expand Down Expand Up @@ -210,7 +201,7 @@ where
type Error = Error<R::Error, S::Error, Q::Error>;
type Question = Q;
type Reason = R::Reason;
type State = State<S>;
type State = S;

fn consult<'a, L>(
&'a self,
Expand All @@ -229,8 +220,8 @@ where

// Build the full policy
debug!("Building full policy...");
let mut phrases: Vec<Phrase> = state.policy;
phrases.extend(state.state.to_eflint().map_err(|err| Error::StateToEFlint { err })?);
let mut phrases: Vec<Phrase> = Vec::new();
phrases.extend(state.to_eflint().map_err(|err| Error::StateToEFlint { err })?);
phrases.extend(question.to_eflint().map_err(|err| Error::QuestionToEFlint { err })?);
debug!("Full request length: {} phrase(s)", phrases.len());

Expand Down

0 comments on commit c5a137f

Please sign in to comment.