Update crates and change to UUID

This commit is contained in:
2022-08-18 21:24:16 +02:00
parent 9227cdef9a
commit f2cdbe0638
11 changed files with 1835 additions and 144 deletions

View File

@ -10,12 +10,13 @@ use crypto::digest::Digest;
use crypto::sha2::Sha256;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use uuid::Uuid;
#[derive(Serialize, Deserialize)]
pub struct InputEnvelope {
pub endpoint: String,
pub from_domain: Option<String>,
pub to_domain: String,
pub from_domain: Option<Uuid>,
pub to_domain: Uuid,
pub token: Option<String>,
pub request_nr: Option<u64>,
pub data: Value,
@ -30,32 +31,21 @@ pub struct OutputEnvelope {
#[derive(Clone, Serialize, Deserialize)]
pub struct Event {
data: Value,
id: Option<Uuid>,
}
pub struct Account {
id: String,
id: Uuid,
name: String,
domain: String,
domain: Uuid,
}
pub struct Session {
id: String,
id: Uuid,
nr: i32,
account: Option<Account>,
}
pub fn get_id(input: &[&str]) -> String {
let mut hasher = Sha256::new();
hasher.input_str(chrono::Utc::now().timestamp_millis().to_string().as_str());
for part in input {
hasher.input_str(" ");
hasher.input_str(part);
}
let mut result = [0u8; 32];
hasher.result(&mut result);
base64_url::encode(&result)
}
pub fn get_account(session: &Option<Session>) -> Result<&Account, Error> {
match session {
Some(session) => match &session.account {
@ -97,8 +87,8 @@ impl Session {
let res = client
.query(
"SELECT session_id, session_nr, a.account_id, account_name, domain_id \
FROM accounts a JOIN sessions s ON a.account_id = s.account_id \
WHERE session_token = $1;",
FROM account a JOIN session s ON a.account_id = s.account_id \
WHERE session_token = $1;",
&[&token],
)
.await?;