Skip to content

Commit

Permalink
Fix the fake dependency by moving away from git
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonkle committed Jan 7, 2025
1 parent bc2461f commit 71a7b49
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 77 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.24.1]

### Changed

- (all packages) - Remove the `git = "<https://github.com/cksac/fake-rs.git>"` parameter from the `fake` dependency, as it is no longer needed.
- `nakago-axum` - Change `std::panic::PanicInfo` to `std::panic::PanicHookInfo`

## [0.24.0]

### Added
Expand Down
9 changes: 2 additions & 7 deletions examples/async-graphql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-examples-async-graphql"
version = "0.24.0"
version = "0.24.1"
description = "A lightweight Rust toolkit for sharp dependency injection 😎"
license.workspace = true
edition.workspace = true
Expand All @@ -24,12 +24,7 @@ async-trait = "0.1"
axum = { version = "0.7", features = ["ws", "macros"] }
chrono = { version = "0.4.19", features = ["serde"] }
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env", "toml", "yaml", "json"] }
futures = "0.3"
hyper = "1.0"
Expand Down
9 changes: 2 additions & 7 deletions examples/cqrs-es/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-examples-cqrs-es"
version = "0.23.0"
version = "0.24.1"
description = "A lightweight Rust toolkit for sharp dependency injection 😎"
license.workspace = true
edition.workspace = true
Expand All @@ -20,11 +20,6 @@ nakago = "0.23"

[dev-dependencies]
criterion = "0.5"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
mockall = "0.13"
pretty_assertions = "1.2"
9 changes: 2 additions & 7 deletions examples/simple-warp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-examples-simple-warp"
version = "0.23.0"
version = "0.24.1"
description = "A lightweight Rust toolkit for sharp dependency injection 😎"
license.workspace = true
edition.workspace = true
Expand All @@ -17,12 +17,7 @@ integration = []
anyhow = "1.0"
async-trait = "0.1"
chrono = { version = "0.4.19", features = ["serde"] }
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env", "toml", "yaml", "json"] }
futures = "0.3"
hyper = "1.0"
Expand Down
9 changes: 2 additions & 7 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-examples-simple"
version = "0.23.0"
version = "0.24.1"
description = "A lightweight Rust toolkit for sharp dependency injection 😎"
license.workspace = true
edition.workspace = true
Expand All @@ -18,12 +18,7 @@ anyhow = "1.0"
async-trait = "0.1"
axum = { version = "0.7", features = ["ws", "macros"] }
chrono = { version = "0.4.19", features = ["serde"] }
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env", "toml", "yaml", "json"] }
futures = "0.3"
hyper = "1.0"
Expand Down
9 changes: 2 additions & 7 deletions nakago/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago"
version = "0.23.0"
version = "0.24.1"
description = "A lightweight Rust toolkit for sharp dependency injection 😎"
documentation = "https://docs.rs/nakago/"
license.workspace = true
Expand Down Expand Up @@ -30,12 +30,7 @@ tokio = { version = "1", features = ["full"] }

