Compare commits

..
Author SHA1 Message Date
phoenix e5ab4aa426 Adding sqlx::FromRow trait
textsender_models PR / Check (pull_request) Has been cancelled
textsender_models PR / Rustfmt (pull_request) Has been cancelled
textsender_models PR / Clippy (pull_request) Has been cancelled
Release Tagging / release (pull_request) Successful in 40s
2026-06-18 14:26:37 -04:00
phoenix ad632fca16 bump: textsender_models
textsender_models PR / Rustfmt (pull_request) Successful in 40s
textsender_models PR / Check (pull_request) Successful in 44s
Release Tagging / release (pull_request) Successful in 28s
textsender_models PR / Clippy (pull_request) Successful in 58s
2026-06-17 16:41:53 -04:00
phoenix 86febdab0d Fix field access issue 2026-06-17 16:41:46 -04:00
phoenix 7534e8652f Updating workflows
textsender_models PR / Rustfmt (pull_request) Successful in 36s
Release Tagging / release (pull_request) Successful in 33s
textsender_models PR / Clippy (pull_request) Successful in 1m12s
textsender_models PR / Check (pull_request) Successful in 1m39s
2026-06-17 16:17:38 -04:00
phoenix c4b2c19f77 Some refactoring
textsender_models PR / Rustfmt (pull_request) Successful in 35s
Release Tagging / release (pull_request) Successful in 38s
textsender_models PR / Check (pull_request) Successful in 1m34s
textsender_models PR / Clippy (pull_request) Successful in 1m33s
2026-06-17 16:15:35 -04:00
phoenix 890d03bdf3 Adding to macros and refactoring 2026-06-17 16:12:07 -04:00
6 changed files with 155 additions and 1540 deletions
Generated
+140 -1445
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "textsender_models" name = "textsender_models"
version = "0.4.10" version = "0.4.1"
edition = "2024" edition = "2024"
rust-version = "1.96" rust-version = "1.96"
description = "Models used for the textsender project" description = "Models used for the textsender project"
@@ -9,7 +9,6 @@ description = "Models used for the textsender project"
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.49", features = ["formatting", "macros", "parsing", "serde"] }
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
uuid = { version = "1.23.3", features = ["v4", "serde"] } uuid = { version = "1.23.3", 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" }
-23
View File
@@ -19,26 +19,3 @@ impl TwilioConfig {
println!("Number: {:?}", self.phone_number); println!("Number: {:?}", self.phone_number);
} }
} }
// TODO: Remove the async at a later point
pub async fn load_config() -> Result<TwilioConfig, std::io::Error> {
let auth_sid_var = crate::envy::environment::get_env("TWILIO_AUTH_SID").await;
let service_sid_var = crate::envy::environment::get_env("TWILIO_SERVICE_SID").await;
let auth_token_var = crate::envy::environment::get_env("TWILIO_AUTH_TOKEN").await;
let phone_number_var = crate::envy::environment::get_env("TWILIO_PHONE_NUMBER").await;
if auth_sid_var.value.is_empty()
|| service_sid_var.value.is_empty()
|| auth_token_var.value.is_empty()
|| phone_number_var.value.is_empty()
{
Err(std::io::Error::other("Config not set"))
} else {
Ok(TwilioConfig {
service_sid: service_sid_var.value,
auth_token: auth_token_var.value,
account_sid: auth_sid_var.value,
phone_number: phone_number_var.value,
})
}
}
-2
View File
@@ -1,5 +1,3 @@
// TODO: Functions does not need to be async
pub async fn get_db_url() -> crate::envy::EnvVar { pub async fn get_db_url() -> crate::envy::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
let key = crate::envy::keys::DB_URL; let key = crate::envy::keys::DB_URL;
+2 -5
View File
@@ -1,6 +1,4 @@
/// Message status - Instant
pub const MESSAGE_EVENT_RESPONSE_STATUS_INSTANT: &str = "INSTANT"; pub const MESSAGE_EVENT_RESPONSE_STATUS_INSTANT: &str = "INSTANT";
/// Message status - Scheduled
pub const MESSAGE_EVENT_RESPONSE_STATUS_SCHEDULED: &str = "SCHEDULED"; pub const MESSAGE_EVENT_RESPONSE_STATUS_SCHEDULED: &str = "SCHEDULED";
#[derive( #[derive(
@@ -8,10 +6,9 @@ pub const MESSAGE_EVENT_RESPONSE_STATUS_SCHEDULED: &str = "SCHEDULED";
)] )]
pub struct MessageEventResponse { pub struct MessageEventResponse {
pub id: uuid::Uuid, pub id: uuid::Uuid,
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")] pub scheduled_message_event_id: uuid::Uuid,
pub scheduled_message_event_id: Option<uuid::Uuid>,
/// Stores a json response of the sent message /// Stores a json response of the sent message
pub response: serde_json::Value, pub response: String,
pub user_id: uuid::Uuid, pub user_id: uuid::Uuid,
pub contact_id: uuid::Uuid, pub contact_id: uuid::Uuid,
pub message_id: uuid::Uuid, pub message_id: uuid::Uuid,
+12 -63
View File
@@ -54,7 +54,7 @@ mod util {
pub fn time_to_std_time( pub fn time_to_std_time(
provided_time: &time::OffsetDateTime, provided_time: &time::OffsetDateTime,
) -> Result<std::time::SystemTime, std::time::SystemTimeError> { ) -> Result<std::time::SystemTime, std::time::SystemTimeError> {
let converted: std::time::SystemTime = (*provided_time).into(); let converted = std::time::SystemTime::from(*provided_time);
Ok(converted) Ok(converted)
} }
} }
@@ -70,25 +70,21 @@ pub struct TokenResource {
/// Token type /// Token type
pub const TOKEN_TYPE: &str = "JWT"; pub const TOKEN_TYPE: &str = "JWT";
pub struct CreateTokenResult {
pub access_token: String,
pub issued: i64,
pub expires_in: i64,
pub token_issued: time::OffsetDateTime,
}
pub fn create_token( pub fn create_token(
key: &String, key: &String,
token_resource: &TokenResource, token_resource: &TokenResource,
duration: time::Duration, duration: time::Duration,
) -> Result<CreateTokenResult, josekit::JoseError> { ) -> Result<(String, i64), 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);
let mut payload = josekit::jwt::JwtPayload::new(); let mut payload = josekit::jwt::JwtPayload::new();
payload.set_subject(&token_resource.message); let message = &token_resource.message;
payload.set_issuer(&token_resource.issuer); let issuer = &token_resource.issuer;
payload.set_audience(token_resource.audiences.clone()); let audiences: &Vec<String> = &token_resource.audiences;
payload.set_subject(message);
payload.set_issuer(issuer);
payload.set_audience(audiences.clone());
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(_) => {}
@@ -106,58 +102,11 @@ pub fn create_token(
let signer = josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256 let signer = josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256
.signer_from_bytes(key.as_bytes()) .signer_from_bytes(key.as_bytes())
.unwrap(); .unwrap();
Ok((
Ok(CreateTokenResult { josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
access_token: josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(), (expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
issued: issued.unix_timestamp(), ))
expires_in: expire.unix_timestamp(),
token_issued: issued,
})
} }
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())), Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
} }
} }
#[cfg(test)]
mod tests {
const TEST_MESSAGE: &str = "Testing for textsender";
const TEST_ISSUER: &str = "textsender-test";
const TEST_AUDIENCE: &str = "area-test";
const TEST_USER_ID: uuid::Uuid = uuid::uuid!("9ab1c75f-d184-4913-ae99-544b4dcfcb41");
const TEST_KEY: &str = "8342nhf7ycrt4983q7ryfc93w478ryfc3w9487ryfc342w98i7cy";
#[test]
fn test_create_token() {
let token_resource = super::TokenResource {
message: String::from(TEST_MESSAGE),
issuer: String::from(TEST_ISSUER),
audiences: vec![String::from(TEST_AUDIENCE)],
user_id: TEST_USER_ID,
};
let token_duration = time::Duration::minutes(30);
let key = String::from(TEST_KEY);
match super::create_token(&key, &token_resource, token_duration) {
Ok(cst) => match time::OffsetDateTime::from_unix_timestamp(cst.issued) {
Ok(d_result) => {
let they_match = {
d_result.year() == cst.token_issued.year()
&& d_result.month() == cst.token_issued.month()
&& d_result.day() == cst.token_issued.day()
&& d_result.hour() == cst.token_issued.hour()
&& d_result.minute() == cst.token_issued.minute()
&& d_result.second() == cst.token_issued.second()
};
assert!(they_match, "Issued times do not match");
}
Err(err) => {
assert!(false, "Error: {err:?}");
}
},
Err(err) => {
assert!(false, "Error: {err:?}");
}
}
}
}