Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ea92ae64e
|
||
|
|
0e8e0db284
|
||
|
|
720f3d8f75
|
||
|
|
7e5bc016b1
|
||
|
|
384dd41690
|
||
|
|
f246676203
|
||
|
|
47e6c85fc7
|
||
|
|
82370ad63a
|
Generated
+1483
-2
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "textsender_models"
|
name = "textsender_models"
|
||||||
version = "0.4.1"
|
version = "0.4.10"
|
||||||
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,6 +9,7 @@ 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" }
|
||||||
|
|||||||
@@ -19,3 +19,26 @@ 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// 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;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
/// 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(
|
||||||
@@ -6,9 +8,10 @@ pub const MESSAGE_EVENT_RESPONSE_STATUS_SCHEDULED: &str = "SCHEDULED";
|
|||||||
)]
|
)]
|
||||||
pub struct MessageEventResponse {
|
pub struct MessageEventResponse {
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
pub scheduled_message_event_id: uuid::Uuid,
|
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
||||||
|
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: String,
|
pub response: serde_json::Value,
|
||||||
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,
|
||||||
|
|||||||
+13
-5
@@ -70,11 +70,17 @@ 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 fn create_token(
|
pub fn create_token(
|
||||||
key: &String,
|
key: &String,
|
||||||
token_resource: &TokenResource,
|
token_resource: &TokenResource,
|
||||||
duration: time::Duration,
|
duration: time::Duration,
|
||||||
) -> Result<(String, i64), 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);
|
||||||
|
|
||||||
@@ -102,10 +108,12 @@ 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((
|
|
||||||
josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
|
Ok(CreateTokenResult {
|
||||||
(expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
|
access_token: josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
|
||||||
))
|
issued: (expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
|
||||||
|
expires_in: (issued - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
|
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user