Skip to main content

Policy

Trait Policy 

Source
pub trait Policy:
    Sized
    + Send
    + Sync
    + 'static {
    type Refusal: HostError;
    type Failure: HostError + Clone + From<EngineFailure<Self::Failure, Self::Refusal>>;
    type Scope;

    // Required methods
    fn judge(&self, action: &PolicyAction<'_>) -> Result<(), Self::Refusal>;
    fn check_sql(&self, tokens: &[Token]) -> Result<(), Self::Refusal>;
    fn begin_app_call(&self);
    fn host_object(&self, name: &str) -> bool;
    fn statement_key(&self) -> u64;
    fn enter(&self, scope: &Self::Scope);
    fn leave(&self, scope: &Self::Scope);
    fn refresh(&self, sql: &HostSql<Self>, extent: Refresh) -> Result<()>;
}
Expand description

What the host adds to the authorizer’s rules.

Required Associated Types§

Source

type Refusal: HostError

What the policy refuses a statement with.

Source

type Failure: HostError + Clone + From<EngineFailure<Self::Failure, Self::Refusal>>

What the host’s handle fails with: the host’s own failures, and sqlive’s, which the host converts into this type through From.

Source

type Scope

A part of the host’s work the policy judges differently, which the host runs through HostSql::within.

Required Methods§

Source

fn judge(&self, action: &PolicyAction<'_>) -> Result<(), Self::Refusal>

Judge an action the authorizer’s rules allowed; Err refuses the statement with it. A host statement’s actions come here too, so the policy sees every action allowed.

Source

fn check_sql(&self, tokens: &[Token]) -> Result<(), Self::Refusal>

Judge an app statement’s text before it is prepared.

Source

fn begin_app_call(&self)

A new app call begins: forget what the last statement left.

Source

fn host_object(&self, name: &str) -> bool

Whether name, a trigger or view, is the host’s own object.

Source

fn statement_key(&self) -> u64

What the policy adds to the app statement cache’s key.

Source

fn enter(&self, scope: &Self::Scope)

Work in scope begins.

Source

fn leave(&self, scope: &Self::Scope)

Work in scope ended, on any path out of it, a panic’s included.

Source

fn refresh(&self, sql: &HostSql<Self>, extent: Refresh) -> Result<()>

Read again what the policy keeps of the connection’s schema: all of it, or what changed since it last read. The connection calls it with Refresh::Whole as it opens and with Refresh::Changed before each app statement, and the host through refresh_policy.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§