mirror of https://github.com/apibillme/broker
replace broker-ntp with nippy
This commit is contained in:
parent
8283767ef0
commit
d3fd496363
|
@ -4,6 +4,11 @@ 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.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [6.1.x] - 2021-03-21
|
||||
|
||||
### Changed
|
||||
- Replaced broker-ntp with nippy
|
||||
|
||||
## [6.0.x] - 2021-03-20
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -167,7 +167,7 @@ dependencies = [
|
|||
"http-types",
|
||||
"httparse",
|
||||
"lazy_static",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"pin-project",
|
||||
]
|
||||
|
||||
|
@ -181,7 +181,7 @@ dependencies = [
|
|||
"fastrand",
|
||||
"futures-lite",
|
||||
"libc",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"nb-connect",
|
||||
"once_cell",
|
||||
"parking",
|
||||
|
@ -255,7 +255,7 @@ dependencies = [
|
|||
"async-channel",
|
||||
"async-std",
|
||||
"http-types",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"memchr",
|
||||
"pin-project-lite 0.1.12",
|
||||
]
|
||||
|
@ -279,7 +279,7 @@ dependencies = [
|
|||
"futures-lite",
|
||||
"gloo-timers",
|
||||
"kv-log-macro",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"memchr",
|
||||
"num_cpus",
|
||||
"once_cell",
|
||||
|
@ -362,9 +362,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
|||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.2"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d175dfa69e619905c4c3cdb7c3c203fa3bdd5d51184e3afdb2742c0280493772"
|
||||
checksum = "f30d3a39baa26f9651f17b375061f3233dde33424a8b72b0dbe93a68a0bc896d"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"serde",
|
||||
|
@ -384,7 +384,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"peeking_take_while",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -451,11 +451,10 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "broker"
|
||||
version = "6.0.8"
|
||||
version = "6.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-std",
|
||||
"broker-ntp",
|
||||
"driftwood",
|
||||
"futures",
|
||||
"go-flag",
|
||||
|
@ -463,6 +462,7 @@ dependencies = [
|
|||
"json",
|
||||
"jsonwebtoken",
|
||||
"lazy_static",
|
||||
"nippy",
|
||||
"rmp-serde",
|
||||
"rocksdb",
|
||||
"rust-argon2",
|
||||
|
@ -474,18 +474,6 @@ dependencies = [
|
|||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "broker-ntp"
|
||||
version = "0.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "037d0f8fa2a4e20313da3d34d3d40606e6366fdc1458f664fc03edc89aa34292"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"conv",
|
||||
"custom_derive",
|
||||
"log 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.6.1"
|
||||
|
@ -504,9 +492,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.3.4"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cache-padded"
|
||||
|
@ -792,7 +780,7 @@ checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
|||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
@ -820,7 +808,7 @@ checksum = "2af1a24f391a5a94d756db5092c6576aad494b88a71a5a36b20c67b63e0df034"
|
|||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"js-sys",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
|
@ -1064,7 +1052,7 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
"dashmap",
|
||||
"http-types",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1180,7 +1168,7 @@ version = "1.0.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f"
|
||||
dependencies = [
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1223,15 +1211,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
|
||||
dependencies = [
|
||||
"log 0.4.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
|
@ -1270,6 +1249,20 @@ dependencies = [
|
|||
"socket2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nippy"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e10eb341b90e4f4c1b4780fbcc203611b7c94768e85ee0b7955d15c4c10ec169"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-std",
|
||||
"byteorder",
|
||||
"conv",
|
||||
"custom_derive",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "5.1.2"
|
||||
|
@ -1407,7 +1400,7 @@ checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4"
|
|||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"libc",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"wepoll-sys",
|
||||
"winapi",
|
||||
]
|
||||
|
@ -1649,7 +1642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"ring",
|
||||
"sct",
|
||||
"webpki",
|
||||
|
@ -1984,7 +1977,7 @@ dependencies = [
|
|||
"http-client",
|
||||
"http-types",
|
||||
"kv-log-macro",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"pin-project-lite 0.2.6",
|
||||
"route-recognizer",
|
||||
"serde",
|
||||
|
@ -2210,7 +2203,7 @@ checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3"
|
|||
dependencies = [
|
||||
"bumpalo",
|
||||
"lazy_static",
|
||||
"log 0.4.14",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "broker"
|
||||
version = "6.0.8"
|
||||
version = "6.1.0"
|
||||
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
@ -22,7 +22,7 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
|
|||
jsonwebtoken = "7.0.1"
|
||||
go-flag = "0.1"
|
||||
lazy_static = "1.4"
|
||||
broker-ntp = "0.0.1"
|
||||
nippy = "1.0.0"
|
||||
rust-argon2 = "0.8"
|
||||
anyhow = "1"
|
||||
rmp-serde = "0.15"
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -138,13 +138,6 @@ fn puts_event(event: Event) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_ntp_time() -> i64 {
|
||||
let pool_ntp = "pool.ntp.org:123";
|
||||
let response = broker_ntp::request(pool_ntp).unwrap();
|
||||
let timestamp = response.transmit_timestamp;
|
||||
broker_ntp::unix_time::Instant::from(timestamp).secs()
|
||||
}
|
||||
|
||||
fn user_create(user_form: UserForm) -> Result<Option<String>> {
|
||||
|
||||
if !is_user_unique(user_form.clone().username)? {
|
||||
|
@ -165,7 +158,7 @@ fn user_create(user_form: UserForm) -> Result<Option<String>> {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_jwt(login: LoginForm) -> Result<Option<String>> {
|
||||
async fn create_jwt(login: LoginForm) -> Result<Option<String>> {
|
||||
|
||||
let user_value = get_user_by_username(login.username)?;
|
||||
match user_value {
|
||||
|
@ -173,7 +166,7 @@ fn create_jwt(login: LoginForm) -> Result<Option<String>> {
|
|||
let verified = argon2::verify_encoded(&user.password, login.password.as_bytes())?;
|
||||
if verified {
|
||||
let app = env_var_config();
|
||||
let iat = get_ntp_time();
|
||||
let iat = nippy::get_unix_ntp_time().await?;
|
||||
let exp = iat + app.jwt_expiry;
|
||||
let iss = "Dispatcher".to_string();
|
||||
let my_claims = Claims{sub: user.clone().username, exp, iat, iss};
|
||||
|
@ -239,7 +232,7 @@ async fn insert(user_username: String, event_form: EventForm) -> Result<bool> {
|
|||
|
||||
match user_value {
|
||||
Some(user) => {
|
||||
let timestamp = get_ntp_time();
|
||||
let timestamp = nippy::get_unix_ntp_time().await?;
|
||||
let id = uuid::Uuid::new_v4();
|
||||
|
||||
let event = Event{
|
||||
|
@ -276,7 +269,7 @@ async fn create_user(mut req: Request<()>) -> tide::Result {
|
|||
async fn login_user(mut req: Request<()>) -> tide::Result {
|
||||
let r = req.body_string().await?;
|
||||
let login_form : LoginForm = serde_json::from_str(&r)?;
|
||||
match create_jwt(login_form)? {
|
||||
match create_jwt(login_form).await? {
|
||||
Some(jwt) => {
|
||||
let msg = format!("jwt: {}", jwt);
|
||||
Ok(tide::Response::builder(200).body(msg).header("content-type", "application/json").build())
|
||||
|
|
Loading…
Reference in New Issue