Skip to content

Commit da014bc

Browse files
authored
Merge pull request #54 from biscuit-auth/display-authorizer-stats
Display evaluation time and iterations after authorization
2 parents c53834c + 87d2191 commit da014bc

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/inspect.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use biscuit_auth::{
88
use chrono::offset::Utc;
99
use serde::Serialize;
1010
use serde_json::json;
11-
use std::path::PathBuf;
1211
use std::{fmt::Display, fs};
12+
use std::{path::PathBuf, time::Duration};
1313

1414
use crate::cli::*;
1515
use crate::errors::CliError::*;
@@ -127,17 +127,29 @@ impl Display for QueryResult {
127127
struct AuthResult {
128128
policies: Vec<String>,
129129
result: RResult<(usize, String), Token>,
130+
iterations: u64,
131+
elapsed: Duration,
130132
}
131133

132134
impl Display for AuthResult {
133135
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
134136
match &self.result.clone().into_result() {
135137
Ok((_, policy)) => {
136-
writeln!(f, "✅ Authorizer check succeeded 🛡️")?;
138+
writeln!(
139+
f,
140+
"✅ Authorizer check succeeded 🛡️ ({}μs, {} iterations)",
141+
self.elapsed.as_micros(),
142+
self.iterations,
143+
)?;
137144
writeln!(f, "Matched allow policy: {}", policy)
138145
}
139146
Err(e) => {
140-
writeln!(f, "❌ Authorizer check failed 🛡️")?;
147+
writeln!(
148+
f,
149+
"❌ Authorizer check failed 🛡️ ({}μs, {} iterations)",
150+
self.elapsed.as_micros(),
151+
self.iterations,
152+
)?;
141153
match e {
142154
Token::FailedLogic(l) => display_logic_error(f, &self.policies, l),
143155
Token::RunLimit(l) => display_run_limit(f, l),
@@ -445,6 +457,8 @@ pub fn handle_inspect_inner(inspect: &Inspect) -> Result<InspectionResults> {
445457
)
446458
})
447459
.into(),
460+
iterations: authorizer_builder.iterations(),
461+
elapsed: authorizer_builder.execution_time(),
448462
});
449463

450464
if let Some(snapshot_file) = &inspect.dump_snapshot_to {
@@ -600,6 +614,8 @@ pub fn handle_inspect_snapshot_inner(
600614
)
601615
})
602616
.into(),
617+
iterations: authorizer.iterations(),
618+
elapsed: authorizer.execution_time(),
603619
});
604620
} else {
605621
auth_result = None;

0 commit comments

Comments
 (0)