#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AccountAuditEvent {
pub kind: String,
pub actor: String,
pub actor_machine: bool,
pub target: String,
pub detail: String,
pub refused: bool,
}
impl AccountAuditEvent {
pub fn by(caller: &crate::auth::Caller, kind: &str, target: impl Into<String>) -> Self {
AccountAuditEvent {
kind: kind.to_owned(),
actor: caller.principal_id.clone(),
actor_machine: caller.machine,
target: target.into(),
detail: String::new(),
refused: false,
}
}
pub fn detail(mut self, detail: impl Into<String>) -> Self {
self.detail = detail.into();
self
}
pub fn refused(mut self) -> Self {
self.refused = true;
self
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AccountAuditQuery {
pub kinds: Vec<String>,
pub actor: String,
pub since_unix_ms: i64,
pub until_unix_ms: i64,
pub text: String,
pub before_seq: Option<u64>,
pub limit: u32,
}
impl AccountAuditQuery {
pub fn from_filter(filter: Option<&gunnar_proto::AuditFilter>, before_seq: Option<u64>, limit: u32) -> Self {
let filter = filter.cloned().unwrap_or_default();
AccountAuditQuery {
kinds: filter.kinds.into_iter().map(|k| k.trim().to_owned()).filter(|k| !k.is_empty()).collect(),
actor: filter.actor.trim().to_owned(),
since_unix_ms: filter.since_unix_ms,
until_unix_ms: filter.until_unix_ms,
text: filter.text.trim().to_owned(),
before_seq,
limit,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NameVerdict {
pub verdict: String,
pub sentence: String,
}
impl NameVerdict {
pub fn clean() -> Self {
NameVerdict {
verdict: "clean".to_owned(),
sentence: String::new(),
}
}
pub fn is_clean(&self) -> bool {
self.verdict == "clean"
}
pub fn is_borderline(&self) -> bool {
self.verdict == "borderline"
}
pub fn is_reserved(&self) -> bool {
self.verdict == "reserved"
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct OperatorAccessDecision {
pub request_id: String,
pub approver: String,
pub approve: bool,
pub minutes: Option<u32>,
pub step_up: Option<(Vec<u8>, u32)>,
}
use crate::seam::ControlResult;
pub trait EnterprisePlane: Send + Sync {
fn account_of_namespace(&self, namespace: &str) -> ControlResult<Option<String>>;
fn account_of_principal(&self, principal_id: &str) -> ControlResult<Option<String>>;
fn is_account_admin(&self, principal_id: &str, account: &str) -> ControlResult<bool>;
fn shielded(&self, principal_id: &str, namespace: &str) -> ControlResult<bool>;
fn account_audit_record(&self, account: &str, event: &AccountAuditEvent) -> ControlResult<()>;
fn account_audit_log(&self, account: &str, query: &AccountAuditQuery) -> ControlResult<gunnar_proto::AuditLogResponse>;
fn account_audit_export(
&self,
account: &str,
query: &AccountAuditQuery,
format: gunnar_proto::AuditExportFormat,
) -> ControlResult<gunnar_proto::ExportAuditLogResponse>;
fn aggregates(&self) -> ControlResult<gunnar_proto::AggregatesResponse>;
fn operator_access_request(
&self,
account: &str,
operator: &str,
reason: &str,
minutes: u32,
) -> ControlResult<gunnar_proto::OperatorAccess>;
fn operator_access_list(&self, account: Option<&str>) -> ControlResult<Vec<gunnar_proto::OperatorAccess>>;
fn operator_access_get(&self, request_id: &str) -> ControlResult<Option<gunnar_proto::OperatorAccess>>;
fn operator_access_decide(&self, decision: &OperatorAccessDecision) -> ControlResult<gunnar_proto::OperatorAccess>;
fn operator_access_revoke(&self, request_id: &str, by: &str) -> ControlResult<gunnar_proto::OperatorAccess>;
fn name_check(&self, kind: &str, name: &str, account: &str) -> ControlResult<NameVerdict>;
fn name_review_add(
&self,
kind: &str,
name: &str,
account: &str,
actor: &str,
hold: bool,
) -> ControlResult<gunnar_proto::NameReview>;
fn name_lists(&self) -> ControlResult<gunnar_proto::NameLists>;
fn set_name_lists(&self, lists: gunnar_proto::NameLists) -> ControlResult<gunnar_proto::NameLists>;
fn name_reviews(&self, account: &str) -> ControlResult<Vec<gunnar_proto::NameReview>>;
fn name_review_decide(&self, account: &str, id: &str, allow: bool, by: &str) -> ControlResult<gunnar_proto::NameReview>;
}
pub fn no_plane() -> crate::seam::ControlError {
crate::seam::ControlError::Unimplemented("the enterprise list needs gunnar's stores (this plane has none)")
}