Struct bonsaidb::server::CustomServer
source · pub struct CustomServer<B = NoBackend>where
B: Backend,{ /* private fields */ }
Expand description
A BonsaiDb server.
Implementations§
source§impl<B> CustomServer<B>where
B: Backend,
impl<B> CustomServer<B>where
B: Backend,
sourcepub async fn listen_for_tcp_on<S, T>(
&self,
addr: T,
service: S
) -> Result<(), Error>
pub async fn listen_for_tcp_on<S, T>( &self, addr: T, service: S ) -> Result<(), Error>
Listens for HTTP traffic on port
. This port will also receive
WebSocket
connections if feature websockets
is enabled.
sourcepub async fn listen_for_secure_tcp_on<S, T>(
&self,
addr: T,
service: S
) -> Result<(), Error>
pub async fn listen_for_secure_tcp_on<S, T>( &self, addr: T, service: S ) -> Result<(), Error>
Listens for HTTPS traffic on port
. This port will also receive
WebSocket
connections if feature websockets
is enabled. If feature
acme
is enabled, this connection will automatically manage the
server’s private key and certificate, which is also used for the
QUIC-based protocol.
source§impl<B> CustomServer<B>where
B: Backend,
impl<B> CustomServer<B>where
B: Backend,
sourcepub async fn listen_for_websockets_on<T>(
&self,
addr: T,
with_tls: bool
) -> Result<(), Error>
pub async fn listen_for_websockets_on<T>( &self, addr: T, with_tls: bool ) -> Result<(), Error>
Listens for websocket connections on addr
.
sourcepub fn upgrade_websocket(
&self,
peer_address: SocketAddr,
request: Request<Body>
) -> Response<Body>
pub fn upgrade_websocket( &self, peer_address: SocketAddr, request: Request<Body> ) -> Response<Body>
Handles upgrading an HTTP connection to the WebSocket
protocol based
on the upgrade request
. Requires feature hyper
to be enabled.
sourcepub async fn handle_websocket<S, E>(
&self,
connection: S,
peer_address: SocketAddr
)
pub async fn handle_websocket<S, E>( &self, connection: S, peer_address: SocketAddr )
Handles an established tokio-tungstenite
WebSocket
stream.
source§impl<B> CustomServer<B>where
B: Backend,
impl<B> CustomServer<B>where
B: Backend,
sourcepub async fn open(
configuration: ServerConfiguration<B>
) -> Result<CustomServer<B>, BackendError<<B as Backend>::Error>>
pub async fn open( configuration: ServerConfiguration<B> ) -> Result<CustomServer<B>, BackendError<<B as Backend>::Error>>
Opens a server using directory
for storage.
sourcepub fn pinned_certificate_path(&self) -> PathBuf
pub fn pinned_certificate_path(&self) -> PathBuf
Returns the path to the public pinned certificate, if this server has one. Note: this function will always succeed, but the file may not exist.
sourcepub fn primary_domain(&self) -> &str
pub fn primary_domain(&self) -> &str
Returns the primary domain configured for this server.
sourcepub async fn admin(&self) -> ServerDatabase<B>
pub async fn admin(&self) -> ServerDatabase<B>
Returns the administration database.
sourcepub async fn install_self_signed_certificate(
&self,
overwrite: bool
) -> Result<(), Error>
pub async fn install_self_signed_certificate( &self, overwrite: bool ) -> Result<(), Error>
Installs an X.509 certificate used for general purpose connections.
sourcepub async fn install_pem_certificate(
&self,
certificate_chain: &[u8],
private_key: &[u8]
) -> Result<(), Error>
pub async fn install_pem_certificate( &self, certificate_chain: &[u8], private_key: &[u8] ) -> Result<(), Error>
Installs a certificate chain and private key used for TLS connections.
sourcepub async fn install_certificate(
&self,
certificate_chain: &CertificateChain,
private_key: &PrivateKey
) -> Result<(), Error>
pub async fn install_certificate( &self, certificate_chain: &CertificateChain, private_key: &PrivateKey ) -> Result<(), Error>
Installs a certificate chain and private key used for TLS connections.
sourcepub async fn certificate_chain(&self) -> Result<CertificateChain, Error>
pub async fn certificate_chain(&self) -> Result<CertificateChain, Error>
Returns the current certificate chain.
sourcepub async fn listen_on(
&self,
config: impl Into<BonsaiListenConfig>
) -> Result<(), Error>
pub async fn listen_on( &self, config: impl Into<BonsaiListenConfig> ) -> Result<(), Error>
Listens for incoming client connections. Does not return until the server shuts down.
Listening on a port
When passing a u16
to this function, the server will begin listening
on an “unspecified” address. This typically is accessible to other
machines on the network/internet, so care should be taken to ensure this
is what is intended.
To ensure that the server only listens for local traffic, specify a local IP or localhost in addition to the port number.
sourcepub fn connected_clients(&self) -> Vec<ConnectedClient<B>>
pub fn connected_clients(&self) -> Vec<ConnectedClient<B>>
Returns all of the currently connected clients.
sourcepub fn broadcast<Api>(&self, response: &<Api as Api>::Response)where
Api: Api,
pub fn broadcast<Api>(&self, response: &<Api as Api>::Response)where
Api: Api,
Sends a custom API response to all connected clients.
sourcepub async fn shutdown(&self, timeout: Option<Duration>) -> Result<(), Error>
pub async fn shutdown(&self, timeout: Option<Duration>) -> Result<(), Error>
Shuts the server down. If a timeout
is provided, the server will stop
accepting new connections and attempt to respond to any outstanding
requests already being processed. After the timeout
has elapsed or if
no timeout
was provided, the server is forcefully shut down.
sourcepub async fn listen_for_shutdown(&self) -> Result<(), Error>
pub async fn listen_for_shutdown(&self) -> Result<(), Error>
Listens for signals from the operating system that the server should shut down and attempts to gracefully shut down.
Methods from Deref<Target = AsyncStorage>§
sourcepub async fn restore<L>(&self, location: L) -> Result<(), Error>where
L: AnyBackupLocation + 'static,
pub async fn restore<L>(&self, location: L) -> Result<(), Error>where
L: AnyBackupLocation + 'static,
Restores all data from a previously stored backup location
.
sourcepub async fn backup<L>(&self, location: L) -> Result<(), Error>where
L: AnyBackupLocation + 'static,
pub async fn backup<L>(&self, location: L) -> Result<(), Error>where
L: AnyBackupLocation + 'static,
Stores a copy of all data in this instance to location
.
sourcepub fn with_effective_permissions(
&self,
effective_permissions: Permissions
) -> Option<AsyncStorage>
pub fn with_effective_permissions( &self, effective_permissions: Permissions ) -> Option<AsyncStorage>
Restricts an unauthenticated instance to having effective_permissions
.
Returns None
if a session has already been established.
sourcepub fn to_blocking(&self) -> Storage
pub fn to_blocking(&self) -> Storage
Converts this instance into its blocking version, which is able to be used without async.
sourcepub fn as_blocking(&self) -> &Storage
pub fn as_blocking(&self) -> &Storage
Returns a reference to this instance’s blocking version, which is able to be used without async.
Trait Implementations§
source§impl<B> AcmeCache for CustomServer<B>where
B: Backend,
impl<B> AcmeCache for CustomServer<B>where
B: Backend,
source§fn read_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
contacts: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
CustomServer<B>: 'async_trait,
fn read_account<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
contacts: &'life1 [&'life2 str]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
CustomServer<B>: 'async_trait,
contacts
, if any. This
function should return None
instead of erroring if data was not
previously written for contacts
.source§fn write_account<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
contacts: &'life1 [&'life2 str],
contents: &'life3 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
CustomServer<B>: 'async_trait,
fn write_account<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
contacts: &'life1 [&'life2 str],
contents: &'life3 [u8]
) -> Pin<Box<dyn Future<Output = Result<(), <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
CustomServer<B>: 'async_trait,
data
for contacts
. The data being written is unique for the
combined list of contacts
. Read moresource§fn write_certificate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
_domains: &'life1 [String],
_directory_url: &'life2 str,
key_pem: &'life3 str,
certificate_pem: &'life4 str
) -> Pin<Box<dyn Future<Output = Result<(), <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
CustomServer<B>: 'async_trait,
fn write_certificate<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
_domains: &'life1 [String],
_directory_url: &'life2 str,
key_pem: &'life3 str,
certificate_pem: &'life4 str
) -> Pin<Box<dyn Future<Output = Result<(), <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
CustomServer<B>: 'async_trait,
Acme
. The parameters are: Read moresource§impl<B> AsyncStorageConnection for CustomServer<B>where
B: Backend,
impl<B> AsyncStorageConnection for CustomServer<B>where
B: Backend,
§type Authenticated = CustomServer<B>
type Authenticated = CustomServer<B>
StorageConnection
type returned from authentication calls.§type Database = ServerDatabase<B>
type Database = ServerDatabase<B>
source§fn admin<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = <CustomServer<B> as AsyncStorageConnection>::Database> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
fn admin<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = <CustomServer<B> as AsyncStorageConnection>::Database> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
source§fn create_database_with_schema<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
schema: SchemaName,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
fn create_database_with_schema<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
schema: SchemaName,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
source§fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
CustomServer<B>: 'async_trait,
fn database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
CustomServer<B>: 'async_trait,
name
with schema DB
.source§fn delete_database<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
fn delete_database<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
name
. Read moresource§fn list_databases<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<Database>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
fn list_databases<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<Database>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
source§fn list_available_schemas<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaSummary>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
fn list_available_schemas<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaSummary>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
SchemaName
s registered with this storage.source§fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
fn create_user<'life0, 'life1, 'async_trait>(
&'life0 self,
username: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
source§fn delete_user<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
CustomServer<B>: 'async_trait,
fn delete_user<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
CustomServer<B>: 'async_trait,
source§fn set_user_password<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
password: SensitiveString
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
CustomServer<B>: 'async_trait,
fn set_user_password<'user, 'life0, 'async_trait, U>(
&'life0 self,
user: U,
password: SensitiveString
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'user: 'async_trait,
'life0: 'async_trait,
U: 'async_trait + Nameable<'user, u64> + Send + Sync,
CustomServer<B>: 'async_trait,
source§fn authenticate<'life0, 'async_trait>(
&'life0 self,
authentication: Authentication
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
fn authenticate<'life0, 'async_trait>(
&'life0 self,
authentication: Authentication
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
CustomServer<B>: 'async_trait,
AuthenticationToken
. If
successful, the returned instance will have the permissions from
identity
.source§fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
fn assume_identity<'life0, 'life1, 'async_trait>(
&'life0 self,
identity: IdentityReference<'life1>
) -> Pin<Box<dyn Future<Output = Result<<CustomServer<B> as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
CustomServer<B>: 'async_trait,
identity
. If successful, the returned instance will have
the merged permissions of the current authentication session and the
permissions from identity
.source§fn add_permission_group_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn add_permission_group_to_user<'user, 'group, 'life0, 'async_trait, U, G>( &'life0 self, user: U, permission_group: G ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
source§fn remove_permission_group_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
permission_group: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn remove_permission_group_from_user<'user, 'group, 'life0, 'async_trait, U, G>( &'life0 self, user: U, permission_group: G ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
source§fn add_role_to_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn add_role_to_user<'user, 'group, 'life0, 'async_trait, U, G>( &'life0 self, user: U, role: G ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
source§fn remove_role_from_user<'user, 'group, 'life0, 'async_trait, U, G>(
&'life0 self,
user: U,
role: G
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
fn remove_role_from_user<'user, 'group, 'life0, 'async_trait, U, G>( &'life0 self, user: U, role: G ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
source§fn create_database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
Self: 'async_trait,
fn create_database<'life0, 'life1, 'async_trait, DB>(
&'life0 self,
name: &'life1 str,
only_if_needed: bool
) -> Pin<Box<dyn Future<Output = Result<Self::Database, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
DB: 'async_trait + Schema,
Self: 'async_trait,
source§fn authenticate_with_token<'life0, 'life1, 'async_trait>(
&'life0 self,
id: u64,
token: &'life1 SensitiveString
) -> Pin<Box<dyn Future<Output = Result<<Self::Authenticated as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn authenticate_with_token<'life0, 'life1, 'async_trait>(
&'life0 self,
id: u64,
token: &'life1 SensitiveString
) -> Pin<Box<dyn Future<Output = Result<<Self::Authenticated as AsyncStorageConnection>::Authenticated, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
AuthenticationToken
. If
successful, the returned instance will have the permissions from
identity
.source§fn authenticate_with_password<'name, 'life0, 'async_trait, User>(
&'life0 self,
user: User,
password: SensitiveString
) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>
fn authenticate_with_password<'name, 'life0, 'async_trait, User>( &'life0 self, user: User, password: SensitiveString ) -> Pin<Box<dyn Future<Output = Result<Self::Authenticated, Error>> + Send + 'async_trait>>
User
using a password. If
successful, the returned instance will have the permissions from
identity
.source§impl<B> Clone for CustomServer<B>where
B: Backend,
impl<B> Clone for CustomServer<B>where
B: Backend,
source§fn clone(&self) -> CustomServer<B>
fn clone(&self) -> CustomServer<B>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<B> Debug for CustomServer<B>
impl<B> Debug for CustomServer<B>
source§impl<B> Deref for CustomServer<B>where
B: Backend,
impl<B> Deref for CustomServer<B>where
B: Backend,
§type Target = AsyncStorage
type Target = AsyncStorage
source§impl<'a, B> From<&'a CustomServer<B>> for Storagewhere
B: Backend,
impl<'a, B> From<&'a CustomServer<B>> for Storagewhere
B: Backend,
source§fn from(server: &'a CustomServer<B>) -> Storage
fn from(server: &'a CustomServer<B>) -> Storage
source§impl<B> From<CustomServer<B>> for Storagewhere
B: Backend,
impl<B> From<CustomServer<B>> for Storagewhere
B: Backend,
source§fn from(server: CustomServer<B>) -> Storage
fn from(server: CustomServer<B>) -> Storage
source§impl<B> HasSession for CustomServer<B>where
B: Backend,
impl<B> HasSession for CustomServer<B>where
B: Backend,
source§fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool
fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> bool
action
is permitted against resource_name
.source§fn check_permission<'a, R, P>(
&self,
resource_name: R,
action: &P
) -> Result<(), Error>
fn check_permission<'a, R, P>( &self, resource_name: R, action: &P ) -> Result<(), Error>
action
is permitted against resource_name
. If permission
is denied, returns a PermissionDenied
error.