//! Authentication client types
use surrealdb::opt::auth::{Database, Namespace, Root};
use thiserror::Error;
/// Credentials level
#[derive(Debug, Clone)]
pub enum CredentialsLevel {
Root,
Namespace,
Database,
}
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Username is needed for authentication but it was not provided")]
Username,
#[error("Password is needed for authentication but it was not provided")]
Password,
#[error("Namespace is needed for authentication but it was not provided")]
Namespace,
#[error("Database is needed for authentication but it was not provided")]
Database,
}
/// Construct a Credentials instance for the given auth level
#[derive(Debug, Default)]
pub struct CredentialsBuilder<'a> {
/// The auth username
pub username: Option<&'a str>,
/// The auth password
pub password: Option<&'a str>,
/// The auth namespace
pub namespace: Option<&'a str>,
/// The auth database
pub database: Option<&'a str>,
}
impl<'a> CredentialsBuilder<'a> {
// Builder methods
pub fn with_username(mut self, username: impl Into