[dev-dependencies]
criterion = "0.5"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
mockall = "0.13"
pretty_assertions = "1.2"
googletest = "0.12"
9 changes: 2 additions & 7 deletions nakago_async_graphql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-async-graphql"
version = "0.24.0"
version = "0.24.1"
description = "An Async-GraphQL integration for Nakago"
documentation = "https://docs.rs/nakago-async-graphql/"
license.workspace = true
Expand All @@ -19,12 +19,7 @@ async-graphql-axum = { version = "6.0", git = "https://github.com/bkonkle/async-
async-trait = "0.1"
axum = { version = "0.7", features = ["macros"] }
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env"] }
hyper = "1.0"
log = "0.4"
Expand Down
9 changes: 2 additions & 7 deletions nakago_axum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-axum"
version = "0.24.0"
version = "0.24.1"
description = "An Axum HTTP routes integration for Nakago"
documentation = "https://docs.rs/nakago-axum/"
license.workspace = true
Expand All @@ -18,12 +18,7 @@ biscuit = "0.7.0"
bytes = "1"
crossterm = "0.28"
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env"] }
futures-util = { version = "0.3", default-features = false, features = [
"sink",
Expand Down
4 changes: 2 additions & 2 deletions nakago_axum/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io, net::SocketAddr, panic::PanicInfo, sync::Arc};
use std::{io, net::SocketAddr, panic::PanicHookInfo, sync::Arc};

use axum::{serve::Serve, Router};
use backtrace::Backtrace;
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn trace_layer() -> TraceLayer<SharedClassifier<ServerErrorsAsFailures>> {
// --------------

/// A generic function to log stacktraces on panic
pub fn handle_panic(info: &PanicInfo<'_>) {
pub fn handle_panic(info: &PanicHookInfo<'_>) {

Check warning on line 87 in nakago_axum/src/init.rs

View check run for this annotation

Codecov / codecov/patch

nakago_axum/src/init.rs#L87

Added line #L87 was not covered by tests
if cfg!(debug_assertions) {
let location = info.location().unwrap();

Expand Down
9 changes: 2 additions & 7 deletions nakago_figment/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-figment"
version = "0.23.0"
version = "0.24.1"
description = "Figment config loading utils for Nakago"
documentation = "https://docs.rs/nakago-figment/"
license.workspace = true
Expand All @@ -12,12 +12,7 @@ homepage.workspace = true
[dependencies]
anyhow = "1.0"
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env", "toml", "yaml", "json"] }
log = "0.4"
nakago = "0.23"
Expand Down
2 changes: 1 addition & 1 deletion nakago_sea_orm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-sea-orm"
version = "0.23.0"
version = "0.24.1"
description = "A SeaORM integration for Nakago"
documentation = "https://docs.rs/nakago-sea-orm/"
license.workspace = true
Expand Down
7 changes: 1 addition & 6 deletions nakago_warp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ async-trait = "0.1"
biscuit = "0.7.0"
bytes = "1"
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
figment = { version = "0.10", features = ["env"] }
futures-util = { version = "0.3", default-features = false, features = [
"sink",
Expand Down
9 changes: 2 additions & 7 deletions nakago_ws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nakago-ws"
version = "0.24.0"
version = "0.24.1"
description = "Websocket utils for Nakago"
documentation = "https://docs.rs/nakago-ws/"
license.workspace = true
Expand All @@ -15,12 +15,7 @@ async-trait = "0.1"
axum = { version = "0.7", features = ["ws", "macros"] }
biscuit = "0.7.0"
derive-new = "0.7"
fake = { version = "2.9", features = [
'derive',
'chrono',
'http',
'uuid',
], git = "https://github.com/cksac/fake-rs.git" }
fake = { version = "2.9", features = ['derive', 'chrono', 'http', 'uuid'] }
futures = "0.3"
http = "1.0.0"
hyper = "1.0"
Expand Down
67 changes: 62 additions & 5 deletions website/docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,62 @@ nakago_figment::Init::<Config>::default()
.await?;
```

First, add the default JWKS Validator from `nakago_axum`'s `auth` module using the `provide_type` method, which uses the type as the key for the Inject container:
First, add the default JWKS Validator from `nakago_axum`'s `auth` module using the `provide` method, which uses the type as the key for the Inject container. Add this to your `init.rs` file, within the `app()` function:

```rust
use nakago_axum::auth::{validator, Validator};

// ...

i.provide::<Validator>(validator::Provide::default()).await?;
i.provide::<Box<dyn Validator>>(validator::Provide::default())
.await?;
```

This will be overridden in your tests to use the unverified variant, but we'll get to that later. Next you should use `jwks::Provide` to inject the JWKS config:
This will be overridden in your tests to use the unverified variant, but we'll get to that later. Next you should use `jwks::Provide` to inject the JWKS config. Add thios to your `init.rs` file as well:

```rust
use nakago_axum::auth::{jwks, Jwks};
use nakago_axum::auth::{jwks, JWKSet, Empty};

// ...

i.provide::<Jwks>(jwks::Provide::<Config>::default()).await?;
i.provide::<JWKSet<Empty>>(jwks::Provide::<Config>::default())
.await?;
```

Your `init.rs` should now look like this:

```rust
use std::path::PathBuf;

use nakago::{Inject, Result};
use nakago_axum::{
auth::{jwks, validator, Empty, JWKSet, Validator},
config,
};

use crate::config::Config;

/// Create a dependency injection container for the top-level application
pub async fn app(config_path: Option<PathBuf>) -> Result<Inject> {
let i = Inject::default();

i.provide::<Box<dyn Validator>>(validator::Provide::default())
.await?;

i.provide::<JWKSet<Empty>>(jwks::Provide::<Config>::default())
.await?;

// Add config loaders before the Config is initialized
config::add_default_loaders(&i).await?;

// Initialize the Config
nakago_figment::Init::<Config>::default()
.maybe_with_path(config_path)
.init(&i)
.await?;

Ok(i)
}
```

### Axum Route
Expand Down Expand Up @@ -167,10 +205,29 @@ pub async fn get_username(sub: Subject) -> Json<UsernameResponse> {
}
```

Make sure to add the `user.rs` file to your `http/mod.rs` file:

```rust
/// User handlers
pub mod user;
```

The `Subject` extension uses Nakago Axum's State proivider to find the Inject container, which it then uses to grab the JWT config and the Validator instance. It decodes the JWT and returns the `sub` claim from the payload. If the user is not logged in, the `Subject` will contain a `None`.

Now add a route that uses the handler to the Init hook at `http/router.rs`:

```rust
use super::{health, user};

// ...

Router::new()
// ...
.route("/username", get(user::get_username))
```

Your `http/router.rs` file should now look like this:

```rust
/// This method should already exist in your `http/router.rs` file
pub fn init(i: &Inject) -> Router {
Expand Down

0 comments on commit 71a7b49

Please sign in to comment.