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

drop session-prefix from session types #62

Merged
merged 2 commits into from
Oct 28, 2023
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ jobs:
features: moka-store,sqlite-store
docker: false

- store: mysql_store
features: diesel-store,diesel/mysql
docker: true

- store: postgres_store
features: diesel-store,diesel/postgres
features: diesel-postgres-store

docker: true
- store: mysql_store
features: diesel-mysql-store
docker: true

- store: diesel_store
features: diesel-store
features: diesel-sqlite-store
docker: false

steps:
Expand Down
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ tokio-rt = ["tokio/rt"]
tokio-time = ["tokio/time"]
continuously-delete-expired = ["tokio-rt", "tokio-time"]
memory-store = []

moka-store = ["moka"]

redis-store = ["fred", "rmp-serde"]

mongodb-store = ["mongodb", "bson", "rmp-serde"]

# SQLx feature flags.
sqlx-store = ["sqlx", "rmp-serde"]
sqlite-store = ["sqlx/sqlite", "sqlx-store"]
postgres-store = ["sqlx/postgres", "sqlx-store"]
mysql-store = ["sqlx/mysql", "sqlx-store"]
moka-store = ["moka"]

# Diesel feature flags.
diesel-store = ["dep:diesel", "tokio/rt", "rmp-serde"]
diesel-sqlite-store = ["diesel-store", "diesel/sqlite"]
diesel-postgres-store = ["diesel-store", "diesel/postgres"]
diesel-mysql-store = ["diesel-store", "diesel/mysql"]

Comment on lines +37 to 40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to expose this features for the users of tower-sessions as they will on it own enable the diesel features they require to construct the right pool type. That's the reason why I originally went with the __diesel_postgres feature. The other solution is to just unconditionally enable all backends as dev-dependency

