2022-01-13 07:29:41 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd)]
|
|
|
|
pub enum Level {
|
|
|
|
No,
|
|
|
|
Kv,
|
|
|
|
Ns,
|
|
|
|
Db,
|
|
|
|
Sc,
|
|
|
|
}
|
|
|
|
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies the authentication level for the datastore execution context.
|
2022-01-13 07:29:41 +00:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd)]
|
|
|
|
pub enum Auth {
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies that the user is not authenticated
|
2022-01-13 07:29:41 +00:00
|
|
|
No,
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies that the user is authenticated with full root permissions
|
2022-01-13 07:29:41 +00:00
|
|
|
Kv,
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies that the user is has full permissions for a particular Namespace
|
2022-01-13 07:29:41 +00:00
|
|
|
Ns(String),
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies that the user is has full permissions for a particular Namespace and Database
|
2022-01-13 07:29:41 +00:00
|
|
|
Db(String, String),
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Specifies that the user is has full permissions for a particular Namespace, Database, and Scope
|
2022-01-13 07:29:41 +00:00
|
|
|
Sc(String, String, String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Auth {
|
|
|
|
fn default() -> Self {
|
|
|
|
Auth::No
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Auth {
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Checks whether permissions clauses need to be processed
|
|
|
|
pub(crate) fn perms(&self) -> bool {
|
2022-04-04 22:26:54 +00:00
|
|
|
match self {
|
|
|
|
Auth::No => true,
|
|
|
|
Auth::Sc(_, _, _) => true,
|
|
|
|
Auth::Db(_, _) => false,
|
|
|
|
Auth::Ns(_) => false,
|
|
|
|
Auth::Kv => false,
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 23:38:16 +00:00
|
|
|
/// Checks whether the current authentication matches the required level
|
|
|
|
pub(crate) fn check(&self, level: Level) -> bool {
|
2022-01-13 07:29:41 +00:00
|
|
|
match self {
|
2022-03-04 16:01:32 +00:00
|
|
|
Auth::No => matches!(level, Level::No),
|
2022-03-31 23:36:23 +00:00
|
|
|
Auth::Sc(_, _, _) => matches!(level, Level::No | Level::Sc),
|
|
|
|
Auth::Db(_, _) => matches!(level, Level::No | Level::Sc | Level::Db),
|
|
|
|
Auth::Ns(_) => matches!(level, Level::No | Level::Sc | Level::Db | Level::Ns),
|
|
|
|
Auth::Kv => true,
|
2022-01-13 07:29:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|