pub struct Capabilities { /* private fields */ }
Expand description
Capabilities are used to limit what a user can do to the system.
Capabilities are split into 4 categories:
- Scripting: Whether or not the user can execute scripts
- Guest access: Whether or not a non-authenticated user can execute queries on the system when authentication is enabled.
- Functions: Whether or not the user can execute certain functions
- Network: Whether or not the user can access certain network addresses
Capabilities are configured globally. By default, capabilities are configured as:
- Scripting: false
- Guest access: false
- Functions: All functions are allowed
- Network: No network address is allowed nor denied, hence all network addresses are denied unless explicitly allowed
The capabilities are defined using allow/deny lists for fine-grained control.
Examples:
- Allow all functions:
--allow-funcs
- Allow all functions except
http.*
:--allow-funcs --deny-funcs 'http.*'
- Allow all network addresses except AWS metadata endpoint:
--allow-net --deny-net='169.254.169.254'
§Examples
Create a new instance, and allow all capabilities
let capabilities = Capabilities::all();
let config = Config::default().capabilities(capabilities);
let db = Surreal::new::<File>(("temp.db", config)).await?;
Create a new instance, and allow certain functions
let capabilities = Capabilities::default()
.with_functions(Targets::<FuncTarget>::All)
.without_functions(Targets::<FuncTarget>::Some(
[FuncTarget::from_str("http::*").unwrap()].into(),
));
let config = Config::default().capabilities(capabilities);
let db = Surreal::new::<File>(("temp.db", config)).await?;
Implementations§
Source§impl Capabilities
impl Capabilities
pub fn all() -> Self
pub fn with_scripting(self, scripting: bool) -> Self
pub fn with_guest_access(self, guest_access: bool) -> Self
pub fn with_live_query_notifications( self, live_query_notifications: bool, ) -> Self
pub fn with_functions(self, allow_funcs: Targets<FuncTarget>) -> Self
pub fn without_functions(self, deny_funcs: Targets<FuncTarget>) -> Self
pub fn with_network_targets(self, allow_net: Targets<NetTarget>) -> Self
pub fn without_network_targets(self, deny_net: Targets<NetTarget>) -> Self
pub fn allows_scripting(&self) -> bool
pub fn allows_guest_access(&self) -> bool
pub fn allows_live_query_notifications(&self) -> bool
pub fn allows_function(&self, target: &FuncTarget) -> bool
pub fn allows_network_target(&self, target: &NetTarget) -> bool
Trait Implementations§
Source§impl Clone for Capabilities
impl Clone for Capabilities
Source§fn clone(&self) -> Capabilities
fn clone(&self) -> Capabilities
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Capabilities
impl Debug for Capabilities
Source§impl Default for Capabilities
impl Default for Capabilities
Auto Trait Implementations§
impl Freeze for Capabilities
impl RefUnwindSafe for Capabilities
impl Send for Capabilities
impl Sync for Capabilities
impl Unpin for Capabilities
impl UnwindSafe for Capabilities
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more