Skip to content

Commit

Permalink
relocate previously bundled stores (#145)
Browse files Browse the repository at this point in the history
This moves all previously bundled stores, with the exception of the
memory store, out of the repo.

Closes #102
  • Loading branch information
maxcountryman committed Jan 22, 2024
1 parent 25a08c5 commit 6359e76
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 1,647 deletions.
58 changes: 3 additions & 55 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,6 @@ jobs:
- name: Run doc tests
run: |
cargo test --workspace --all-features --doc
#- name: Generate code coverage
# run: |
# output_dir="./coverage/doc"
# cargo tarpaulin -olcov --doc --output-dir $output_dir
# mkdir -p coverage-artifacts/doc
# mv $output_dir coverage-artifacts/doc/
#- uses: actions/upload-artifact@v4
# with:
# name: coverage-artifacts-doc
# path: coverage-artifacts/doc
test-integration:
needs: check
Expand All @@ -73,45 +63,7 @@ jobs:
strategy:
matrix:
include:
- store: redis_store
features: redis-store
docker: true

- store: mongodb_store
features: mongodb-store
docker: true

- store: postgres_store
features: postgres-store
docker: true

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

- store: sqlite_store
features: sqlite-store
docker: false

- store: moka_store
features: moka-store
docker: false

- store: caching_store
features: moka-store,sqlite-store
docker: false

#- store: postgres_store
# features: diesel-postgres-store

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

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

steps:
- uses: actions/checkout@v4
Expand All @@ -120,17 +72,13 @@ jobs:
cargo install cargo-tarpaulin
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@nextest
- name: Start session store
if: matrix.docker
run: |
docker compose -f tests/docker-compose.yml up ${{ matrix.store }} -d
- name: Run integration tests
run: |
cargo nextest run ${{ matrix.store }}_test --test integration-tests --features ${{ matrix.features }}
cargo nextest run ${{ matrix.store }}_test --test integration-tests
- name: Generate code coverage
run: |
output_dir="./coverage/${{ matrix.store }}_${{ matrix.features }}"
cargo tarpaulin -olcov --test integration-tests --features ${{ matrix.features }} --output-dir $output_dir
cargo tarpaulin -olcov --test integration-tests --output-dir $output_dir
mkdir -p coverage-artifacts/integration
mv $output_dir coverage-artifacts/integration/
- uses: actions/upload-artifact@v4
Expand Down
74 changes: 13 additions & 61 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
[workspace]
members = [
".",
"memory-store",
"moka-store",
"mongodb-store",
"redis-store",
"sqlx-store",
"tower-sessions-core",
]
members = [".", "memory-store", "tower-sessions-core"]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -42,46 +34,26 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["axum-core", "memory-store"]

# Runtime features.
axum-core = ["tower-sessions-core/axum-core"]
deletion-task = ["tower-sessions-core/deletion-task"]

# Session stores.
memory-store = ["tower-sessions-memory-store"]
moka-store = ["tower-sessions-moka-store"]
redis-store = ["tower-sessions-redis-store"]
mongodb-store = ["tower-sessions-mongodb-store"]
sqlx-store = []
sqlite-store = ["sqlx-store", "tower-sessions-sqlx-store/sqlite"]
postgres-store = ["sqlx-store", "tower-sessions-sqlx-store/postgres"]
mysql-store = ["sqlx-store", "tower-sessions-sqlx-store/mysql"]

[workspace.dependencies]
tower-sessions = { version = "=0.9.1", path = ".", default-features = false }

tower-sessions-core = { version = "=0.9.1", path = "tower-sessions-core", default-features = false }
tower-sessions-memory-store = { version = "=0.9.1", path = "memory-store" }
tower-sessions-moka-store = { version = "=0.9.1", path = "moka-store" }
tower-sessions-redis-store = { version = "=0.9.1", path = "redis-store" }
tower-sessions-mongodb-store = { version = "=0.9.1", path = "mongodb-store" }
tower-sessions-sqlx-store = { version = "=0.9.1", path = "sqlx-store" }

async-trait = "0.1.74"
parking_lot = { version = "0.12.1", features = ["serde"] }
rmp-serde = { version = "1.1.2" }
serde = "1.0.192"
time = "0.3.30"
thiserror = "1.0.50"
time = "0.3.30"
tokio = { version = "1.32.0", default-features = false, features = ["sync"] }

[dependencies]
tower-sessions-core = { workspace = true, features = ["axum-core"] }
tower-sessions-memory-store = { workspace = true, optional = true }
tower-sessions-moka-store = { workspace = true, optional = true }
tower-sessions-redis-store = { workspace = true, optional = true }
tower-sessions-mongodb-store = { workspace = true, optional = true }
tower-sessions-sqlx-store = { workspace = true, optional = true }

[dev-dependencies]
async-trait = "0.1.74"
Expand All @@ -91,6 +63,7 @@ futures = { version = "0.3.28", default-features = false, features = [
"async-await",
] }
http = "1.0"
http-body-util = "0.1"
hyper = "1.0"
reqwest = { version = "0.11.22", default-features = false, features = [
"rustls",
Expand All @@ -101,7 +74,15 @@ tokio = { version = "1.32.0", features = ["full"] }
tokio-test = "0.4.3"
tower = "0.4.13"
tower-cookies = "0.10.0"
http-body-util = "0.1"
tower-sessions-core = { workspace = true, features = ["deletion-task"] }
tower-sessions-moka-store = "0.9.1"
tower-sessions-mongodb-store = "0.9.1"
tower-sessions-redis-store = "0.9.1"
tower-sessions-sqlx-store = { version = "0.9.2", features = [
"sqlite",
"postgres",
"mysql",
] }

[[example]]
name = "counter"
Expand All @@ -111,35 +92,6 @@ required-features = ["axum-core", "memory-store"]
name = "counter-extractor"
required-features = ["axum-core", "memory-store"]

[[example]]
name = "redis-store"
required-features = ["axum-core", "redis-store"]

[[example]]
name = "mongodb-store"
required-features = ["axum-core", "mongodb-store", "deletion-task"]

[[example]]
name = "sqlite-store"
required-features = ["axum-core", "sqlite-store", "deletion-task"]

[[example]]
name = "postgres-store"
required-features = ["axum-core", "postgres-store", "deletion-task"]

[[example]]
name = "moka-postgres-store"
required-features = [
"axum-core",
"postgres-store",
"moka-store",
"deletion-task",
]

[[example]]
name = "mysql-store"
required-features = ["axum-core", "mysql-store", "deletion-task"]

[[example]]
name = "strongly-typed"
required-features = ["axum-core", "memory-store"]
required-features = ["axum-core"]
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ It offers:
- **An `axum` Extractor for `Session`:** Applications built with `axum`
can use `Session` as an extractor directly in their handlers. This makes
using sessions as easy as including `Session` in your handler.
- **Common Backends Out-of-the-Box:** `RedisStore`, SQLx
(`SqliteStore`, `PostgresStore`, `MySqlStore`), and `MongoDBStore` stores
are available via their respective feature flags.
- **Simple Key-Value Interface:** Sessions offer a key-value interface that
supports native Rust types. So long as these types are `Serialize` and can
be converted to JSON, it's straightforward to insert, get, and remove any
Expand All @@ -50,6 +47,27 @@ It offers:

This crate's session implementation is inspired by the [Django sessions middleware](https://docs.djangoproject.com/en/4.2/topics/http/sessions) and it provides a transliteration of those semantics.

### Session stores

Sessions are managed by user-provided types that implement `SessionStore`.
What this means is that applications can and should implement session stores
to fit their specific needs.

That said, a number of session store implmentations already exist and may be
useful starting points.

| Crate | Persistent | Description |
| ---------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------ |
| [`tower-sessions-dynamodb-store`](https://github.com/necrobious/tower-sessions-dynamodb-store) | Yes | DynamoDB session store |
| [`tower-sessions-firestore-store`](https://github.com/AtTheTavern/tower-sessions-firestore-store) | Yes | Firestore session store |
| [`tower-sessions-mongodb-store`](https://github.com/maxcountryman/tower-sessions-stores/tree/main/mongodb-store) | Yes | MongoDB session store |
| [`tower-sessions-moka-store`](https://github.com/maxcountryman/tower-sessions-stores/tree/main/moka-store) | No | Moka session store |
| [`tower-sessions-redis-store`](https://github.com/maxcountryman/tower-sessions-stores/tree/main/redis-store) | Yes | Redis via `fred` session store |
| [`tower-sessions-sqlx-store`](https://github.com/maxcountryman/tower-sessions-stores/tree/main/sqlx-store) | Yes | SQLite, Postgres, and MySQL session stores |
| [`tower-sessions-surrealdb-store`](https://github.com/rynoV/tower-sessions-surrealdb-store) | Yes | SurrealDB session store |

Have a store to add? Please open a PR adding it.

### User session management

To facilitate authentication and authorization, we've built [`axum-login`](https://github.com/maxcountryman/axum-login) on top of this crate. Please check it out if you're looking for a generalized auth solution.
Expand Down Expand Up @@ -108,16 +126,6 @@ You can find this [example][counter-example] as well as other example projects i
> [!NOTE]
> See the [crate documentation][docs] for more usage information.
### Additional session stores

| Crate | Persistent | Description |
| ------------------------------------------------------------------------------------------------- | ---------- | ----------------------- |
| [`tower-sessions-surrealdb-store`](https://github.com/rynoV/tower-sessions-surrealdb-store) | Yes | SurrealDB session store |
| [`tower-sessions-dynamodb-store`](https://github.com/necrobious/tower-sessions-dynamodb-store) | Yes | DynamoDB session store |
| [`tower-sessions-firestore-store`](https://github.com/AtTheTavern/tower-sessions-firestore-store) | Yes | Firestore session store |

Have a store to add? Please open a PR.

## 🦺 Safety

This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust.
Expand Down
44 changes: 0 additions & 44 deletions examples/moka-postgres-store.rs

This file was deleted.

35 changes: 0 additions & 35 deletions examples/mongodb-store.rs

This file was deleted.

48 changes: 0 additions & 48 deletions examples/mysql-store.rs

This file was deleted.

Loading

0 comments on commit 6359e76

Please sign in to comment.