From cc40e26e3f7b90f43d4f700ef73deaef47b7813a Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 9 May 2022 23:58:25 +0100 Subject: [PATCH] Add additional functions on Auth type for validating authentication --- lib/src/dbs/auth.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/src/dbs/auth.rs b/lib/src/dbs/auth.rs index 4fcb29fd..2c383d8e 100644 --- a/lib/src/dbs/auth.rs +++ b/lib/src/dbs/auth.rs @@ -1,3 +1,4 @@ +/// The authentication level for a datastore execution context. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd)] pub enum Level { No, @@ -7,7 +8,7 @@ pub enum Level { Sc, } -/// Specifies the authentication level for the datastore execution context. +/// Specifies the current authentication for the datastore execution context. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd)] pub enum Auth { /// Specifies that the user is not authenticated @@ -29,6 +30,26 @@ impl Default for Auth { } impl Auth { + /// Checks whether the current authentication has root level permissions + pub fn is_kv(&self) -> bool { + self.check(Level::Kv) + } + /// Checks whether the current authentication has namespace level permissions + pub fn is_ns(&self) -> bool { + self.check(Level::Ns) + } + /// Checks whether the current authentication has database level permissions + pub fn is_db(&self) -> bool { + self.check(Level::Db) + } + /// Checks whether the current authentication has scope level permissions + pub fn is_sc(&self) -> bool { + self.check(Level::Sc) + } + /// Checks whether the current authentication is unauthenticated + pub fn is_no(&self) -> bool { + self.check(Level::Sc) + } /// Checks whether permissions clauses need to be processed pub(crate) fn perms(&self) -> bool { match self {