From 62582ed33c03af77dd27dcf0eb29abc5ad11e23d Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Sun, 1 May 2022 17:03:05 +0200 Subject: [PATCH 1/8] Adding lauch config file to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b75a144..beb0ad6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ target/ tmp/ Cargo.lock .DS_Store +.vscode/launch.json From 46b5c6f2deaace9cfddf87e7bcd1321a7ac21559 Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Mon, 2 May 2022 22:41:23 +0200 Subject: [PATCH 2/8] load database and collection from env --- .gitignore | 1 + tests/test.rs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index beb0ad6..30b03f4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ tmp/ Cargo.lock .DS_Store .vscode/launch.json +.cargo/config.toml diff --git a/tests/test.rs b/tests/test.rs index 16379c3..51cbe8c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -10,6 +10,8 @@ mod tests { lazy_static! { static ref HOST: String = env::var("HOST").unwrap_or_else(|_| "127.0.0.1".to_string()); static ref PORT: String = env::var("PORT").unwrap_or_else(|_| "27017".to_string()); + static ref DATABASE: String = env::var("DATABASE").unwrap_or_else(|_| "db_name".to_string()); + static ref COLLECTION: String = env::var("COLLECTION").unwrap_or_else(|_| "collection".to_string()); static ref CONNECTION_STRING: String = format!("mongodb://{}:{}/", HOST.as_str(), PORT.as_str()); } @@ -26,8 +28,8 @@ mod tests { Ok(c) => c, Err(e) => panic!("Client Creation Failed: {}", e), }; - - let store = MongodbSessionStore::from_client(client, "db_name", "collection"); + + let store = MongodbSessionStore::from_client(client, &DATABASE, &COLLECTION); let mut rng = rand::thread_rng(); let n2: u16 = rng.gen(); let key = format!("key-{}", n2); From 503d3456cfa873744d2c4cc48c86de2617148180 Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Tue, 3 May 2022 22:00:54 +0200 Subject: [PATCH 3/8] eliminate warning in lib.rs function initialize --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 37ec7e7..71cae92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ impl MongodbSessionStore { /// # Ok(()) }) } /// ``` pub async fn initialize(&self) -> Result { - &self.index_on_expiry_at().await?; + let _ = &self.index_on_expiry_at().await?; Ok(()) } From 29fa2e0b5b069efd91cdec53a3fd1a8cd6288c32 Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Tue, 3 May 2022 22:06:51 +0200 Subject: [PATCH 4/8] updating dev-dependencies --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b0e31d1..7d136bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ mongodb = { version = "1.1.1", default-features = false, features = ["async-std- async-session = "2.0.0" [dev-dependencies] -async-std = { version = "1.8.0", features = ["attributes"] } -rand = {version = "0.7.3"} -lazy_static = "1" -tide = "0.15" +async-std = { version = "1.11.0", features = ["attributes"] } +rand = {version = "0.8.5"} +lazy_static = "1.4.0" +tide = "0.16" From 695e69bfdb9cb56cfee4219243de9db0a3355a1b Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Wed, 4 May 2022 00:52:03 +0200 Subject: [PATCH 5/8] updating test.rs for missing parameters --- tests/test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test.rs b/tests/test.rs index 51cbe8c..3928257 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -19,7 +19,7 @@ mod tests { #[test] fn test_from_client() -> async_session::Result { async_std::task::block_on(async { - let client_options = match ClientOptions::parse(&CONNECTION_STRING).await { + let client_options = match ClientOptions::parse(&*CONNECTION_STRING).await { Ok(c) => c, Err(e) => panic!("Client Options Failed: {}", e), }; @@ -49,7 +49,7 @@ mod tests { fn test_new() -> async_session::Result { async_std::task::block_on(async { let store = - MongodbSessionStore::new(&CONNECTION_STRING, "db_name", "collection").await?; + MongodbSessionStore::new(&CONNECTION_STRING, &DATABASE, &COLLECTION).await?; let mut rng = rand::thread_rng(); let n2: u16 = rng.gen(); @@ -70,7 +70,7 @@ mod tests { fn test_with_expire() -> async_session::Result { async_std::task::block_on(async { let store = - MongodbSessionStore::new(&CONNECTION_STRING, "db_name", "collection").await?; + MongodbSessionStore::new(&CONNECTION_STRING, &DATABASE, &COLLECTION).await?; store.initialize().await?; @@ -96,7 +96,7 @@ mod tests { use std::time::Duration; async_std::task::block_on(async { let store = - MongodbSessionStore::new(&CONNECTION_STRING, "db_name", "collection").await?; + MongodbSessionStore::new(&CONNECTION_STRING, &DATABASE, &COLLECTION).await?; store.initialize().await?; From 3bc316406d58ee25e1645b1e0c57e250b87f5981 Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Wed, 4 May 2022 22:16:01 +0200 Subject: [PATCH 6/8] updating mongodb --- Cargo.toml | 2 +- src/lib.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7d136bb..f6cc528 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ authors = [ [features] [dependencies] -mongodb = { version = "1.1.1", default-features = false, features = ["async-std-runtime"] } +mongodb = { version = "2.2.1", default-features = false, features = ["async-std-runtime", "bson-chrono-0_4"] } async-session = "2.0.0" [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 71cae92..505f01e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,8 +17,8 @@ use async_session::chrono::{Duration, Utc}; use async_session::{async_trait, Result, Session, SessionStore}; -use mongodb::bson; -use mongodb::bson::{doc, Bson}; +use mongodb::{bson, Collection}; +use mongodb::bson::{doc, Bson, Document}; use mongodb::options::{ReplaceOptions, SelectionCriteria}; use mongodb::Client; @@ -162,7 +162,7 @@ impl SessionStore for MongodbSessionStore { async fn load_session(&self, cookie_value: String) -> Result> { let id = Session::id_from_cookie_value(&cookie_value)?; - let coll = self.client.database(&self.db).collection(&self.coll_name); + let coll:Collection = self.client.database(&self.db).collection(&self.coll_name); let filter = doc! { "session_id": id }; match coll.find_one(filter, None).await? { None => Ok(None), @@ -175,7 +175,7 @@ impl SessionStore for MongodbSessionStore { // https://docs.mongodb.com/manual/core/index-ttl/#timing-of-the-delete-operation // This prevents those documents being returned if let Some(expiry_at) = doc.get("expireAt").and_then(Bson::as_datetime) { - if expiry_at < &Utc::now() { + if expiry_at < &Utc::now().into() { return Ok(None); } } @@ -185,14 +185,14 @@ impl SessionStore for MongodbSessionStore { } async fn destroy_session(&self, session: Session) -> Result { - let coll = self.client.database(&self.db).collection(&self.coll_name); + let coll:Collection = self.client.database(&self.db).collection(&self.coll_name); coll.delete_one(doc! { "session_id": session.id() }, None) .await?; Ok(()) } async fn clear_store(&self) -> Result { - let coll = self.client.database(&self.db).collection(&self.coll_name); + let coll:Collection = self.client.database(&self.db).collection(&self.coll_name); coll.drop(None).await?; self.initialize().await?; Ok(()) From d54b507c1f58fd631a38cbb491fb7b101d73e98a Mon Sep 17 00:00:00 2001 From: "PAPKE2019\\Tilo" Date: Wed, 4 May 2022 22:27:40 +0200 Subject: [PATCH 7/8] updating async-session --- Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f6cc528..1163409 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,8 @@ authors = [ [dependencies] mongodb = { version = "2.2.1", default-features = false, features = ["async-std-runtime", "bson-chrono-0_4"] } -async-session = "2.0.0" +# can not go higher due to dev-dependencie "tide" which requires "async-session" in version 2.0.1 +async-session = "2.0.1" [dev-dependencies] async-std = { version = "1.11.0", features = ["attributes"] } From 4876e784b61aa4b3aab151b52641ccd43b433b8f Mon Sep 17 00:00:00 2001 From: Anton Whalley Date: Sun, 21 Aug 2022 09:31:41 +0100 Subject: [PATCH 8/8] release: bump version number Signed-off-by: Anton Whalley --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1163409..420242b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-mongodb-session" -version = "2.0.0" +version = "2.1.0" license = "MIT OR Apache-2.0" repository = "https://github.com/yoshuawuyts/async-mongodb-session" documentation = "https://docs.rs/async-mongodb-session"