Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02061bf7a3 | ||
|
|
151eeaacf6 | ||
|
|
137398405f |
@@ -14,10 +14,10 @@ jobs:
|
|||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo check
|
- run: cargo check
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ jobs:
|
|||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: cargo fmt --all -- --check
|
- run: cargo fmt --all -- --check
|
||||||
@@ -37,10 +37,10 @@ jobs:
|
|||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: cargo clippy -- -D warnings
|
- run: cargo clippy -- -D warnings
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Important for git describe --tags
|
fetch-depth: 0 # Important for git describe --tags
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
|
|||||||
+10
-10
@@ -14,10 +14,10 @@ jobs:
|
|||||||
name: Check
|
name: Check
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo check
|
- run: cargo check
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ jobs:
|
|||||||
name: Test Suite
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo test
|
- run: cargo test
|
||||||
|
|
||||||
@@ -36,10 +36,10 @@ jobs:
|
|||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: cargo fmt --all -- --check
|
- run: cargo fmt --all -- --check
|
||||||
@@ -48,10 +48,10 @@ jobs:
|
|||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: cargo clippy -- -D warnings
|
- run: cargo clippy -- -D warnings
|
||||||
@@ -60,9 +60,9 @@ jobs:
|
|||||||
name: build
|
name: build
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96
|
toolchain: 1.97
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo build
|
- run: cargo build
|
||||||
|
|||||||
Generated
+167
-442
File diff suppressed because it is too large
Load Diff
+5
-5
@@ -1,16 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "textsender_models"
|
name = "textsender_models"
|
||||||
version = "0.4.11"
|
version = "0.5.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.96"
|
rust-version = "1.97"
|
||||||
description = "Models used for the textsender project"
|
description = "Models used for the textsender project"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.150" }
|
serde_json = { version = "1.0.150" }
|
||||||
time = { version = "0.3.49", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
|
||||||
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
uuid = { version = "1.23.4", features = ["v4", "serde"] }
|
||||||
dotenvy = { version = "0.15.7" }
|
dotenvy = { version = "0.15.7" }
|
||||||
const_format = { version = "0.2.36" }
|
const_format = { version = "0.2.36" }
|
||||||
josekit = { version = "0.10.3" }
|
josekit = { version = "0.10.3" }
|
||||||
|
|||||||
@@ -4,13 +4,10 @@
|
|||||||
pub struct Contact {
|
pub struct Contact {
|
||||||
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
||||||
pub id: Option<uuid::Uuid>,
|
pub id: Option<uuid::Uuid>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub firstname: Option<String>,
|
pub firstname: Option<String>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub lastname: Option<String>,
|
pub lastname: Option<String>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub nickname: Option<String>,
|
pub nickname: Option<String>,
|
||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
|
|||||||
+41
-3
@@ -2,14 +2,52 @@
|
|||||||
/// extract it into some strings
|
/// extract it into some strings
|
||||||
pub fn delimitize(var: &crate::envy::EnvVar) -> Result<Vec<String>, std::io::Error> {
|
pub fn delimitize(var: &crate::envy::EnvVar) -> Result<Vec<String>, std::io::Error> {
|
||||||
if var.has_delimiter {
|
if var.has_delimiter {
|
||||||
Ok(var
|
let values: Vec<String> = match var
|
||||||
.value
|
.value
|
||||||
.split(var.delimiter)
|
.split(var.delimiter)
|
||||||
.map(|c| c.parse::<String>().unwrap())
|
.map(|c| c.parse::<String>())
|
||||||
.collect())
|
.collect()
|
||||||
|
{
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(std::io::Error::other(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(values)
|
||||||
} else {
|
} else {
|
||||||
Err(std::io::Error::other(
|
Err(std::io::Error::other(
|
||||||
"Environment variable does not have a delimiter",
|
"Environment variable does not have a delimiter",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delimitize() {
|
||||||
|
let envvar = crate::envy::EnvVar {
|
||||||
|
key: "OCEANS".to_string(),
|
||||||
|
value: "Atlantic|Pacific|Indian|Arctic".to_string(),
|
||||||
|
has_delimiter: true,
|
||||||
|
delimiter: '|',
|
||||||
|
};
|
||||||
|
let all_values = vec![
|
||||||
|
"Atlantic".to_string(),
|
||||||
|
"Pacific".to_string(),
|
||||||
|
"Indian".to_string(),
|
||||||
|
"Arctic".to_string(),
|
||||||
|
];
|
||||||
|
|
||||||
|
match delimitize(&envvar) {
|
||||||
|
Ok(values) => {
|
||||||
|
assert_eq!(values, all_values, "Failure in delimitizing EnvVar values");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert!(false, "Error delimitizing: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+73
-19
@@ -78,17 +78,57 @@ pub struct CreateTokenResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_token(
|
pub fn create_token(
|
||||||
key: &String,
|
key: &str,
|
||||||
token_resource: &TokenResource,
|
token_resource: TokenResource,
|
||||||
duration: time::Duration,
|
duration: time::Duration,
|
||||||
) -> Result<CreateTokenResult, josekit::JoseError> {
|
) -> Result<CreateTokenResult, josekit::JoseError> {
|
||||||
let mut header = josekit::jws::JwsHeader::new();
|
let mut header = josekit::jws::JwsHeader::new();
|
||||||
header.set_token_type(TOKEN_TYPE);
|
header.set_token_type(TOKEN_TYPE);
|
||||||
|
|
||||||
|
match init_payload(token_resource, duration) {
|
||||||
|
Ok((payload, issued, expire)) => {
|
||||||
|
let signer = match josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256
|
||||||
|
.signer_from_bytes(key.as_bytes())
|
||||||
|
{
|
||||||
|
Ok(signer) => signer,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let access_token = match josekit::jwt::encode_with_signer(&payload, &header, &signer) {
|
||||||
|
Ok(access_token) => access_token,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(CreateTokenResult {
|
||||||
|
access_token,
|
||||||
|
issued: issued.unix_timestamp(),
|
||||||
|
expires_in: expire.unix_timestamp(),
|
||||||
|
token_issued: issued,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_payload(
|
||||||
|
token_resource: TokenResource,
|
||||||
|
duration: time::Duration,
|
||||||
|
) -> Result<
|
||||||
|
(
|
||||||
|
josekit::jwt::JwtPayload,
|
||||||
|
time::OffsetDateTime,
|
||||||
|
time::OffsetDateTime,
|
||||||
|
),
|
||||||
|
josekit::JoseError,
|
||||||
|
> {
|
||||||
let mut payload = josekit::jwt::JwtPayload::new();
|
let mut payload = josekit::jwt::JwtPayload::new();
|
||||||
payload.set_subject(&token_resource.message);
|
payload.set_subject(token_resource.message);
|
||||||
payload.set_issuer(&token_resource.issuer);
|
payload.set_issuer(token_resource.issuer);
|
||||||
payload.set_audience(token_resource.audiences.clone());
|
payload.set_audience(token_resource.audiences);
|
||||||
|
|
||||||
if !token_resource.user_id.is_nil() {
|
if !token_resource.user_id.is_nil() {
|
||||||
match payload.set_claim("user_id", Some(serde_json::json!(token_resource.user_id))) {
|
match payload.set_claim("user_id", Some(serde_json::json!(token_resource.user_id))) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
@@ -97,24 +137,38 @@ pub fn create_token(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match init_payload_issued(&mut payload, duration) {
|
||||||
|
Ok((issued, expire)) => Ok((payload, issued, expire)),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_payload_issued(
|
||||||
|
payload: &mut josekit::jwt::JwtPayload,
|
||||||
|
duration: time::Duration,
|
||||||
|
) -> Result<(time::OffsetDateTime, time::OffsetDateTime), josekit::JoseError> {
|
||||||
match get_issued() {
|
match get_issued() {
|
||||||
Ok(issued) => {
|
Ok(issued) => {
|
||||||
let expire = issued + duration;
|
let expire = issued + duration;
|
||||||
payload.set_issued_at(&util::time_to_std_time(&issued).unwrap());
|
let issued_at = match util::time_to_std_time(&issued) {
|
||||||
payload.set_expires_at(&util::time_to_std_time(&expire).unwrap());
|
Ok(issued_at) => issued_at,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(josekit::JoseError::InvalidClaim(err.into()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let expires_at = match util::time_to_std_time(&expire) {
|
||||||
|
Ok(expires_at) => expires_at,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(josekit::JoseError::InvalidClaim(err.into()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let signer = josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256
|
payload.set_issued_at(&issued_at);
|
||||||
.signer_from_bytes(key.as_bytes())
|
payload.set_expires_at(&expires_at);
|
||||||
.unwrap();
|
Ok((issued, expire))
|
||||||
|
|
||||||
Ok(CreateTokenResult {
|
|
||||||
access_token: josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
|
|
||||||
issued: issued.unix_timestamp(),
|
|
||||||
expires_in: expire.unix_timestamp(),
|
|
||||||
token_issued: issued,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
|
Err(err) => Err(josekit::JoseError::InvalidClaim(err.into())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +192,7 @@ mod tests {
|
|||||||
let token_duration = time::Duration::minutes(30);
|
let token_duration = time::Duration::minutes(30);
|
||||||
let key = String::from(TEST_KEY);
|
let key = String::from(TEST_KEY);
|
||||||
|
|
||||||
match super::create_token(&key, &token_resource, token_duration) {
|
match super::create_token(&key, token_resource, token_duration) {
|
||||||
Ok(cst) => match time::OffsetDateTime::from_unix_timestamp(cst.issued) {
|
Ok(cst) => match time::OffsetDateTime::from_unix_timestamp(cst.issued) {
|
||||||
Ok(d_result) => {
|
Ok(d_result) => {
|
||||||
let they_match = {
|
let they_match = {
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ pub struct User {
|
|||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
// Firstname is a pointer
|
|
||||||
pub firstname: String,
|
pub firstname: String,
|
||||||
// Lastname is a pointer
|
|
||||||
pub lastname: String,
|
pub lastname: String,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub created: Option<time::OffsetDateTime>,
|
pub created: Option<time::OffsetDateTime>,
|
||||||
@@ -27,7 +25,6 @@ pub struct ServiceUser {
|
|||||||
pub passphrase: String,
|
pub passphrase: String,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub created: Option<time::OffsetDateTime>,
|
pub created: Option<time::OffsetDateTime>,
|
||||||
// When serializing to json, if empty do not populate
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub last_login: Option<time::OffsetDateTime>,
|
pub last_login: Option<time::OffsetDateTime>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
@@ -81,7 +78,6 @@ pub struct UserProfile {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
|
||||||
pub struct Salt {
|
pub struct Salt {
|
||||||
// #[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub salt: String,
|
pub salt: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user