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