Compare commits

..
Author SHA1 Message Date
phoenix 897ac80b96 Tweaked UserProfile
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
Go CI / Test and Lint (push) Failing after 17s
2026-05-27 22:44:12 -04:00
phoenix 509b9d58a5 Merge branch 'main' of git.kundeng.us:phoenix/textsender-models into user_profile
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Successful in 7s
Go CI / Test and Lint (push) Successful in 17s
2026-05-27 22:38:20 -04:00
phoenix e459183747 go fmt
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Successful in 6s
Go CI / Test and Lint (push) Successful in 16s
2026-05-25 22:46:26 -04:00
phoenix 19d074d3d7 Added todo
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Successful in 6s
Go CI / Test and Lint (push) Successful in 17s
2026-05-25 22:46:00 -04:00
phoenix 209e1428d8 Syntax fix
Go CI / Test and Lint (push) Successful in 6s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Successful in 6s
2026-05-25 22:43:20 -04:00
phoenix 97591d99b5 Updated test
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
2026-05-25 22:42:40 -04:00
phoenix 587f9a05af -m: Test fix
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
2026-05-25 22:41:49 -04:00
phoenix b130f6e069 Test fix
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
2026-05-25 22:39:37 -04:00
phoenix e74dd82211 Code refactoring
Go Release / build-and-release (pull_request) Successful in 7s
Go CI / Test and Lint (pull_request) Failing after 6s
Go CI / Test and Lint (push) Failing after 17s
2026-05-25 22:36:59 -04:00
phoenix 8cfccc2722 Test fix
Go CI / Test and Lint (push) Successful in 6s
Go CI / Test and Lint (pull_request) Successful in 17s
Go Release / build-and-release (pull_request) Successful in 6s
2026-05-25 22:31:18 -04:00
phoenix 801a314421 Test fix
Go CI / Test and Lint (push) Failing after 16s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
2026-05-25 22:30:21 -04:00
phoenix 9565259dc1 Test fix
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 5s
Go CI / Test and Lint (pull_request) Failing after 7s
2026-05-25 22:26:38 -04:00
phoenix f05a513926 Created test file
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 5s
Go CI / Test and Lint (pull_request) Failing after 6s
2026-05-25 22:24:06 -04:00
phoenix 39ecf052a0 Added assert
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (push) Successful in 17s
Go CI / Test and Lint (pull_request) Successful in 16s
2026-05-25 22:22:18 -04:00
phoenix 2b5cb3a093 Test fixes
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 6s
Go CI / Test and Lint (push) Failing after 12s
2026-05-25 22:21:14 -04:00
phoenix c2cde15189 Added test
Go CI / Test and Lint (push) Failing after 5s
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 5s
2026-05-25 22:18:02 -04:00
phoenix b8e8621e0d Build fix
Go CI / Test and Lint (push) Successful in 5s
Go Release / build-and-release (pull_request) Successful in 5s
Go CI / Test and Lint (pull_request) Successful in 5s
2026-05-25 22:12:58 -04:00
phoenix 0bf24d929c Build fix
Go CI / Test and Lint (push) Failing after 6s
Go Release / build-and-release (pull_request) Successful in 7s
Go CI / Test and Lint (pull_request) Failing after 5s
2026-05-25 22:12:07 -04:00
phoenix dcbc2609c4 -m: Added UserProfile
Go Release / build-and-release (pull_request) Successful in 6s
Go CI / Test and Lint (pull_request) Failing after 5s
Go CI / Test and Lint (push) Failing after 50s
2026-05-25 22:10:14 -04:00
39 changed files with 363 additions and 2800 deletions
-46
View File
@@ -1,46 +0,0 @@
name: schedtxt_models PR
on:
pull_request:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: cargo check
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: cargo clippy -- -D warnings
-68
View File
@@ -1,68 +0,0 @@
name: Rust Build
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: cargo check
test:
name: Test Suite
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: cargo test
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: cargo clippy -- -D warnings
build:
name: build
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: cargo build
@@ -1,4 +1,4 @@
name: Release Tagging
name: Go Release
on:
push:
@@ -9,28 +9,27 @@ on:
- main
jobs:
release:
build-and-release:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Important for git describe --tags
uses: actions/checkout@v5
- name: Install Rust
uses: actions-rs/toolchain@v1
- name: Set up Go
uses: actions/setup-go@v6
with:
toolchain: 1.97
components: cargo
go-version: '1.26.2'
- name: Extract Version from Cargo.toml
- name: Create version
id: version
run: |
VERSION=$(grep '^version = "' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
echo "Creating version"
VERSION="0.2.2"
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
BRANCH_REF="${{ gitea.ref }}"
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-111"
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-556"
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
+27
View File
@@ -0,0 +1,27 @@
name: Go CI
on: [push, pull_request] # Triggers on push or pull request events
jobs:
test:
name: Test and Lint
runs-on: ubuntu-24.04
steps:
- name: Check out repository code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26.2'
- name: Configure Git for SSH
run: |
git config --global url."git@${{ secrets.GIT_HOST_ROOT }}:".insteadOf "https://${{ secrets.GIT_HOST_ROOT }}/"
go env -w GOPRIVATE=${{ secrets.GIT_HOST_ROOT }}/phoenix/*
- name: Download dependencies
run: |
go mod download
- name: Run tests
run: go test -v ./... # Runs all tests in the project
+1 -1
View File
@@ -1 +1 @@
target/
/vendor/
Generated
-1865
View File
File diff suppressed because it is too large Load Diff
-30
View File
@@ -1,30 +0,0 @@
[package]
name = "schedtxt_models"
version = "0.5.3"
edition = "2024"
rust-version = "1.97"
license = "MIT"
description = "Models used for the schedtxt project"
[dependencies]
serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.150" }
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
uuid = { version = "1.23.5", features = ["v4", "serde"] }
dotenvy = { version = "0.15.7" }
const_format = { version = "0.2.36" }
josekit = { version = "0.10.3" }
utoipa = { version = "5.5.0", features = ["uuid", "time"] }
[features]
default = ["full"]
full = ["user", "message", "contact", "config", "envy", "token"]
user = []
message = []
contact = []
config = []
envy = []
token = []
[dev-dependencies]
-22
View File
@@ -1,22 +0,0 @@
Copyright (c) 2026 Kun Deng.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
+10 -2
View File
@@ -1,2 +1,10 @@
# schedtxt_models
Models library for the `schedtxt` project.
# textsender-models
A library containing functions, structs, types, and other code for the textsender
project
### Building project
```SHELL
go mod tidy
go mod vendor
```
+15
View File
@@ -0,0 +1,15 @@
module git.kundeng.us/phoenix/textsender-models
go 1.26.2
require (
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.11.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+14
View File
@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-43
View File
@@ -1,43 +0,0 @@
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct TwilioConfig {
#[serde(alias = "auth_id")]
pub account_sid: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub service_sid: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub auth_token: String,
#[serde(skip_serializing_if = "String::is_empty")]
pub phone_number: String,
}
impl TwilioConfig {
pub fn print_config(&self) {
println!("Twilio config");
println!("Account SID: {:?}", self.account_sid);
println!("Service SID: {:?}", self.service_sid);
println!("Auth Token: {:?}", self.auth_token);
println!("Number: {:?}", self.phone_number);
}
}
pub fn load_config() -> Result<TwilioConfig, std::io::Error> {
let auth_sid_var = crate::envy::environment::get_env("TWILIO_AUTH_SID");
let service_sid_var = crate::envy::environment::get_env("TWILIO_SERVICE_SID");
let auth_token_var = crate::envy::environment::get_env("TWILIO_AUTH_TOKEN");
let phone_number_var = crate::envy::environment::get_env("TWILIO_PHONE_NUMBER");
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
View File
@@ -1 +0,0 @@
pub mod auxiliary;
-16
View File
@@ -1,16 +0,0 @@
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct Contact {
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
pub id: Option<uuid::Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
pub firstname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub lastname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub nickname: Option<String>,
pub phone_number: String,
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
pub user_id: Option<uuid::Uuid>,
}
-106
View File
@@ -1,106 +0,0 @@
pub fn get_db_url() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::DB_URL;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_secret_main_key() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::SECRET_MAIN_KEY;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_service_passphrase() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::SERVICE_PASSPHRASE;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_secret_key() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::SECRET_KEY;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_root_directory() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::ROOT_DIRECTORY;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_app_base_api_url() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::SCHEDTXT_BASE_API_URL;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_app_auth_base_api_url() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::SCHEDTXT_AUTH_BASE_API_URL;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_app_env() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::APP_ENV;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_backend_port() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::BACKEND_PORT;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_frontend_url() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::FRONTEND_URL;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_rust_log() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::RUST_LOG;
let value = std::env::var(key).expect(key);
crate::envy::init_envvar(key, &value)
}
pub fn get_allowed_origins() -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let key = crate::envy::keys::ALLOWED_ORIGINS;
let value = std::env::var(key).expect(key);
let mut envvar = crate::envy::init_envvar(key, &value);
crate::envy::init_delimiter(&mut envvar, ',');
envvar
}
/// Get environment not specified in the library
pub fn get_env(environment: &str) -> crate::envy::EnvVar {
dotenvy::dotenv().ok();
let my_error = format!("{environment} {}", crate::envy::keys::error::GENERAL_ERROR);
let value = std::env::var(environment).expect(&my_error);
crate::envy::init_envvar(environment, &value)
}
-53
View File
@@ -1,53 +0,0 @@
/// Environment key for Database management
pub const DB_URL: &str = "DATABASE_URL";
/// Environment key for secret main key
/// Used for the schedtxt app
pub const SECRET_MAIN_KEY: &str = "SECRET_MAIN_KEY";
/// Environment key for service logins
pub const SERVICE_PASSPHRASE: &str = "SERVICE_PASSPHRASE";
/// Environment key for secret key
/// Generic use of secret key that could be found in various apps
pub const SECRET_KEY: &str = "SECRET_KEY";
/// Environment key for root directory for the textsender app
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY";
/// Environment key for schedtxt api url
pub const SCHEDTXT_BASE_API_URL: &str = "SCHEDTXT_BASE_API_URL";
/// Environment key for textsender auth api url
pub const SCHEDTXT_AUTH_BASE_API_URL: &str = "SCHEDTXT_AUTH_BASE_API_URL";
/// Environment key for App status
pub const APP_ENV: &str = "APP_ENV";
/// Environment key for backend port. Used for both auth and core functionality
pub const BACKEND_PORT: &str = "BACKEND_PORT";
/// Environment key for frontend url
pub const FRONTEND_URL: &str = "FRONTEND_URL";
/// Environment key for application logging
pub const RUST_LOG: &str = "RUST_LOG";
/// Environment key for allowed origins for CORS support
pub const ALLOWED_ORIGINS: &str = "ALLOWED_ORIGINS";
pub mod error {
use const_format::concatcp;
pub const GENERAL_ERROR: &str = "must not be set in enviornment file";
pub const DB_URL: &str = concatcp!(super::DB_URL, " ", GENERAL_ERROR);
pub const SECRET_MAIN_KEY: &str = concatcp!(super::SECRET_MAIN_KEY, " ", GENERAL_ERROR);
pub const SERVICE_LOGIN: &str = concatcp!(super::SERVICE_PASSPHRASE, " ", GENERAL_ERROR);
pub const SECRET_KEY: &str = concatcp!(super::SECRET_KEY, " ", GENERAL_ERROR);
pub const ROOT_DIRECTORY: &str = concatcp!(super::ROOT_DIRECTORY, " ", GENERAL_ERROR);
pub const SCHEDTXT_BASE_API_URL: &str =
concatcp!(super::SCHEDTXT_BASE_API_URL, " ", GENERAL_ERROR);
pub const SCHEDTXT_AUTH_BASE_API_URL: &str =
concatcp!(super::SCHEDTXT_AUTH_BASE_API_URL, " ", GENERAL_ERROR);
pub const APP_ENV: &str = concatcp!(super::APP_ENV, " ", GENERAL_ERROR);
pub const BACKEND_PORT: &str = concatcp!(super::BACKEND_PORT, " ", GENERAL_ERROR);
pub const FRONTEND_URL: &str = concatcp!(super::FRONTEND_URL, " ", GENERAL_ERROR);
pub const RUST_LOG: &str = concatcp!(super::RUST_LOG, " ", GENERAL_ERROR);
pub const ALLOWED_ORIGINS: &str = concatcp!(super::ALLOWED_ORIGINS, " ", GENERAL_ERROR);
}
-57
View File
@@ -1,57 +0,0 @@
pub mod environment;
pub mod keys;
pub mod utility;
#[derive(Debug, Default, Clone)]
pub struct EnvVar {
pub key: String,
pub value: String,
pub has_delimiter: bool,
pub delimiter: char,
}
pub fn init_envvar(key: &str, value: &str) -> EnvVar {
EnvVar {
key: key.to_string(),
value: value.to_string(),
has_delimiter: false,
..Default::default()
}
}
pub fn init_delimiter(envvar: &mut EnvVar, delimiter: char) {
let amount_of_delimiters_found: i32 = {
let mut count = 0;
for v in envvar.value.chars() {
if v == delimiter {
count += 1;
}
}
count
};
let has_delimiter = amount_of_delimiters_found >= 1;
if has_delimiter {
envvar.has_delimiter = has_delimiter;
envvar.delimiter = delimiter;
} else {
envvar.has_delimiter = has_delimiter;
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_init_delimiter() {
let delimiter: char = ',';
let value = format!("red,green,white,black");
let mut env_var = super::EnvVar {
key: String::from("COLORS"),
value: value.clone(),
..Default::default()
};
super::init_delimiter(&mut env_var, delimiter);
assert_eq!(value, env_var.value, "Colors do not match");
}
}
-53
View File
@@ -1,53 +0,0 @@
/// Take the Environment variable and delimitize it. If the value has a delimiter,
/// extract it into some strings
pub fn delimitize(var: &crate::envy::EnvVar) -> Result<Vec<String>, std::io::Error> {
if var.has_delimiter {
let values: Vec<String> = match var
.value
.split(var.delimiter)
.map(|c| c.parse::<String>())
.collect()
{
Ok(v) => v,
Err(err) => {
return Err(std::io::Error::other(err));
}
};
Ok(values)
} else {
Err(std::io::Error::other(
"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:?}");
}
}
}
}
-15
View File
@@ -1,15 +0,0 @@
pub mod config;
pub mod contact;
pub mod envy;
pub mod message;
pub mod token;
pub mod user;
pub mod init {
pub fn is_uuid_nil(uuid: &Option<uuid::Uuid>) -> bool {
match uuid {
Some(id) => id.is_nil(),
None => true,
}
}
}
-21
View File
@@ -1,21 +0,0 @@
/// Message status - Instant
pub const MESSAGE_EVENT_RESPONSE_STATUS_INSTANT: &str = "INSTANT";
/// Message status - Scheduled
pub const MESSAGE_EVENT_RESPONSE_STATUS_SCHEDULED: &str = "SCHEDULED";
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct MessageEventResponse {
pub 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
pub response: serde_json::Value,
pub user_id: uuid::Uuid,
pub contact_id: uuid::Uuid,
pub message_id: uuid::Uuid,
pub status: String,
#[serde(with = "time::serde::rfc3339::option")]
pub sent: Option<time::OffsetDateTime>,
}
-13
View File
@@ -1,13 +0,0 @@
pub mod event;
pub mod scheduling;
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct Message {
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
pub id: Option<uuid::Uuid>,
pub content: String,
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
pub user_id: Option<uuid::Uuid>,
}
-29
View File
@@ -1,29 +0,0 @@
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct ScheduledMessageEvent {
pub id: uuid::Uuid,
pub contact_id: uuid::Uuid,
pub message_id: uuid::Uuid,
pub scheduled_message_id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct ScheduledMessage {
pub id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub scheduled: Option<time::OffsetDateTime>,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
pub status: String,
pub user_id: uuid::Uuid,
}
pub const READY: &str = "READY";
pub const PENDING: &str = "PENDING";
pub const PROCESSING: &str = "PROCESSING";
pub const DONE: &str = "DONE";
-217
View File
@@ -1,217 +0,0 @@
use serde::Deserialize;
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
pub struct Claims {
pub user_id: uuid::Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
#[serde(alias = "iss")]
pub issued: String,
#[serde(alias = "exp")]
#[serde(deserialize_with = "deserialize_i64_from_f64")]
pub expired: i64,
#[serde(alias = "iat")]
#[serde(deserialize_with = "deserialize_i64_from_f64")]
pub issued_at: i64,
}
fn deserialize_i64_from_f64<'de, D>(deserializer: D) -> Result<i64, D::Error>
where
D: serde::Deserializer<'de>,
{
let val = f64::deserialize(deserializer)?;
// Handle NaN and infinity cases
if val.is_nan() || val.is_infinite() {
return Err(serde::de::Error::custom("invalid float value"));
}
// Round to nearest integer and convert
let rounded = val.round();
// Check if the rounded value can fit in i64
if rounded < (i64::MIN as f64) || rounded > (i64::MAX as f64) {
Err(serde::de::Error::custom("float out of i64 range"))
} else {
Ok(rounded as i64)
}
}
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct LoginResult {
pub user_id: uuid::Uuid,
pub access_token: String,
pub token_type: String,
pub expires_in: i64,
pub issued_at: i64,
}
/// Alias for LoginResult
pub type Login = LoginResult;
pub fn get_issued() -> time::Result<time::OffsetDateTime> {
Ok(time::OffsetDateTime::now_utc())
}
mod util {
pub fn time_to_std_time(
provided_time: &time::OffsetDateTime,
) -> Result<std::time::SystemTime, std::time::SystemTimeError> {
let converted: std::time::SystemTime = (*provided_time).into();
Ok(converted)
}
}
#[derive(Debug, utoipa::ToSchema)]
pub struct TokenResource {
pub message: String,
pub issuer: String,
pub audiences: Vec<String>,
pub user_id: uuid::Uuid,
}
/// Token type
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(
key: &str,
token_resource: TokenResource,
duration: time::Duration,
) -> Result<CreateTokenResult, josekit::JoseError> {
let mut header = josekit::jws::JwsHeader::new();
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();
payload.set_subject(token_resource.message);
payload.set_issuer(token_resource.issuer);
payload.set_audience(token_resource.audiences);
if !token_resource.user_id.is_nil() {
match payload.set_claim("user_id", Some(serde_json::json!(token_resource.user_id))) {
Ok(_) => {}
Err(err) => {
return Err(err);
}
}
}
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() {
Ok(issued) => {
let expire = issued + duration;
let issued_at = match util::time_to_std_time(&issued) {
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()));
}
};
payload.set_issued_at(&issued_at);
payload.set_expires_at(&expires_at);
Ok((issued, expire))
}
Err(err) => Err(josekit::JoseError::InvalidClaim(err.into())),
}
}
#[cfg(test)]
mod tests {
const TEST_MESSAGE: &str = "Testing for schedtxt";
const TEST_ISSUER: &str = "schedtxt-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:?}");
}
}
}
}
-130
View File
@@ -1,130 +0,0 @@
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct User {
pub id: uuid::Uuid,
pub phone_number: String,
pub username: String,
pub password: String,
pub firstname: String,
pub lastname: String,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
#[serde(with = "time::serde::rfc3339::option")]
pub last_login: Option<time::OffsetDateTime>,
#[serde(skip)]
pub salt_id: uuid::Uuid,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct ServiceUser {
pub id: uuid::Uuid,
pub username: String,
pub passphrase: String,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
#[serde(with = "time::serde::rfc3339::option")]
pub last_login: Option<time::OffsetDateTime>,
#[serde(skip)]
pub salt_id: uuid::Uuid,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct Organization {
pub id: uuid::Uuid,
pub name: String,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct UserLoginHistory {
pub id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub login_time: Option<time::OffsetDateTime>,
pub user_id: uuid::Uuid,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct ServiceUserLoginHistory {
pub id: uuid::Uuid,
#[serde(with = "time::serde::rfc3339::option")]
pub login_time: Option<time::OffsetDateTime>,
pub service_user_id: uuid::Uuid,
}
#[derive(
Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow, utoipa::ToSchema,
)]
pub struct UserProfile {
pub user_id: uuid::Uuid,
pub phone_number: String,
pub username: String,
pub firstname: String,
pub lastname: String,
#[serde(with = "time::serde::rfc3339::option")]
pub created: Option<time::OffsetDateTime>,
#[serde(with = "time::serde::rfc3339::option")]
pub last_login: Option<time::OffsetDateTime>,
}
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
pub struct Salt {
pub id: uuid::Uuid,
#[serde(skip_serializing_if = "String::is_empty")]
pub salt: String,
}
impl Salt {
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
if output_pretty {
serde_json::to_string_pretty(&self)
} else {
serde_json::to_string(&self)
}
}
}
pub fn init_user_profile(usr: &User) -> UserProfile {
UserProfile {
user_id: usr.id,
phone_number: usr.phone_number.clone(),
username: usr.username.clone(),
firstname: usr.firstname.clone(),
lastname: usr.lastname.clone(),
created: usr.created,
last_login: usr.last_login,
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_init_user_profile() {
let usr = super::User {
id: uuid::Uuid::new_v4(),
phone_number: String::from("+12308438462"),
username: String::from("Cowboy99"),
password: String::from("238n7cyr2q89d3xhe2"),
firstname: String::from("BillyBob"),
lastname: String::from("Jones"),
created: Some(time::OffsetDateTime::now_utc()),
last_login: Some(time::OffsetDateTime::now_utc()),
..Default::default()
};
let profile = super::init_user_profile(&usr);
assert_eq!(
usr.phone_number, profile.phone_number,
"Phone numbers are not equal"
);
}
}
+20
View File
@@ -0,0 +1,20 @@
package auxiliary
import (
"fmt"
)
type TwilioConfig struct {
AccountSID string `json:"auth_sid"`
ServiceSID string `json:"service_sid"`
AuthToken string `json:"auth_token"`
Number string `json:"phone_number"`
}
func (config *TwilioConfig) PrintConfig() {
fmt.Println("Twilio config")
fmt.Println("Account SID:", config.AccountSID)
fmt.Println("Service SID:", config.ServiceSID)
fmt.Println("Auth Token:", config.AuthToken)
fmt.Println("Number:", config.Number)
}
+14
View File
@@ -0,0 +1,14 @@
package contact
import (
"github.com/google/uuid"
)
type Contact struct {
Id *uuid.UUID `json:"id,omitempty"`
Firstname *string `json:"first_name,omitempty"`
Lastname *string `json:"last_name,omitempty"`
Nickname *string `json:"nickname,omitempty"`
PhoneNumber string `json:"phone_number"`
UserId *uuid.UUID `json:"user_id,omitempty"`
}
+18
View File
@@ -0,0 +1,18 @@
package event
import (
"time"
"github.com/google/uuid"
)
type MessageEventResponse struct {
Id uuid.UUID `json:"id,omitempty"`
ScheduledMessageEventId uuid.UUID `json:"scheduled_message_event_id,omitempty"`
Response map[string]any `json:"response"`
UserId uuid.UUID `json:"user_id,omitempty"`
ContactId *uuid.UUID `json:"contact_id,omitempty"`
MessageId *uuid.UUID `json:"message_id,omitempty"`
Status string `json:"status"`
Sent time.Time `json:"sent"`
}
+6
View File
@@ -0,0 +1,6 @@
package event
const (
Message_Event_Response_Status_Instant = "INSTANT"
Message_Event_Response_Status_Scheduled = "SCHEDULED"
)
+11
View File
@@ -0,0 +1,11 @@
package message
import (
"github.com/google/uuid"
)
type Message struct {
Id *uuid.UUID `json:"id,omitempty"`
Content string `json:"content"`
UserId *uuid.UUID `json:"user_id,omitempty"`
}
+15
View File
@@ -0,0 +1,15 @@
package scheduling
import (
"time"
"github.com/google/uuid"
)
type ScheduledMessageEvent struct {
Id uuid.UUID `json:"id"`
ContactId uuid.UUID `json:"contact_id"`
MessageId uuid.UUID `json:"message_id"`
ScheduledMessageId uuid.UUID `json:"scheduled_message_id"`
Created time.Time `json:"created"`
}
+15
View File
@@ -0,0 +1,15 @@
package scheduling
import (
"time"
"github.com/google/uuid"
)
type ScheduledMessage struct {
Id uuid.UUID `json:"id"`
Scheduled time.Time `json:"scheduled"`
Created time.Time `json:"created"`
Status string `json:"status"`
UserId uuid.UUID `json:"user_id"`
}
+8
View File
@@ -0,0 +1,8 @@
package scheduling
const (
Ready = "READY"
Pending = "PENDING"
Processing = "PROCESSING"
Done = "DONE"
)
+24
View File
@@ -0,0 +1,24 @@
package token
import (
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)
type Claims struct {
UserId uuid.UUID `json:"user_id"`
Role string `json:"role"`
jwt.RegisteredClaims
}
type LoginResult struct {
UserId uuid.UUID `json:"user_id"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int64 `json:"expires_in"`
IssuedAt int64 `json:"issued_at"`
}
// Alias for LoginResult
// Will be deprecated at some point
type Login = LoginResult
+42
View File
@@ -0,0 +1,42 @@
package types
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
// NOTE: Might end up removing this
type JSONB json.RawMessage
// Scan implements sql.Scanner
func (j *JSONB) Scan(value interface{}) error {
if value == nil {
*j = nil
return nil
}
var data []byte
switch v := value.(type) {
case []byte:
// pgx may pass data as []byte in binary format
data = v
case string:
// pgx may pass data as string in text format
data = []byte(v)
default:
return fmt.Errorf("unsupported type: %T", v)
}
*j = JSONB(data)
return nil
}
// Value implements driver.Valuer
func (j JSONB) Value() (driver.Value, error) {
if j == nil {
return nil, nil
} else {
return []byte(j), nil
}
}
+18
View File
@@ -0,0 +1,18 @@
package user
import (
"github.com/google/uuid"
"time"
)
type UserLoginHistory struct {
Id uuid.UUID `json:"id"`
LoginTime time.Time `json:"login_time"`
UserId uuid.UUID `json:"user_id"`
}
type ServiceUserLoginHistory struct {
Id uuid.UUID `json:"id"`
LoginTime time.Time `json:"login_time"`
ServiceUserId uuid.UUID `json:"service_user_id"`
}
+16
View File
@@ -0,0 +1,16 @@
package user
import (
"time"
"github.com/google/uuid"
)
type ServiceUser struct {
Id uuid.UUID `json:"id"`
// TODO: Remove the omitempty tags at a later point
Username string `json:"username,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
Created time.Time `json:"created"`
LastLogin *time.Time `json:"last_login,omitempty"`
}
+18
View File
@@ -0,0 +1,18 @@
package user
import (
"time"
"github.com/google/uuid"
)
type User struct {
Id uuid.UUID `json:"id"`
PhoneNumber string `json:"phone_number"`
Username string `json:"username"`
Password string `json:"password"`
Firstname *string `json:"first_name,omitempty"`
Lastname *string `json:"last_name,omitempty"`
Created time.Time `json:"created"`
LastLogin *time.Time `json:"last_login,omitempty"`
}
+42
View File
@@ -0,0 +1,42 @@
package user
import (
"fmt"
)
// TODO: Replace Usr with all the fields from User, except Password and other sensitive fields
type UserProfile struct {
UserId uuid.UUID `json:"user_id"`
PhoneNumber string `json:"phone_number"`
Username string `json:"username"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
Created time `json:"created"`
LastLogin *time `json:"last_login,omitempty"`
}
func InitUserProfile(usr *User) (usrProfile *UserProfile, err error) {
if usr == nil {
return nil, fmt.Errorf("User is empty")
} else {
usrProfile = new(UserProfile)
if len(usr.Password) > 0 {
// newUsr := User{Id: usr.Id, PhoneNumber: usr.PhoneNumber, Username: usr.Username, Firstname: usr.Firstname, Lastname: usr.Lastname, Created: usr.Created, LastLogin: usr.LastLogin}
// usrProfile.Usr = &newUsr
usrProfile.UserId = usr.Id
usrProfile.PhoneNumber = usr.PhoneNumber
usrProfile.Username = usr.Username
usrProfile.Firstname = usr.Firstname
usrProfile.Lastname = usr.Lastname
usrProfile.Created = usr.Created
if usr.LastLogin != nil {
usrProfile.LastLogin = usr.LastLogin
}
return usrProfile, nil
} else {
usrProfile.Usr = usr
return usrProfile, nil
}
}
}
+18
View File
@@ -0,0 +1,18 @@
package user
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestInitUserProfile(t *testing.T) {
usr := User{Username: "Bob", PhoneNumber: "+12224572351", Password: "TheNight!"}
profile, err := InitUserProfile(&usr)
assert.NoError(t, err, "Error %v", err)
assert.NotEmpty(t, profile, "UserProfile is empty")
assert.Empty(t, profile.Usr.Password, "Password should be empty")
}