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 time 0.1 dependency #133

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
424 changes: 172 additions & 252 deletions Cargo.lock

Large diffs are not rendered by default.

965 changes: 397 additions & 568 deletions Cargo.nix

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions sos21-api-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ license = "MIT OR Apache-2.0"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-futures = "0.2"
tracing-subscriber = "0.2"
tracing-subscriber = "0.2.25"
anyhow = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
futures = "0.3"
async-trait = "0.1.42"
thiserror = "1"
chrono = "0.4"
chrono = { version = "0.4", default-features = false }
uuid = { version = "0.8", features = ["v4"] }
warp = { version = "0.3.1", default-features = false }
sqlx = { version = "0.5", features = ["postgres", "runtime-tokio-rustls"] }
jsonwebtoken = "7"
jsonwebtoken = "8.0.0-beta.5"
mime = "0.3"
bytes = "1"
mpart-async = "0.5"
Expand All @@ -42,4 +42,4 @@ sos21-gateway-s3 = { path = "../sos21-gateway/s3" }
sos21-use-case = { path = "../sos21-use-case" }

[build-dependencies]
vergen = { version = "4", default-features = false, features = ["build", "cargo", "git"] }
built = { version = "0.5", features = ["git2"] }
2 changes: 1 addition & 1 deletion sos21-api-server/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
vergen::vergen(vergen::Config::default())?;
built::write_built_file()?;

Ok(())
}
12 changes: 3 additions & 9 deletions sos21-api-server/src/filter/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@ async fn validate_token(
let header = jwt::decode_header(&bearer.token)?;
let kid = header.kid.context("No key ID found in JWT header")?;
let key = key_store.get(&kid).await.context("Unknown key ID")?;
let validation = jwt::Validation {
leeway: 0,
validate_exp: true,
validate_nbf: false,
aud: Some(std::iter::once(config.jwt_audience.clone()).collect()),
iss: Some(config.jwt_issuer.clone()),
sub: None,
algorithms: vec![jwt::Algorithm::RS256],
};
let mut validation = jwt::Validation::new(jwt::Algorithm::RS256);
validation.set_audience(&[config.jwt_audience.clone()]);
validation.set_iss(&[config.jwt_issuer.clone()]);
let data = jwt::decode(&bearer.token, &key, &validation).context("Failed to validate JWT")?;
Ok(data.claims)
}
Expand Down
13 changes: 6 additions & 7 deletions sos21-api-server/src/filter/authentication/key_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use url::Url;
pub struct KeyStore {
url: Url,
client: Client,
keys: Arc<RwLock<HashMap<String, DecodingKey<'static>>>>,
keys: Arc<RwLock<HashMap<String, DecodingKey>>>,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -80,18 +80,17 @@ impl KeyStore {
.keys
.into_iter()
.map(|key| {
(
key.kid,
DecodingKey::from_rsa_components(&key.n, &key.e).into_static(),
)
DecodingKey::from_rsa_components(&key.n, &key.e)
.map(|dk| (key.kid, dk))
.context("Failed to decode keys")
})
.collect();
.collect::<Result<_>>()?;
*self.keys.write().await = keys;

Ok(max_age)
}

pub async fn get<T>(&self, kid: &T) -> Option<DecodingKey<'static>>
pub async fn get<T>(&self, kid: &T) -> Option<DecodingKey>
where
T: Hash + Eq,
String: Borrow<T>,
Expand Down
8 changes: 6 additions & 2 deletions sos21-api-server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ macro_rules! handler {
$vis async fn $name(
$($param: $ty),*
) -> Result<impl ::warp::reply::Reply, ::warp::reject::Rejection> {
let result: HandlerResult<$resp, $err> = $body;
crate::handler::handle_handler_result(result)
async fn run(
$($param: $ty),*
) -> HandlerResult<$resp, $err> {
$body
}
crate::handler::handle_handler_result(run($($param),*).await)
}
};
(@impl_authentication $vis:vis $name:ident (
Expand Down
35 changes: 22 additions & 13 deletions sos21-api-server/src/handler/meta/get_build_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::handler::{HandlerResponse, HandlerResult};
use crate::build_info;
use crate::handler::{HandlerError, HandlerResponse, HandlerResult};

use anyhow::anyhow;
use serde::{Deserialize, Serialize};
use warp::http::StatusCode;

Expand Down Expand Up @@ -37,23 +39,30 @@ impl HandlerResponse for Response {
}
}

fn git_info() -> Option<ResponseGit> {
let commit = build_info::GIT_COMMIT_HASH?;
let version = build_info::GIT_VERSION?;
let branch = build_info::GIT_HEAD_REF?;
Some(ResponseGit {
commit,
version,
branch,
})
}

#[macro_rules_attribute::macro_rules_attribute(handler!)]
pub async fn handler(_request: Request) -> HandlerResult<Response, Error> {
// See https://docs.rs/vergen/ and sos21-api-server/build.rs

let git = {
let commit = env!("VERGEN_GIT_SHA");
let version = env!("VERGEN_GIT_SEMVER");
let branch = env!("VERGEN_GIT_BRANCH");
ResponseGit {
commit,
version,
branch,
let git = match git_info() {
Some(git) => git,
None => {
return Err(HandlerError::ServiceUnavailable(anyhow!(
"no git info available"
)))
}
};

let version = env!("VERGEN_BUILD_SEMVER");
let profile = env!("VERGEN_CARGO_PROFILE");
let version = build_info::PKG_VERSION;
let profile = build_info::PROFILE;
let out = option_env!("out");

Ok(Response {
Expand Down
4 changes: 4 additions & 0 deletions sos21-api-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ pub mod handler;

pub use config::Config;
pub use server::Server;

mod build_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
2 changes: 1 addition & 1 deletion sos21-database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
anyhow = "1"
chrono = "0.4"
chrono = { version = "0.4", default-features = false }
uuid = "0.8"
futures = "0.3"
bitflags = "1"
Expand Down
2 changes: 1 addition & 1 deletion sos21-domain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
test = ["tokio", "maplit", "once_cell", "rand"]

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4", default-features = false, features = ["serde"] }
thiserror = "1"
enumflags2 = "0.7"
paste = "1"
Expand Down
2 changes: 1 addition & 1 deletion sos21-run-migrations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ structopt = "0.3"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-futures = "0.2"
tracing-subscriber = "0.2"
tracing-subscriber = "0.2.25"
2 changes: 1 addition & 1 deletion sos21-use-case/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
[dependencies]
anyhow = "1"
bytes = "1"
chrono = "0.4"
chrono = { version = "0.4", default-features = false }
csv = "1"
futures = "0.3"
mime = "0.3"
Expand Down