use crate::errors::FnError;
#[derive(Clone, Debug, Default)]
pub struct ConnectorConfig {
pub config_json: String,
}
#[derive(Clone, Copy, Debug)]
pub struct ConnectorHandle(pub u64);
pub trait Connector: Send + Sync {
fn protocol(&self) -> &str;
fn start(&self, cfg: ConnectorConfig) -> Result<ConnectorHandle, FnError>;
fn stop(&self, handle: ConnectorHandle) -> Result<(), FnError>;
}
#[derive(Clone, Debug)]
pub enum Credentials {
Basic {
username: String,
password: String,
},
Bearer(String),
MtlsCert(Vec<u8>),
}
#[derive(Clone, Debug)]
pub struct Principal {
pub id: String,
pub groups: Vec<String>,
pub capabilities: crate::CapabilitySet,
}
impl Principal {
#[must_use]
pub fn anonymous() -> Self {
Self {
id: "anonymous".to_owned(),
groups: Vec::new(),
capabilities: crate::CapabilitySet::new(),
}
}
}
#[derive(Clone, Debug, thiserror::Error)]
#[error("authentication failure: {0}")]
pub struct AuthError(pub String);
pub trait AuthProvider: Send + Sync {
fn scheme(&self) -> &str;
fn authenticate(&self, credentials: &Credentials) -> Result<Principal, AuthError>;
}
#[derive(Clone, Debug)]
pub struct Action {
pub verb: String,
}
#[derive(Clone, Debug)]
pub struct Resource {
pub path: String,
}
#[derive(Clone, Debug)]
pub enum Decision {
Allow,
Deny {
reason: String,
},
}
#[derive(Clone, Debug, thiserror::Error)]
#[error("authorization policy failure: {0}")]
pub struct AuthzError(pub String);
pub trait AuthzPolicy: Send + Sync {
fn check(
&self,
principal: &Principal,
action: &Action,
resource: &Resource,
) -> Result<Decision, AuthzError>;
}