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:
scheme | encryption | routing |
---|---|---|
neo4j | none | yes |
neo4j+s | yes | yes |
neo4j+scc | yes, but every certificate is accepted. | yes |
bolt | none | no |
bolt+s | yes | no |
bolt+scc | yes, 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:
- Consider the platform support
- Make sure a crypto provider is installed (e.g., by calling
rustls::crypto::CryptoProvider::install_default()
when starting the process).
Implementations§
Source§impl ConnectionConfig
impl ConnectionConfig
Sourcepub fn new(address: Address) -> Self
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.
Sourcepub fn with_address(self, address: Address) -> Self
pub fn with_address(self, address: Address) -> Self
Change the address the driver should connect to.
Sourcepub fn with_routing(self, routing: bool) -> Self
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.
Sourcepub fn with_routing_context(
self,
routing_context: HashMap<String, String>,
) -> StdResult<Self, InvalidRoutingContextError<Self>>
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"
.
Sourcepub fn with_encryption_trust_default_cas(
self,
) -> StdResult<Self, TlsConfigError>
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.
Sourcepub fn with_encryption_trust_custom_cas<P: AsRef<Path>>(
self,
paths: &[P],
) -> StdResult<Self, TlsConfigError>
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.
Sourcepub fn with_encryption_trust_any_certificate(self) -> Self
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.
Sourcepub fn with_encryption_custom_tls_config(self, tls_config: ClientConfig) -> Self
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.
Sourcepub fn with_encryption_disabled(self) -> Self
pub fn with_encryption_disabled(self) -> Self
Disable TLS encryption.
Trait Implementations§
Source§impl Debug for ConnectionConfig
impl Debug for ConnectionConfig
Source§impl FromStr for ConnectionConfig
impl FromStr for ConnectionConfig
Auto Trait Implementations§
impl Freeze for ConnectionConfig
impl !RefUnwindSafe for ConnectionConfig
impl Send for ConnectionConfig
impl Sync for ConnectionConfig
impl Unpin for ConnectionConfig
impl !UnwindSafe for ConnectionConfig
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
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>
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>
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