Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify features, strip dependencies and remove native-tls #184

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gremlin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gremlin-client = { path = "../gremlin-client", version = "0.8.0", features = ["async-std-runtime"] }
gremlin-client = { path = "../gremlin-client", version = "0.8.0", features = ["async"] }
rustyline = "6.2.0"
smol = "0.4.3"
shellwords = "1.1.0"
Expand Down
5 changes: 2 additions & 3 deletions gremlin-cli/src/actions/fallback.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::actions::Action;
use crate::actions::{display_results, Action};
use crate::{command::Command, context::GremlinContext};
use async_std::prelude::*;

use futures::future::BoxFuture;
use futures::FutureExt;
use gremlin_client::{
aio::{GResultSet, GremlinClient},
GValue,
};

use crate::actions::display_results;
pub struct FallbackAction;

impl Action for FallbackAction {
Expand Down
68 changes: 24 additions & 44 deletions gremlin-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ keywords = ["database", "graphs","tinkerpop"]
categories = ["database"]
readme = "README.md"



[features]

default = []



async_gremlin = ["futures","mobc","async-tungstenite","async-trait","url","pin-project-lite"]

async_std = ["async-std-runtime"]
tokio-runtime = ["async_gremlin","tokio","mobc/tokio","async-tungstenite/tokio-runtime","async-tungstenite/tokio-native-tls","tokio-native-tls","tokio-stream"]
async-std-runtime = ["async_gremlin","async-std","async-tungstenite/async-std-runtime","async-tungstenite/async-tls","mobc/async-std","async-tls","rustls","webpki"]

default = ["async"]
derive = ["gremlin-derive"]
async = ["async-trait", "async-tungstenite", "async-tungstenite/tokio-runtime", "async-tungstenite/tokio-rustls-webpki-roots", "futures", "mobc", "mobc/tokio", "pin-project-lite", "tokio", "tokio-stream", "url", "tokio-rustls"]
sync = []

[badges]
travis-ci = { repository = "wolf4ood/gremlin-rs" }
Expand All @@ -34,50 +24,40 @@ is-it-maintained-open-issues = { repository = "wolf4ood/gremlin-rs" }
maintenance = {status = "actively-developed"}

[dependencies]
async-std = { version = "1.4.0", features = ["unstable","attributes"], optional = true }
async-tls = { version = "0.11", optional = true }
async-trait = { version = "0.1.10", optional = true }
async-tungstenite = { version = "0.18", default-features = false, optional = true }
base64 = "0.13.1"
#Avoids bringing in time crate (https://github.com/time-rs/time/issues/293)
chrono = { version = "0.4", default-features = false }
futures = { version = "0.3.1", optional = true }
gremlin-derive = { path="../gremlin-derive", version="0.1", optional = true }
lazy_static = "1.3.0"
mobc = { version = "0.7", default-features = false, features = ["unstable"], optional = true }
pin-project-lite = { version = "0.2", optional = true }
r2d2 = "0.8.3"
serde = "1.0"
serde_json = "1.0"
serde_derive="1.0"
r2d2 = "0.8.3"
#Avoids bringing in time crate (https://github.com/time-rs/time/issues/293)
chrono = { version = "0.4", default-features = false}
lazy_static = "1.3.0"
base64 = "0.13.1"
native-tls = "0.2.3"
tungstenite = { version = "0.18.0", features = ["native-tls"] }
async-tungstenite = { version = "0.18", optional = true, default-features=false}
async-std = { version = "1.4.0", optional = true, features = ["unstable","attributes"] }
async-trait = { version = "0.1.10", optional = true }
async-tls = { version = "0.11", optional = true }
thiserror = "1.0.20"
tokio = { version = "1", features = ["full"], optional = true }
tokio-native-tls = { version = "0.3.0", optional = true }
tokio-rustls = { version = "0.23.4", features = ["dangerous_configuration"], optional = true }
tokio-stream = { version = "0.1.2", optional = true }
gremlin-derive = { path="../gremlin-derive", version="0.1", optional=true }
rustls = { version="0.19", features = ["dangerous_configuration"], optional = true}
tungstenite = { version = "0.18.0", features = ["rustls-tls-webpki-roots"] }
url = {version = "2.1.0", optional = true }
uuid = { version = "1.1.2", features = ["serde", "v4"] }
webpki = { version = "0.21.3", optional = true }
thiserror = "1.0.20"



mobc = {version = "0.7", optional = true, default-features=false, features = ["unstable"] }
url = {version = "2.1.0", optional = true}
futures = { version = "0.3.1", optional = true}
pin-project-lite = { version = "0.2", optional = true}
tokio = { version = "1", optional=true, features = ["full"] }


[dependencies.uuid]
features = ["serde", "v4"]
version = "1.1.2"




[[example]]
name = "traversal_async"
required-features = ["async_gremlin"]
required-features = ["async"]

[[example]]
name = "vertex_async"
required-features = ["async_gremlin"]
required-features = ["async"]

[[example]]
name = "derive"
Expand Down
3 changes: 1 addition & 2 deletions gremlin-client/examples/traversal_async.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use gremlin_client::{aio::GremlinClient, process::traversal::traversal};

#[cfg_attr(feature = "async-std-runtime", async_std::main)]
#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async", tokio::main)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = GremlinClient::connect("localhost").await?;

Expand Down
8 changes: 2 additions & 6 deletions gremlin-client/examples/vertex_async.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use gremlin_client::{aio::GremlinClient, Vertex};

#[cfg(feature = "async-std-runtime")]
use async_std::prelude::*;

#[cfg(feature = "tokio-runtime")]
#[cfg(feature = "async")]
use tokio_stream::StreamExt;

#[cfg_attr(feature = "async-std-runtime", async_std::main)]
#[cfg_attr(feature = "tokio-runtime", tokio::main)]
#[cfg_attr(feature = "async", tokio::main)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = GremlinClient::connect("localhost").await?;

Expand Down
109 changes: 16 additions & 93 deletions gremlin-client/src/aio/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,24 @@ use crate::connection::ConnectionOptions;

use crate::message::Response;

#[cfg(feature = "async-std-runtime")]
mod async_std_use {
pub use async_std::net::TcpStream;
pub use async_std::task;
pub use async_tls::client::TlsStream;
}

#[cfg(feature = "async-std-runtime")]
use async_std_use::*;

#[cfg(feature = "tokio-runtime")]
mod tokio_use {
pub use tokio::net::TcpStream;
pub use tokio::task;
pub use tokio_native_tls::TlsStream;
}

#[cfg(feature = "tokio-runtime")]
use tokio_use::*;

#[cfg(feature = "async-std-runtime")]
use async_tungstenite::async_std::connect_async_with_tls_connector;

#[cfg(feature = "tokio-runtime")]
use async_tungstenite::tokio::{connect_async_with_tls_connector, TokioAdapter};

use async_tungstenite::tungstenite::protocol::Message;
use async_tungstenite::WebSocketStream;
use async_tungstenite::{self, stream};
use async_tungstenite::tokio::connect_async;
use async_tungstenite::{
self, stream, tokio::TokioAdapter, tungstenite::protocol::Message, WebSocketStream,
};
use futures::{
channel::mpsc::{channel, Receiver, Sender},
lock::Mutex,
stream::{SplitSink, SplitStream},
SinkExt, StreamExt,
};

use futures::channel::mpsc::{channel, Receiver, Sender};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::{net::TcpStream, task};
use tokio_rustls::client::TlsStream;
use url;
use uuid::Uuid;

#[cfg(feature = "async-std-runtime")]
type WSStream = WebSocketStream<stream::Stream<TcpStream, TlsStream<TcpStream>>>;
use std::collections::HashMap;
use std::sync::Arc;

#[cfg(feature = "tokio-runtime")]
type WSStream =
WebSocketStream<stream::Stream<TokioAdapter<TcpStream>, TokioAdapter<TlsStream<TcpStream>>>>;

Expand All @@ -71,57 +44,6 @@ impl std::fmt::Debug for Conn {
}
}

