parent
5e5342ebc7
commit
8f89f8729c
10 changed files with 556 additions and 541 deletions
932
Cargo.lock
generated
932
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
24
Cargo.toml
24
Cargo.toml
|
@ -26,27 +26,27 @@ codegen-units = 1
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
argon2 = "0.4.1"
|
argon2 = "0.4.1"
|
||||||
base64 = "0.13.0"
|
clap = { version = "3.2.23", features = ["env"] }
|
||||||
bytes = "1.2.1"
|
base64 = "0.21.0"
|
||||||
chrono = { version = "0.4.22", features = ["serde"] }
|
bytes = "1.3.0"
|
||||||
clap = { version = "3.2.22", features = ["env"] }
|
chrono = { version = "0.4.23", features = ["serde"] }
|
||||||
fern = { version = "0.6.1", features = ["colored"] }
|
fern = { version = "0.6.1", features = ["colored"] }
|
||||||
futures = "0.3.24"
|
futures = "0.3.25"
|
||||||
http = "0.2.8"
|
http = "0.2.8"
|
||||||
hyper = "0.14.20"
|
hyper = "0.14.23"
|
||||||
jsonwebtoken = "8.1.1"
|
jsonwebtoken = "8.2.0"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
once_cell = "1.15.0"
|
once_cell = "1.17.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
reqwest = { version = "0.11.13", features = ["blocking"] }
|
reqwest = { version = "0.11.13", features = ["blocking"] }
|
||||||
rustyline = "10.0.0"
|
rustyline = "10.0.0"
|
||||||
serde = { version = "1.0.145", features = ["derive"] }
|
serde = { version = "1.0.152", features = ["derive"] }
|
||||||
serde_cbor = "0.11.2"
|
serde_cbor = "0.11.2"
|
||||||
serde_json = "1.0.85"
|
serde_json = "1.0.91"
|
||||||
serde_pack = { version = "1.1.1", package = "rmp-serde" }
|
serde_pack = { version = "1.1.1", package = "rmp-serde" }
|
||||||
surrealdb = { path = "lib", features = ["protocol-http", "protocol-ws", "rustls"] }
|
surrealdb = { path = "lib", features = ["protocol-http", "protocol-ws", "rustls"] }
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.38"
|
||||||
tokio = { version = "1.21.2", features = ["macros", "signal"] }
|
tokio = { version = "1.24.1", features = ["macros", "signal"] }
|
||||||
warp = { version = "0.3.3", features = ["compression", "tls", "websocket"] }
|
warp = { version = "0.3.3", features = ["compression", "tls", "websocket"] }
|
||||||
|
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
|
|
|
@ -55,19 +55,19 @@ argon2 = "0.4.1"
|
||||||
async-recursion = "1.0.0"
|
async-recursion = "1.0.0"
|
||||||
bcrypt = "0.13.0"
|
bcrypt = "0.13.0"
|
||||||
bigdecimal = { version = "0.3.0", features = ["serde", "string-only"] }
|
bigdecimal = { version = "0.3.0", features = ["serde", "string-only"] }
|
||||||
channel = { version = "1.7.1", package = "async-channel" }
|
channel = { version = "1.8.0", package = "async-channel" }
|
||||||
chrono = { version = "0.4.22", features = ["serde"] }
|
chrono = { version = "0.4.23", features = ["serde"] }
|
||||||
derive = { version = "0.5.0", package = "surrealdb-derive" }
|
derive = { version = "0.5.0", package = "surrealdb-derive" }
|
||||||
deunicode = "1.3.2"
|
deunicode = "1.3.3"
|
||||||
dmp = "0.1.1"
|
dmp = "0.1.1"
|
||||||
echodb = { version = "0.3.0", optional = true }
|
echodb = { version = "0.3.0", optional = true }
|
||||||
executor = { version = "1.4.1", package = "async-executor" }
|
executor = { version = "1.5.0", package = "async-executor" }
|
||||||
flume = "0.10.14"
|
flume = "0.10.14"
|
||||||
futures = "0.3.24"
|
futures = "0.3.25"
|
||||||
futures-concurrency = "7.0.0"
|
futures-concurrency = "7.0.0"
|
||||||
foundationdb = { version = "0.7.0", default-features = false, features = ["embedded-fdb-include"], optional = true }
|
foundationdb = { version = "0.7.0", default-features = false, features = ["embedded-fdb-include"], optional = true }
|
||||||
fuzzy-matcher = "0.3.7"
|
fuzzy-matcher = "0.3.7"
|
||||||
geo = { version = "0.23.0", features = ["use-serde"] }
|
geo = { version = "0.23.1", features = ["use-serde"] }
|
||||||
indexmap = { version = "1.9.2", features = ["serde"] }
|
indexmap = { version = "1.9.2", features = ["serde"] }
|
||||||
indxdb = { version = "0.2.0", optional = true }
|
indxdb = { version = "0.2.0", optional = true }
|
||||||
lexical-sort = "0.3.1"
|
lexical-sort = "0.3.1"
|
||||||
|
@ -76,22 +76,22 @@ md-5 = "0.10.5"
|
||||||
msgpack = { version = "1.1.1", package = "rmp-serde" }
|
msgpack = { version = "1.1.1", package = "rmp-serde" }
|
||||||
nanoid = "0.4.0"
|
nanoid = "0.4.0"
|
||||||
native-tls = { version = "0.2.11", optional = true }
|
native-tls = { version = "0.2.11", optional = true }
|
||||||
nom = { version = "7.1.1", features = ["alloc"] }
|
nom = { version = "7.1.2", features = ["alloc"] }
|
||||||
once_cell = "1.16.0"
|
once_cell = "1.17.0"
|
||||||
pbkdf2 = "0.11.0"
|
pbkdf2 = "0.11.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
regex = "1.6.0"
|
regex = "1.7.1"
|
||||||
reqwest = { version = "0.11.13", default-features = false, features = ["json", "stream"], optional = true }
|
reqwest = { version = "0.11.13", default-features = false, features = ["json", "stream"], optional = true }
|
||||||
rocksdb = { version = "0.19.0", optional = true }
|
rocksdb = { version = "0.19.0", optional = true }
|
||||||
rustls = { version = "0.20.7", optional = true }
|
rustls = { version = "0.20.8", optional = true }
|
||||||
scrypt = "0.10.0"
|
scrypt = "0.10.0"
|
||||||
semver = { version = "1.0.14", features = ["serde"] }
|
semver = { version = "1.0.16", features = ["serde"] }
|
||||||
serde = { version = "1.0.148", features = ["derive"] }
|
serde = { version = "1.0.152", features = ["derive"] }
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.91"
|
||||||
sha-1 = "0.10.0"
|
sha-1 = "0.10.1"
|
||||||
sha2 = "0.10.6"
|
sha2 = "0.10.6"
|
||||||
storekey = "0.3.0"
|
storekey = "0.4.0"
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.38"
|
||||||
tikv = { version = "0.1.0", package = "tikv-client", optional = true }
|
tikv = { version = "0.1.0", package = "tikv-client", optional = true }
|
||||||
tokio-stream = { version = "0.1.11", optional = true }
|
tokio-stream = { version = "0.1.11", optional = true }
|
||||||
tokio-util = { version = "0.7.4", optional = true, features = ["compat"] }
|
tokio-util = { version = "0.7.4", optional = true, features = ["compat"] }
|
||||||
|
@ -115,17 +115,17 @@ features = [
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
time = { version = "0.3.17", features = ["serde"] }
|
time = { version = "0.3.17", features = ["serde"] }
|
||||||
tokio = { version = "1.22.0", features = ["macros", "rt", "rt-multi-thread"] }
|
tokio = { version = "1.24.1", features = ["macros", "rt", "rt-multi-thread"] }
|
||||||
ulid = { version = "1.0.0", features = ["serde"] }
|
ulid = { version = "1.0.0", features = ["serde"] }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
pharos = "0.5.3"
|
pharos = "0.5.3"
|
||||||
tokio = { version = "1.22.0", default-features = false, features = ["rt"] }
|
tokio = { version = "1.24.1", default-features = false, features = ["rt"] }
|
||||||
uuid = { version = "1.2.1", features = ["serde", "js", "v4", "v7"] }
|
uuid = { version = "1.2.2", features = ["serde", "js", "v4", "v7"] }
|
||||||
wasm-bindgen-futures = "0.4.33"
|
wasm-bindgen-futures = "0.4.33"
|
||||||
ws_stream_wasm = "0.7.3"
|
ws_stream_wasm = "0.7.3"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
tokio = { version = "1.22.0", default-features = false, features = ["io-util", "fs", "rt-multi-thread"] }
|
tokio = { version = "1.24.1", default-features = false, features = ["io-util", "fs", "rt-multi-thread"] }
|
||||||
tokio-tungstenite = { version = "0.17.2", optional = true }
|
tokio-tungstenite = { version = "0.18.0", optional = true }
|
||||||
uuid = { version = "1.2.1", features = ["serde", "v4", "v7"] }
|
uuid = { version = "1.2.2", features = ["serde", "v4", "v7"] }
|
||||||
|
|
|
@ -6,6 +6,6 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = { version = "4.2.1", features = ["macros"] }
|
actix-web = { version = "4.2.1", features = ["macros"] }
|
||||||
serde = { version = "1.0.147", features = ["derive"] }
|
serde = { version = "1.0.152", features = ["derive"] }
|
||||||
surrealdb = { path = "../.." }
|
surrealdb = { path = "../.." }
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.38"
|
||||||
|
|
|
@ -73,7 +73,7 @@ impl<'js> FromJs<'js> for Value {
|
||||||
if (v).is_instance_of(&date) {
|
if (v).is_instance_of(&date) {
|
||||||
let f: js::Function = v.get("getTime")?;
|
let f: js::Function = v.get("getTime")?;
|
||||||
let m: i64 = f.call((js::This(v),))?;
|
let m: i64 = f.call((js::This(v),))?;
|
||||||
let d = Utc.timestamp_millis(m);
|
let d = Utc.timestamp_millis_opt(m).unwrap();
|
||||||
return Ok(Datetime::from(d).into());
|
return Ok(Datetime::from(d).into());
|
||||||
}
|
}
|
||||||
// Check to see if this object is an array
|
// Check to see if this object is an array
|
||||||
|
|
|
@ -41,23 +41,35 @@ pub fn group((datetime, strand): (Value, Value)) -> Result<Value, Error> {
|
||||||
match datetime {
|
match datetime {
|
||||||
Value::Datetime(v) => match strand {
|
Value::Datetime(v) => match strand {
|
||||||
Value::Strand(g) => match g.as_str() {
|
Value::Strand(g) => match g.as_str() {
|
||||||
"year" => Ok(Utc.ymd(v.year(), 1, 1).and_hms(0, 0, 0).into()),
|
"year" => Ok(Utc
|
||||||
"month" => Ok(Utc.ymd(v.year(), v.month(), 1).and_hms(0, 0, 0).into()),
|
.with_ymd_and_hms(v.year(), 1, 1, 0,0,0)
|
||||||
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
|
.into()),
|
||||||
|
"month" => Ok(Utc
|
||||||
|
.with_ymd_and_hms(v.year(), v.month(), 1, 0,0,0)
|
||||||
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
|
.into()),
|
||||||
"day" => Ok(Utc
|
"day" => Ok(Utc
|
||||||
.ymd(v.year(), v.month(), v.day())
|
.with_ymd_and_hms(v.year(), v.month(), v.day(), 0,0,0)
|
||||||
.and_hms(0, 0, 0)
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
.into()),
|
.into()),
|
||||||
"hour" => Ok(Utc
|
"hour" => Ok(Utc
|
||||||
.ymd(v.year(), v.month(), v.day())
|
.with_ymd_and_hms(v.year(), v.month(), v.day(), v.hour(),0,0)
|
||||||
.and_hms(v.hour(), 0, 0)
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
.into()),
|
.into()),
|
||||||
"minute" => Ok(Utc
|
"minute" => Ok(Utc
|
||||||
.ymd(v.year(), v.month(), v.day())
|
.with_ymd_and_hms(v.year(), v.month(), v.day(), v.hour(),v.minute(),0)
|
||||||
.and_hms(v.hour(), v.minute(), 0)
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
.into()),
|
.into()),
|
||||||
"second" => Ok(Utc
|
"second" => Ok(Utc
|
||||||
.ymd(v.year(), v.month(), v.day())
|
.with_ymd_and_hms(v.year(), v.month(), v.day(), v.hour(), v.minute(), v.second())
|
||||||
.and_hms(v.hour(), v.minute(), v.second())
|
.earliest()
|
||||||
|
.unwrap()
|
||||||
.into()),
|
.into()),
|
||||||
_ => Err(Error::InvalidArguments {
|
_ => Err(Error::InvalidArguments {
|
||||||
name: String::from("time::group"),
|
name: String::from("time::group"),
|
||||||
|
|
|
@ -63,4 +63,24 @@ mod tests {
|
||||||
let dec = Thing::decode(&enc).unwrap();
|
let dec = Thing::decode(&enc).unwrap();
|
||||||
assert_eq!(val, dec);
|
assert_eq!(val, dec);
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn key_complex() {
|
||||||
|
use super::*;
|
||||||
|
//
|
||||||
|
let id1 = "['test']";
|
||||||
|
let (_, id1) = crate::sql::id::id(id1).expect("Failed to parse the ID");
|
||||||
|
let val = Thing::new("test".to_string(), "test".to_string(), "test".to_string(), id1);
|
||||||
|
let enc = Thing::encode(&val).unwrap();
|
||||||
|
let dec = Thing::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
println!("---");
|
||||||
|
//
|
||||||
|
let id2 = "['f8e238f2-e734-47b8-9a16-476b291bd78a']";
|
||||||
|
let (_, id2) = crate::sql::id::id(id2).expect("Failed to parse the ID");
|
||||||
|
let val = Thing::new("test".to_string(), "test".to_string(), "test".to_string(), id2);
|
||||||
|
let enc = Thing::encode(&val).unwrap();
|
||||||
|
let dec = Thing::decode(&enc).unwrap();
|
||||||
|
assert_eq!(val, dec);
|
||||||
|
println!("---");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@ use crate::sql::duration::Duration;
|
||||||
use crate::sql::error::IResult;
|
use crate::sql::error::IResult;
|
||||||
use crate::sql::escape::escape_str;
|
use crate::sql::escape::escape_str;
|
||||||
use crate::sql::serde::is_internal_serialization;
|
use crate::sql::serde::is_internal_serialization;
|
||||||
use chrono::{DateTime, FixedOffset, NaiveDate, Offset, SecondsFormat, TimeZone, Utc};
|
use chrono::{DateTime, FixedOffset, Offset, SecondsFormat, TimeZone, Utc};
|
||||||
|
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||||
use nom::branch::alt;
|
use nom::branch::alt;
|
||||||
use nom::character::complete::char;
|
use nom::character::complete::char;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
|
@ -25,12 +26,6 @@ impl Default for Datetime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<i64> for Datetime {
|
|
||||||
fn from(v: i64) -> Self {
|
|
||||||
Self(Utc.timestamp(v, 0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DateTime<Utc>> for Datetime {
|
impl From<DateTime<Utc>> for Datetime {
|
||||||
fn from(v: DateTime<Utc>) -> Self {
|
fn from(v: DateTime<Utc>) -> Self {
|
||||||
Self(v)
|
Self(v)
|
||||||
|
@ -164,13 +159,17 @@ fn convert(
|
||||||
zone: FixedOffset,
|
zone: FixedOffset,
|
||||||
) -> IResult<&str, Datetime> {
|
) -> IResult<&str, Datetime> {
|
||||||
// Attempt to create date
|
// Attempt to create date
|
||||||
let n = NaiveDate::from_ymd_opt(year, mon, day)
|
let d = NaiveDate::from_ymd_opt(year, mon, day)
|
||||||
.ok_or_else(|| Err::Error(error_position!(i, ErrorKind::Verify)))?;
|
.ok_or_else(|| Err::Error(error_position!(i, ErrorKind::Verify)))?;
|
||||||
// Attempt to create time
|
// Attempt to create time
|
||||||
|
let t = NaiveTime::from_hms_nano_opt(hour, min, sec, nano)
|
||||||
|
.ok_or_else(|| Err::Error(error_position!(i, ErrorKind::Verify)))?;
|
||||||
|
//
|
||||||
|
let v = NaiveDateTime::new(d, t);
|
||||||
|
// Attempt to create time
|
||||||
let d = zone
|
let d = zone
|
||||||
.from_local_date(&n)
|
.from_local_datetime(&v)
|
||||||
.unwrap()
|
.earliest()
|
||||||
.and_hms_nano_opt(hour, min, sec, nano)
|
|
||||||
.ok_or_else(|| Err::Error(error_position!(i, ErrorKind::Verify)))?
|
.ok_or_else(|| Err::Error(error_position!(i, ErrorKind::Verify)))?
|
||||||
.with_timezone(&Utc);
|
.with_timezone(&Utc);
|
||||||
// This is a valid datetime
|
// This is a valid datetime
|
||||||
|
@ -237,9 +236,15 @@ fn zone_all(i: &str) -> IResult<&str, FixedOffset> {
|
||||||
if h == 0 && m == 0 {
|
if h == 0 && m == 0 {
|
||||||
Ok((i, Utc.fix()))
|
Ok((i, Utc.fix()))
|
||||||
} else if s < 0 {
|
} else if s < 0 {
|
||||||
Ok((i, FixedOffset::west((h * 3600 + m * 60) as i32)))
|
match FixedOffset::west_opt((h * 3600 + m * 60) as i32) {
|
||||||
|
Some(v) => Ok((i, v)),
|
||||||
|
None => Err(Err::Error(error_position!(i, ErrorKind::Verify))),
|
||||||
|
}
|
||||||
} else if s > 0 {
|
} else if s > 0 {
|
||||||
Ok((i, FixedOffset::east((h * 3600 + m * 60) as i32)))
|
match FixedOffset::east_opt((h * 3600 + m * 60) as i32) {
|
||||||
|
Some(v) => Ok((i, v)),
|
||||||
|
None => Err(Err::Error(error_position!(i, ErrorKind::Verify))),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok((i, Utc.fix()))
|
Ok((i, Utc.fix()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
|
use base64::Engine;
|
||||||
use std::str;
|
use std::str;
|
||||||
use surrealdb::sql::json;
|
use surrealdb::sql::json;
|
||||||
use surrealdb::sql::Value;
|
use surrealdb::sql::Value;
|
||||||
|
@ -7,7 +9,7 @@ pub fn parse(value: &str) -> Result<Value, Error> {
|
||||||
// Extract the middle part of the token
|
// Extract the middle part of the token
|
||||||
let value = value.splitn(3, '.').skip(1).take(1).next().ok_or(Error::InvalidAuth)?;
|
let value = value.splitn(3, '.').skip(1).take(1).next().ok_or(Error::InvalidAuth)?;
|
||||||
// Decode the base64 token data content
|
// Decode the base64 token data content
|
||||||
let value = base64::decode(value).map_err(|_| Error::InvalidAuth)?;
|
let value = BASE64.decode(value).map_err(|_| Error::InvalidAuth)?;
|
||||||
// Convert the decoded data to a string
|
// Convert the decoded data to a string
|
||||||
let value = str::from_utf8(&value).map_err(|_| Error::InvalidAuth)?;
|
let value = str::from_utf8(&value).map_err(|_| Error::InvalidAuth)?;
|
||||||
// Parse the token data into SurrealQL
|
// Parse the token data into SurrealQL
|
||||||
|
|
|
@ -7,6 +7,8 @@ use crate::iam::LOG;
|
||||||
use crate::iam::TOKEN;
|
use crate::iam::TOKEN;
|
||||||
use argon2::password_hash::{PasswordHash, PasswordVerifier};
|
use argon2::password_hash::{PasswordHash, PasswordVerifier};
|
||||||
use argon2::Argon2;
|
use argon2::Argon2;
|
||||||
|
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||||
|
use base64::Engine;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use jsonwebtoken::{decode, DecodingKey, Validation};
|
use jsonwebtoken::{decode, DecodingKey, Validation};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -93,7 +95,7 @@ pub async fn basic(session: &mut Session, auth: String) -> Result<(), Error> {
|
||||||
// Get the config options
|
// Get the config options
|
||||||
let opts = CF.get().unwrap();
|
let opts = CF.get().unwrap();
|
||||||
// Decode the encoded auth data
|
// Decode the encoded auth data
|
||||||
let auth = base64::decode(auth)?;
|
let auth = BASE64.decode(auth)?;
|
||||||
// Convert the auth data to String
|
// Convert the auth data to String
|
||||||
let auth = String::from_utf8(auth)?;
|
let auth = String::from_utf8(auth)?;
|
||||||
// Split the auth data into user and pass
|
// Split the auth data into user and pass
|
||||||
|
|
Loading…
Reference in a new issue