[dependencies]
async-trait = "0.1.73"
Expand Down
4 changes: 2 additions & 2 deletions examples/counter-concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::StatusCode;
use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{MemoryStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{Expiry, MemoryStore, Session, SessionManagerLayer};

const COUNTER_KEY: &str = "counter";

Expand All @@ -24,7 +24,7 @@ async fn main() {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::days(1))),
.with_expiry(Expiry::InactivityDuration(Duration::days(1))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/counter-extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use http::{request::Parts, StatusCode};
use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{MemoryStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{Expiry, MemoryStore, Session, SessionManagerLayer};

const COUNTER_KEY: &str = "counter";

Expand Down Expand Up @@ -49,7 +49,7 @@ async fn main() {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::StatusCode;
use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{MemoryStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{Expiry, MemoryStore, Session, SessionManagerLayer};

const COUNTER_KEY: &str = "counter";

Expand All @@ -24,7 +24,7 @@ async fn main() {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
8 changes: 4 additions & 4 deletions examples/diesel-store-with-custom-table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tower::ServiceBuilder;
use tower_sessions::{
diesel_store::{DieselStore, DieselStoreError, SessionTable},
session_store::ExpiredDeletion,
Session, SessionExpiry, SessionManagerLayer,
Expiry, Session, SessionManagerLayer,
};

const COUNTER_KEY: &str = "counter";
Expand Down Expand Up @@ -58,8 +58,8 @@ impl SessionTable<SqliteConnection> for self::my_sessions::table {
// or create the table via normal diesel migrations on startup and leave that
// function empty
conn.batch_execute(
"CREATE TABLE `my_sessions` (`id` TEXT PRIMARY KEY NOT NULL, `expiry_date` TEXT \
NOT NULL, `data` BLOB NOT NULL);",
"CREATE TABLE `my_sessions` (`id` TEXT PRIMARY KEY NOT NULL, `expiry_date` TEXT NOT \
NULL, `data` BLOB NOT NULL);",
)?;
Ok(())
}
Expand Down Expand Up @@ -87,7 +87,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
5 changes: 2 additions & 3 deletions examples/diesel-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{
diesel_store::DieselStore, session_store::ExpiredDeletion, Session, SessionExpiry,
SessionManagerLayer,
diesel_store::DieselStore, session_store::ExpiredDeletion, Expiry, Session, SessionManagerLayer,
};

const COUNTER_KEY: &str = "counter";
Expand Down Expand Up @@ -43,7 +42,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/moka-postgres-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{
sqlx::PgPool, CachingSessionStore, MokaStore, PostgresStore, Session, SessionExpiry,
sqlx::PgPool, CachingSessionStore, Expiry, MokaStore, PostgresStore, Session,
SessionManagerLayer,
};

Expand All @@ -35,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(caching_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/mongodb-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::StatusCode;
use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{mongodb::Client, MongoDBStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{mongodb::Client, Expiry, MongoDBStore, Session, SessionManagerLayer};

const COUNTER_KEY: &str = "counter";

Expand All @@ -26,7 +26,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/mysql-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{
session_store::ExpiredDeletion, sqlx::MySqlPool, MySqlStore, Session, SessionExpiry,
session_store::ExpiredDeletion, sqlx::MySqlPool, Expiry, MySqlStore, Session,
SessionManagerLayer,
};

Expand Down Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/postgres-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{
session_store::ExpiredDeletion, sqlx::PgPool, PostgresStore, Session, SessionExpiry,
session_store::ExpiredDeletion, sqlx::PgPool, Expiry, PostgresStore, Session,
SessionManagerLayer,
};

Expand Down Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/redis-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use http::StatusCode;
use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{fred::prelude::*, RedisStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{fred::prelude::*, Expiry, RedisStore, Session, SessionManagerLayer};

const COUNTER_KEY: &str = "counter";

Expand All @@ -29,7 +29,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/sqlite-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use time::Duration;
use tower::ServiceBuilder;
use tower_sessions::{
session_store::ExpiredDeletion, sqlx::SqlitePool, Session, SessionExpiry, SessionManagerLayer,
session_store::ExpiredDeletion, sqlx::SqlitePool, Expiry, Session, SessionManagerLayer,
SqliteStore,
};

Expand Down Expand Up @@ -36,7 +36,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions examples/strongly-typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use http::{request::Parts, StatusCode};
use serde::{Deserialize, Serialize};
use time::{Duration, OffsetDateTime};
use tower::ServiceBuilder;
use tower_sessions::{MemoryStore, Session, SessionExpiry, SessionManagerLayer};
use tower_sessions::{Expiry, MemoryStore, Session, SessionManagerLayer};
use uuid::Uuid;

#[derive(Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -117,7 +117,7 @@ async fn main() {
.layer(
SessionManagerLayer::new(session_store)
.with_secure(false)
.with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
.with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
);

let app = Router::new()
Expand Down
4 changes: 2 additions & 2 deletions src/cookie_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines the configuration for the cookie belonging to the session.
use tower_cookies::{cookie::SameSite, Cookie};

use crate::{session::SessionExpiry, Session};
use crate::{session::Expiry, Session};

/// Defines the configuration for the cookie belonging to the session.
#[derive(Debug, Clone)]
Expand All @@ -26,7 +26,7 @@ pub struct CookieConfig {
pub same_site: SameSite,

/// Specifies the maximum age of the session.
pub expiry: Option<SessionExpiry>,
pub expiry: Option<Expiry>,

/// Indicates whether the cookie should only be transmitted over secure
/// (HTTPS) connections.
Expand Down
4 changes: 2 additions & 2 deletions src/diesel_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ where

async fn load(
&self,
session_id: &crate::session::SessionId,
session_id: &crate::session::Id,
) -> Result<Option<crate::Session>, Self::Error> {
let session_id = session_id.to_string();
let pool = self.pool.clone();
Expand All @@ -350,7 +350,7 @@ where
Ok(res)
}

async fn delete(&self, session_id: &crate::session::SessionId) -> Result<(), Self::Error> {
async fn delete(&self, session_id: &crate::session::Id) -> Result<(), Self::Error> {
let session_id = session_id.to_string();
let pool = self.pool.clone();
tokio::task::spawn_blocking(move || {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! use serde::{Deserialize, Serialize};
//! use time::Duration;
//! use tower::ServiceBuilder;
//! use tower_sessions::{MemoryStore, Session, SessionExpiry, SessionManagerLayer};
//! use tower_sessions::{Expiry, MemoryStore, Session, SessionManagerLayer};
//!
//! const COUNTER_KEY: &str = "counter";
//!
Expand All @@ -56,7 +56,7 @@
//! .layer(
//! SessionManagerLayer::new(session_store)
//! .with_secure(false)
//! .with_expiry(SessionExpiry::InactivityDuration(Duration::seconds(10))),
//! .with_expiry(Expiry::InactivityDuration(Duration::seconds(10))),
//! );
//!
//! let app = Router::new()
Expand Down Expand Up @@ -505,7 +505,7 @@ pub use self::sqlx_store::SqlxStoreError;
pub use self::{
cookie_config::CookieConfig,
service::{SessionManager, SessionManagerLayer},
session::{Session, SessionExpiry},
session::{Expiry, Session},
session_store::{CachingSessionStore, ExpiredDeletion, SessionStore},
};

Expand Down
8 changes: 4 additions & 4 deletions src/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_trait::async_trait;
use parking_lot::Mutex;

use crate::{
session::{Session, SessionId},
session::{Id, Session},
SessionStore,
};

Expand All @@ -19,7 +19,7 @@ use crate::{
/// MemoryStore::default();
/// ```
#[derive(Clone, Debug, Default)]
pub struct MemoryStore(Arc<Mutex<HashMap<SessionId, Session>>>);
pub struct MemoryStore(Arc<Mutex<HashMap<Id, Session>>>);

#[async_trait]
impl SessionStore for MemoryStore {
Expand All @@ -30,11 +30,11 @@ impl SessionStore for MemoryStore {
Ok(())
}

async fn load(&self, session_id: &SessionId) -> Result<Option<Session>, Self::Error> {
async fn load(&self, session_id: &Id) -> Result<Option<Session>, Self::Error> {
Ok(self.0.lock().get(session_id).cloned())
}

async fn delete(&self, session_id: &SessionId) -> Result<(), Self::Error> {
async fn delete(&self, session_id: &Id) -> Result<(), Self::Error> {
self.0.lock().remove(session_id);
Ok(())
}
Expand Down
Loading
Loading