|
3 | 3 | use ::biscuit_auth::RootKeyProvider;
|
4 | 4 | use ::biscuit_auth::UnverifiedBiscuit;
|
5 | 5 | use chrono::DateTime;
|
| 6 | +use chrono::Duration; |
6 | 7 | use chrono::TimeZone;
|
7 | 8 | use chrono::Utc;
|
8 | 9 | use std::collections::BTreeSet;
|
9 | 10 | use std::collections::HashMap;
|
10 | 11 |
|
11 |
| -use ::biscuit_auth::{builder, error, Authorizer, Biscuit, KeyPair, PrivateKey, PublicKey}; |
| 12 | +use ::biscuit_auth::{ |
| 13 | + builder, error, Authorizer, AuthorizerLimits, Biscuit, KeyPair, PrivateKey, PublicKey, |
| 14 | +}; |
12 | 15 |
|
13 | 16 | use pyo3::exceptions::PyValueError;
|
14 | 17 | use pyo3::prelude::*;
|
@@ -341,6 +344,17 @@ impl PyBiscuit {
|
341 | 344 | #[pyclass(name = "Authorizer")]
|
342 | 345 | pub struct PyAuthorizer(Authorizer);
|
343 | 346 |
|
| 347 | +#[pyclass(name = "AuthorizerLimits")] |
| 348 | +#[derive(Clone)] |
| 349 | +pub struct PyAuthorizerLimits { |
| 350 | + #[pyo3(get, set)] |
| 351 | + pub max_facts: u64, |
| 352 | + #[pyo3(get, set)] |
| 353 | + pub max_iterations: u64, |
| 354 | + #[pyo3(get, set)] |
| 355 | + pub max_time: Duration, |
| 356 | +} |
| 357 | + |
344 | 358 | #[pymethods]
|
345 | 359 | impl PyAuthorizer {
|
346 | 360 | /// Create a new authorizer from a datalog snippet and optional parameter values
|
@@ -446,6 +460,29 @@ impl PyAuthorizer {
|
446 | 460 | .map_err(|e| DataLogError::new_err(e.to_string()))
|
447 | 461 | }
|
448 | 462 |
|
| 463 | + /// Returns the runtime limits of the authorizer |
| 464 | + /// |
| 465 | + /// Those limits cover all the executions under the `authorize`, `query` and `query_all` methods |
| 466 | + pub fn limits(&self) -> PyAuthorizerLimits { |
| 467 | + let limits = self.0.limits(); |
| 468 | + PyAuthorizerLimits { |
| 469 | + max_facts: limits.max_facts, |
| 470 | + max_iterations: limits.max_iterations, |
| 471 | + max_time: Duration::from_std(limits.max_time).expect("Duration out of range"), |
| 472 | + } |
| 473 | + } |
| 474 | + |
| 475 | + /// Sets the runtime limits of the authorizer |
| 476 | + /// |
| 477 | + /// Those limits cover all the executions under the `authorize`, `query` and `query_all` methods |
| 478 | + pub fn set_limits(&mut self, limits: &PyAuthorizerLimits) { |
| 479 | + self.0.set_limits(AuthorizerLimits { |
| 480 | + max_facts: limits.max_facts, |
| 481 | + max_iterations: limits.max_iterations, |
| 482 | + max_time: Duration::to_std(&limits.max_time).expect("Duration out of range"), |
| 483 | + }) |
| 484 | + } |
| 485 | + |
449 | 486 | /// Merge another `Authorizer` in this `Authorizer`. The `Authorizer` argument will not be modified
|
450 | 487 | ///
|
451 | 488 | /// :param builder: an Authorizer
|
|
0 commit comments