#[cfg(feature = "async-std-runtime")]
mod tls {

use crate::connection::ConnectionOptions;
pub struct NoCertificateVerification {}

impl rustls::ServerCertVerifier for NoCertificateVerification {
fn verify_server_cert(
&self,
_roots: &rustls::RootCertStore,
_presented_certs: &[rustls::Certificate],
_dns_name: webpki::DNSNameRef<'_>,
_ocsp: &[u8],
) -> Result<rustls::ServerCertVerified, rustls::TLSError> {
Ok(rustls::ServerCertVerified::assertion())
}
}

pub fn connector(opts: &ConnectionOptions) -> Option<async_tls::TlsConnector> {
use rustls::ClientConfig;
use std::sync::Arc;
if opts
.tls_options
.as_ref()
.map(|tls| tls.accept_invalid_certs)
.unwrap_or(false)
{
let mut config = ClientConfig::new();
config
.dangerous()
.set_certificate_verifier(Arc::new(NoCertificateVerification {}));

Some(async_tls::TlsConnector::from(Arc::new(config)))
} else {
Some(async_tls::TlsConnector::new())
}
}
}

#[cfg(feature = "tokio-runtime")]
mod tls {

use crate::connection::ConnectionOptions;
use tokio_native_tls::TlsConnector;

pub fn connector(opts: &ConnectionOptions) -> Option<TlsConnector> {
opts.tls_options
.as_ref()
.and_then(|tls| tls.tls_connector().map(TlsConnector::from).ok())
}
}
impl Conn {
pub async fn connect<T>(options: T) -> GremlinResult<Conn>
where
Expand All @@ -130,10 +52,12 @@ impl Conn {
let opts = options.into();
let url = url::Url::parse(&opts.websocket_url()).expect("failed to pars url");

#[cfg(feature = "async-std-runtime")]
let (client, _) = { connect_async_with_tls_connector(url, tls::connector(&opts)).await? };
#[cfg(feature = "tokio-runtime")]
let (client, _) = { connect_async_with_tls_connector(url, tls::connector(&opts)).await? };
// let connector = opts
// .tls_options
// .as_ref()
// .and_then(|tls| tls.tls_connector().map(TlsConnector::from).ok());

let (client, _) = { connect_async(url).await? }; // connect_async_with_tls_connector(url, connector).await? };

let (sink, stream) = client.split();
let (sender, receiver) = channel(20);
Expand Down Expand Up @@ -285,8 +209,7 @@ fn receiver_loop(
mod tests {
use super::*;

#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async", tokio::test)]
async fn it_should_connect() {
Conn::connect(("localhost", 8182)).await.unwrap();
}
Expand Down
20 changes: 3 additions & 17 deletions gremlin-client/src/aio/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,10 @@ mod tests {
use mobc::Pool;
use std::time::Duration;

#[cfg(feature = "async-std-runtime")]
mod async_std_use {
pub use async_std::task;
}

#[cfg(feature = "async-std-runtime")]
use async_std_use::*;

#[cfg(feature = "tokio-runtime")]
mod tokio_use {
pub use tokio::task;
}

#[cfg(feature = "tokio-runtime")]
use tokio_use::*;
#[cfg(feature = "async")]
use tokio::task;

#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async", tokio::test)]
#[allow(unused_must_use)]
async fn it_should_create_a_connection_pool() {
let manager = GremlinConnectionManager::new(ConnectionOptions::default());
Expand Down
37 changes: 15 additions & 22 deletions gremlin-client/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::net::TcpStream;

use crate::{GraphSON, GremlinError, GremlinResult};
use native_tls::TlsConnector;

use tungstenite::{
client::{uri_mode, IntoClientRequest},
client_tls_with_config,
client_tls,
stream::{MaybeTlsStream, Mode, NoDelay},
Connector, Message, WebSocket,
Message, WebSocket,
};

struct ConnectionStream(WebSocket<MaybeTlsStream<TcpStream>>);
Expand All @@ -19,14 +19,14 @@ impl std::fmt::Debug for ConnectionStream {

impl ConnectionStream {
fn connect(options: ConnectionOptions) -> GremlinResult<Self> {
let connector = match options.tls_options.as_ref() {
Some(option) => Some(Connector::NativeTls(
option
.tls_connector()
.map_err(|e| GremlinError::Generic(e.to_string()))?,
)),
_ => None,
};
// let connector = match options.tls_options.as_ref() {
// Some(option) => Some(Connector::Rustls(
// option
// .tls_connector()
// .map_err(|e| GremlinError::Generic(e.to_string()))?,
// )),
// _ => None,
// };

let request = options
.websocket_url()
Expand All @@ -47,9 +47,10 @@ impl ConnectionStream {
NoDelay::set_nodelay(&mut stream, true)
.map_err(|e| GremlinError::Generic(e.to_string()))?;

let (client, _response) =
client_tls_with_config(options.websocket_url(), stream, None, connector)
.map_err(|e| GremlinError::Generic(e.to_string()))?;
let (client, _response) = client_tls(options.websocket_url(), stream)
.map_err(|e| GremlinError::Generic(e.to_string()))?;
// client_tls_with_config(options.websocket_url(), stream, None, connector)
// .map_err(|e| GremlinError::Generic(e.to_string()))?;

Ok(ConnectionStream(client))
}
Expand Down Expand Up @@ -230,14 +231,6 @@ impl Connection {
}
}

impl TlsOptions {
pub(crate) fn tls_connector(&self) -> native_tls::Result<TlsConnector> {
TlsConnector::builder()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading