From 21c722a8b62fcb6733b997e00914383258879da6 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Sun, 7 Mar 2021 19:34:11 +0100 Subject: [PATCH 1/5] Add h1-client-rustls feature --- .github/workflows/rust.yml | 5 ++++- README.md | 26 ++++++++++++++++++++++++++ influxdb/Cargo.toml | 3 ++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7e8a9943..74619844 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,6 +48,9 @@ jobs: integration_test: name: Integration Tests (stable/ubuntu-latest) runs-on: ubuntu-latest + strategy: + matrix: + http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client, wasm-client] services: influxdb: image: influxdb:1.8 @@ -67,7 +70,7 @@ jobs: steps: - uses: actions/checkout@v1 - uses: dtolnay/rust-toolchain@stable - - run: cargo test --package influxdb --package influxdb_derive --all-features --no-fail-fast + - run: cargo test --manifest-path=./influxdb/Cargo.toml --no-default-features --features 'use-serde derive ${{ matrix.http-backend }}' --no-fail-fast coverage: name: Code Coverage (stable/ubuntu-20.04) diff --git a/README.md b/README.md index 0e3f0333..74c7de03 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Pull requests are always welcome. See [Contributing](https://github.com/Empty2k1 - `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs - `GROUP BY` support - Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml) +- Swappable HTTP backends ([see below](#Choice-of-HTTP-backend)) ## Quickstart @@ -98,6 +99,31 @@ async fn main() { For further examples, check out the Integration Tests in `tests/integration_tests.rs` in the repository. +## Choice of HTTP backend + +To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature: + +- **[hyper](https://github.com/hyperium/hyper)** (used by default) + ```toml + influxdb = { version = "0.3.0", features = ["derive"] } + ``` +- **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/) + ```toml + influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] } + ``` +- **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL) + ```toml + influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] } + ``` +- **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls) + ```toml + influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] } + ``` +- WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)** + ```toml + influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] } + ``` + ## License [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) diff --git a/influxdb/Cargo.toml b/influxdb/Cargo.toml index 637a5b7a..efc77d3e 100644 --- a/influxdb/Cargo.toml +++ b/influxdb/Cargo.toml @@ -21,7 +21,7 @@ futures = "0.3.4" lazy_static = "1.4.0" influxdb_derive = { version = "0.3.0", optional = true } regex = "1.3.5" -surf = { version = "2.1.0", default-features = false } +surf = { version = "2.2.0", default-features = false } serde = { version = "1.0.104", features = ["derive"], optional = true } serde_json = { version = "1.0.48", optional = true } thiserror = "1.0" @@ -30,6 +30,7 @@ thiserror = "1.0" use-serde = ["serde", "serde_json"] curl-client = ["surf/curl-client"] h1-client = ["surf/h1-client"] +h1-client-rustls = ["surf/h1-client-rustls"] hyper-client = ["surf/hyper-client"] wasm-client = ["surf/wasm-client"] default = ["use-serde", "hyper-client"] From b5b5a4ed990cfc93145d3e4016e5e8bd678dd371 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Mon, 8 Mar 2021 09:01:32 +0100 Subject: [PATCH 2/5] Update README part in lib.rs --- influxdb/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/influxdb/src/lib.rs b/influxdb/src/lib.rs index 350362ef..2c955fa7 100644 --- a/influxdb/src/lib.rs +++ b/influxdb/src/lib.rs @@ -13,6 +13,7 @@ //! - `#[derive(InfluxDbWriteable)]` Derive Macro for Writing / Reading into Structs //! - `GROUP BY` support //! - Tokio and async-std support (see example below) or [available backends](https://github.com/Empty2k12/influxdb-rust/blob/master/influxdb/Cargo.toml) +//! - Swappable HTTP backends ([see below](#Choice-of-HTTP-backend)) //! //! # Quickstart //! @@ -66,6 +67,31 @@ //! For further examples, check out the Integration Tests in `tests/integration_tests.rs` //! in the repository. //! +//! # Choice of HTTP backend +//! +//! To communicate with InfluxDB, you can choose the HTTP backend to be used configuring the appropriate feature: +//! +//! - **[hyper](https://github.com/hyperium/hyper)** (used by default) +//! ```toml +//! influxdb = { version = "0.3.0", features = ["derive"] } +//! ``` +//! - **[curl](https://github.com/alexcrichton/curl-rust)**, using [libcurl](https://curl.se/libcurl/) +//! ```toml +//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "curl-client"] } +//! ``` +//! - **[async-h1](https://github.com/http-rs/async-h1)** with native TLS (OpenSSL) +//! ```toml +//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] } +//! ``` +//! - **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls) +//! ```toml +//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] } +//! ``` +//! - WebAssembly's `window.fetch`, via `web-sys` and **[wasm-bindgen](https://github.com/rustwasm/wasm-bindgen)** +//! ```toml +//! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "wasm-client"] } +//! ``` +//! //! # License //! //! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) From d87e50500b2872cf82e6c5bef8db70ece85c164e Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Mon, 8 Mar 2021 09:18:30 +0100 Subject: [PATCH 3/5] Remove test of wasm-client feature (requires wasm-pack) --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 74619844..209fcaed 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -50,7 +50,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client, wasm-client] + http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client] services: influxdb: image: influxdb:1.8 From 80846d42d6e5f6eda7a61e1c3a98be385fdbd9db Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Mon, 8 Mar 2021 18:19:25 +0100 Subject: [PATCH 4/5] Replaced localhost with 127.0.0.1 in tests (workaround for Github actions) --- influxdb/tests/integration_tests.rs | 22 +++++++++++----------- influxdb/tests/utilities.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/influxdb/tests/integration_tests.rs b/influxdb/tests/integration_tests.rs index e02a81ca..d92f4050 100644 --- a/influxdb/tests/integration_tests.rs +++ b/influxdb/tests/integration_tests.rs @@ -51,7 +51,7 @@ async fn test_ping_influx_db_tokio() { async fn test_connection_error() { let test_name = "test_connection_error"; let client = - Client::new("http://localhost:10086", test_name).with_auth("nopriv_user", "password"); + Client::new("http://127.0.0.1:10086", test_name).with_auth("nopriv_user", "password"); let read_query = Query::raw_read_query("SELECT * FROM weather"); let read_result = client.query(&read_query).await; assert_result_err(&read_result); @@ -75,7 +75,7 @@ async fn test_authed_write_and_read() { run_test( || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("CREATE DATABASE {}", TEST_NAME); client .query(&Query::raw_read_query(query)) @@ -83,7 +83,7 @@ async fn test_authed_write_and_read() { .expect("could not setup db"); let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); @@ -100,7 +100,7 @@ async fn test_authed_write_and_read() { }, || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("DROP DATABASE {}", TEST_NAME); client @@ -123,7 +123,7 @@ async fn test_wrong_authed_write_and_read() { run_test( || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("CREATE DATABASE {}", TEST_NAME); client .query(&Query::raw_read_query(query)) @@ -131,7 +131,7 @@ async fn test_wrong_authed_write_and_read() { .expect("could not setup db"); let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("wrong_user", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("wrong_user", "password"); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); @@ -156,7 +156,7 @@ async fn test_wrong_authed_write_and_read() { ), } - let client = Client::new("http://localhost:9086", TEST_NAME) + let client = Client::new("http://127.0.0.1:9086", TEST_NAME) .with_auth("nopriv_user", "password"); let read_query = Query::raw_read_query("SELECT * FROM weather"); let read_result = client.query(&read_query).await; @@ -171,7 +171,7 @@ async fn test_wrong_authed_write_and_read() { }, || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("DROP DATABASE {}", TEST_NAME); client .query(&Query::raw_read_query(query)) @@ -193,13 +193,13 @@ async fn test_non_authed_write_and_read() { run_test( || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("CREATE DATABASE {}", TEST_NAME); client .query(&Query::raw_read_query(query)) .await .expect("could not setup db"); - let non_authed_client = Client::new("http://localhost:9086", TEST_NAME); + let non_authed_client = Client::new("http://127.0.0.1:9086", TEST_NAME); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); @@ -226,7 +226,7 @@ async fn test_non_authed_write_and_read() { }, || async move { let client = - Client::new("http://localhost:9086", TEST_NAME).with_auth("admin", "password"); + Client::new("http://127.0.0.1:9086", TEST_NAME).with_auth("admin", "password"); let query = format!("DROP DATABASE {}", TEST_NAME); client .query(&Query::raw_read_query(query)) diff --git a/influxdb/tests/utilities.rs b/influxdb/tests/utilities.rs index 92d4e0eb..b850d2df 100644 --- a/influxdb/tests/utilities.rs +++ b/influxdb/tests/utilities.rs @@ -18,7 +18,7 @@ pub fn create_client(db_name: T) -> Client where T: Into, { - Client::new("http://localhost:8086", db_name) + Client::new("http://127.0.0.1:8086", db_name) } #[cfg(not(tarpaulin_include))] From 00bde4e3ec2b09c337fe40f568bd146226f19870 Mon Sep 17 00:00:00 2001 From: Julien Enoch Date: Mon, 8 Mar 2021 20:02:22 +0100 Subject: [PATCH 5/5] Fix typo --- README.md | 2 +- influxdb/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74c7de03..60915c1d 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ To communicate with InfluxDB, you can choose the HTTP backend to be used configu ```toml influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] } ``` -- **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls) +- **[async-h1](https://github.com/http-rs/async-h1)** with [rustls](https://github.com/ctz/rustls) ```toml influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] } ``` diff --git a/influxdb/src/lib.rs b/influxdb/src/lib.rs index 2c955fa7..1c5b012f 100644 --- a/influxdb/src/lib.rs +++ b/influxdb/src/lib.rs @@ -83,7 +83,7 @@ //! ```toml //! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client"] } //! ``` -//! - **[async-h1](https://github.com/http-rs/async-h1)** with [rutstls](https://github.com/ctz/rustls) +//! - **[async-h1](https://github.com/http-rs/async-h1)** with [rustls](https://github.com/ctz/rustls) //! ```toml //! influxdb = { version = "0.3.0", default-features = false, features = ["derive", "use-serde", "h1-client-rustls"] } //! ```