pub struct CustomServer<B = NoBackend>where
    B: Backend,{ /* private fields */ }
Expand description

A BonsaiDb server.

Implementations§

source§

impl<B> CustomServer<B>where B: Backend,

source

pub async fn listen_for_tcp_on<S, T>( &self, addr: T, service: S ) -> impl Future<Output = Result<(), Error>>where S: TcpService, T: ToSocketAddrs + Send + Sync,

Listens for HTTP traffic on port. This port will also receive WebSocket connections if feature websockets is enabled.

source

pub async fn listen_for_secure_tcp_on<S, T>( &self, addr: T, service: S ) -> impl Future<Output = Result<(), Error>>where S: TcpService, T: ToSocketAddrs + Send + Sync,

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,

source

pub async fn listen_for_websockets_on<T>( &self, addr: T, with_tls: bool ) -> impl Future<Output = Result<(), Error>>where T: ToSocketAddrs + Send + Sync,

Listens for websocket connections on addr.

source

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.

source

pub async fn handle_websocket<S, E>( &self, connection: S, peer_address: SocketAddr ) -> impl Future<Output = ()>where S: Stream<Item = Result<Message, E>> + Sink<Message> + Send + 'static, E: Debug + Send,

Handles an established tokio-tungstenite WebSocket stream.

source§

impl<B> CustomServer<B>where B: Backend,

source

pub async fn open( configuration: ServerConfiguration<B> ) -> impl Future<Output = Result<CustomServer<B>, BackendError<<B as Backend>::Error>>>

Opens a server using directory for storage.

source

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.

source

pub fn primary_domain(&self) -> &str

Returns the primary domain configured for this server.

source

pub fn backend(&self) -> &B

Returns the Backend implementor for this server.

source

pub async fn admin(&self) -> impl Future<Output = ServerDatabase<B>>

Returns the administration database.

source

pub async fn install_self_signed_certificate( &self, overwrite: bool ) -> impl Future<Output = Result<(), Error>>

Installs an X.509 certificate used for general purpose connections.

source

pub async fn install_pem_certificate( &self, certificate_chain: &[u8], private_key: &[u8] ) -> impl Future<Output = Result<(), Error>>

Installs a certificate chain and private key used for TLS connections.

source

pub async fn install_certificate( &self, certificate_chain: &CertificateChain, private_key: &PrivateKey ) -> impl Future<Output = Result<(), Error>>

Installs a certificate chain and private key used for TLS connections.

source

pub async fn certificate_chain( &self ) -> impl Future<Output = Result<CertificateChain, Error>>

Returns the current certificate chain.

source

pub async fn listen_on( &self, config: impl Into<BonsaiListenConfig> ) -> impl Future<Output = 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.

source

pub fn connected_clients(&self) -> Vec<ConnectedClient<B>, Global>

Returns all of the currently connected clients.

source

pub fn broadcast<Api>(&self, response: &<Api as Api>::Response)where Api: Api,

Sends a custom API response to all connected clients.

source

pub async fn shutdown( &self, timeout: Option<Duration> ) -> impl Future<Output = 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.

source

pub async fn listen_for_shutdown( &self ) -> impl Future<Output = 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>§

pub async fn restore<L>( &self, location: L ) -> impl Future<Output = Result<(), Error>>where L: AnyBackupLocation + 'static,

Restores all data from a previously stored backup location.

pub async fn backup<L>( &self, location: L ) -> impl Future<Output = Result<(), Error>>where L: AnyBackupLocation + 'static,

Stores a copy of all data in this instance to location.

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.

pub fn to_blocking(&self) -> Storage

Converts this instance into its blocking version, which is able to be used without async.

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,

§

type Error = Error

The error type returned from the functions on this trait.
source§

fn read_account<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, contacts: &'life1 [&'life2 str] ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, <CustomServer<B> as AcmeCache>::Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, CustomServer<B>: 'async_trait,

Returns the previously written data for 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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, CustomServer<B>: 'async_trait,

Writes data for contacts. The data being written is unique for the combined list of contacts. Read more
source§

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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, CustomServer<B>: 'async_trait,

Writes a certificate retrieved from Acme. The parameters are: Read more
source§

impl<B> AsyncStorageConnection for CustomServer<B>where B: Backend,

§

type Authenticated = CustomServer<B>

The StorageConnection type returned from authentication calls.
§

type Database = ServerDatabase<B>

