Struct ConnectionConfig

Source
pub struct ConnectionConfig { /* private fields */ }
Expand description

Tell the driver where the DBMS it be found and how to connect to it.

§From a URI

Most official drivers only accept a URI string to configure this aspect of the driver. This crate supports the same mechanism by implementing FromStr for ConnectionConfig. The string is expected to follow the form:

scheme://host[:port[?routing_context]]

Where scheme must be one of:

schemeencryptionrouting
neo4jnoneyes
neo4j+syesyes
neo4j+sccyes, but every certificate is accepted.yes
boltnoneno
bolt+syesno
bolt+sccyes, but every certificate is accepted.no

⚠️ WARNING:
The ...+ssc schemes are not secure and provided for testing purposes only.

The routing context may only be present for schemes that support routing.

use neo4j::driver::ConnectionConfig;

let conf: ConnectionConfig = "neo4j+s://localhost:7687?foo=bar".parse().unwrap();

§Programmatically

To get better type safety and avoid parsing errors at runtime, this crate also provides a builder API.

use std::collections::HashMap;

use neo4j::driver::ConnectionConfig;

let routing_context = {
    let mut map = HashMap::with_capacity(1);
    map.insert("foo".to_string(), "bar".to_string());
    map
};
let conf = ConnectionConfig::new(("localhost", 7687).into())
    .with_encryption_trust_default_cas()
    .unwrap()
    .with_routing_context(routing_context);

§TLS

The driver utilizes rustls for TLS concerns. Make sure to have a look at the requirements, for building and using it. In particular:

Implementations§

Source§

impl ConnectionConfig

Source

pub fn new(address: Address) -> Self

Create a new connection configuration with default values.

Besides the required address, no TLS encryption will be used and routing with an empty routing context is the default.

Source

pub fn with_address(self, address: Address) -> Self

Change the address the driver should connect to.

Source

pub fn with_routing(self, routing: bool) -> Self

Choose whether the driver should perform routing true or not false.

Routing is enabled by default.

Routing should be used and also works with single instance DBMS setups. Only when specifically needing to connect to a single cluster node (e.g., for maintenance), should routing be disabled.

When disabling routing (with_routing(false)), after a routing context has been configured (ConnectionConfig::with_routing_context()), the routing context will be dropped. When enabling it (with_routing(true)), an empty routing context will be configured. If you want to enable routing with a routing context, calling ConnectionConfig::with_routing_context() is sufficient.

Source

pub fn with_routing_context( self, routing_context: HashMap<String, String>, ) -> StdResult<Self, InvalidRoutingContextError<Self>>

Enable routing with a specific routing context.

The routing context is a set of key-value pairs that will be sent to the DBMS and used can be used for routing policies (e.g., choosing a region).

§Errors

An InvalidRoutingContextError is returned if the routing context contains the reserved key "address".

Source

pub fn with_encryption_trust_default_cas( self, ) -> StdResult<Self, TlsConfigError>

Enforce TLS encryption, verifying the server’s certificate against the system’s root CA certificate store.

Returns an error if the system’s root CA certificate store could not be loaded.

To use TLS, see the notes about TLS requirements.

Source

pub fn with_encryption_trust_custom_cas<P: AsRef<Path>>( self, paths: &[P], ) -> StdResult<Self, TlsConfigError>

Enforce TLS encryption, verifying the server’s certificate against root CA certificates loaded from the given file(s).

Returns an error if loading the root CA certificates failed.

To use TLS, see the notes about TLS requirements.

Source

pub fn with_encryption_trust_any_certificate(self) -> Self

Enforce TLS encryption, without verifying the server’s certificate.

⚠️ WARNING:
This is not secure and should only be used for testing purposes.

To use TLS, see the notes about TLS requirements.

Source

pub fn with_encryption_custom_tls_config(self, tls_config: ClientConfig) -> Self

Enforce TLS encryption, using a custom TLS configuration.

⚠️ WARNING:
Depending on the passed TLS configuration, this might not be secure.

§Example
use neo4j::driver::ConnectionConfig;
use rustls::client::ClientConfig;

let client_config: ClientConfig = get_custom_client_config();
let config = ConnectionConfig::new(("localhost", 7687).into())
    .with_encryption_custom_tls_config(client_config);

To use TLS, see the notes about TLS requirements.

Source

pub fn with_encryption_disabled(self) -> Self

Disable TLS encryption.

Trait Implementations§

Source§

impl Debug for ConnectionConfig

Source§

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

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

impl FromStr for ConnectionConfig

Source§

type Err = ConnectionConfigParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> StdResult<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl TryFrom<&str> for ConnectionConfig

Source§

type Error = ConnectionConfigParseError

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

fn try_from(value: &str) -> StdResult<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V