The type that represents a database for this implementation.
source§

fn admin<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = <CustomServer<B> as AsyncStorageConnection>::Database> + Send + 'async_trait, Global>>where 'life0: 'async_trait, CustomServer<B>: 'async_trait,

Returns the currently authenticated session, if any.
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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, CustomServer<B>: 'async_trait,

Creates a database named name using the SchemaName schema. Read more
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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, DB: 'async_trait + Schema, CustomServer<B>: 'async_trait,

Returns a reference to database 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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, CustomServer<B>: 'async_trait,

Deletes a database named name. Read more
source§

fn list_databases<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<Database, Global>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, CustomServer<B>: 'async_trait,

Lists the databases in this storage.
source§

fn list_available_schemas<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<SchemaSummary, Global>, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, CustomServer<B>: 'async_trait,

Lists the SchemaNames 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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, CustomServer<B>: 'async_trait,

Creates a user.
source§

fn delete_user<'user, 'life0, 'async_trait, U>( &'life0 self, user: U ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>where 'user: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Deletes a user.
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, Global>>where 'user: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Sets a user’s password.
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, Global>>where 'life0: 'async_trait, CustomServer<B>: 'async_trait,

Authenticates using an 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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, CustomServer<B>: 'async_trait,

Assumes the 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, Global>>where 'user: 'async_trait, 'group: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, G: 'async_trait + Nameable<'group, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Adds a user to a permission group.
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, Global>>where 'user: 'async_trait, 'group: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, G: 'async_trait + Nameable<'group, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Removes a user from a permission group.
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, Global>>where 'user: 'async_trait, 'group: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, G: 'async_trait + Nameable<'group, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Adds a user to a permission group.
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, Global>>where 'user: 'async_trait, 'group: 'async_trait, 'life0: 'async_trait, U: 'async_trait + Nameable<'user, u64> + Send + Sync, G: 'async_trait + Nameable<'group, u64> + Send + Sync, CustomServer<B>: 'async_trait,

Removes a user from a permission group.
§

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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, DB: 'async_trait + Schema, Self: 'async_trait,

Creates a database named name with the Schema provided. Read more
§

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, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Authenticates using an AuthenticationToken. If successful, the returned instance will have the permissions from identity.
§

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, Global>>where 'name: 'async_trait, 'life0: 'async_trait, User: 'async_trait + Nameable<'name, u64> + Send, Self: 'async_trait,

Authenticates a 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,

source§

fn clone(&self) -> CustomServer<B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<B> Debug for CustomServer<B>where B: Debug + Backend,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<B> Deref for CustomServer<B>where B: Backend,

§

type Target = AsyncStorage

The resulting type after dereferencing.
source§

fn deref(&self) -> &<CustomServer<B> as Deref>::Target

Dereferences the value.
source§

impl<'a, B> From<&'a CustomServer<B>> for Storagewhere B: Backend,

source§

fn from(server: &'a CustomServer<B>) -> Storage

Converts to this type from the input type.
source§

impl<B> From<CustomServer<B>> for Storagewhere B: Backend,

source§

fn from(server: CustomServer<B>) -> Storage

Converts to this type from the input type.
source§

impl<B> HasSession for CustomServer<B>where B: Backend,

source§

fn session(&self) -> Option<&Session>

Returns the currently authenticated session, if any.
§

fn allowed_to<'a, R, P>(&self, resource_name: R, action: &P) -> boolwhere R: AsRef<[Identifier<'a>]>, P: Action,

Checks if action is permitted against resource_name.
§

fn check_permission<'a, R, P>( &self, resource_name: R, action: &P ) -> Result<(), Error>where R: AsRef<[Identifier<'a>]>, P: Action,

Checks if action is permitted against resource_name. If permission is denied, returns a PermissionDenied error.
source§

impl<B> ResolvesServerCert for CustomServer<B>where B: Backend,

source§

fn resolve(&self, client_hello: ClientHello<'_>) -> Option<Arc<CertifiedKey>>

Choose a certificate chain and matching key given simplified ClientHello information. Read more

Auto Trait Implementations§

§

impl<B = NoBackend> !RefUnwindSafe for CustomServer<B>

§

impl<B> Send for CustomServer<B>

§

impl<B> Sync for CustomServer<B>

§

impl<B> Unpin for CustomServer<B>

§

impl<B = NoBackend> !UnwindSafe for CustomServer<B>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more