Compare commits

...

21 Commits

Author SHA1 Message Date
1823a3a4aa Version bump
All checks were successful
Rust Build / Check (pull_request) Successful in 33s
Rust Build / Test Suite (pull_request) Successful in 33s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Successful in 33s
Release Tagging / release (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 30s
2025-10-10 14:39:40 -04:00
50e77edddc Clippy fix
All checks were successful
Release Tagging / release (pull_request) Successful in 33s
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 33s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 31s
2025-10-10 14:38:46 -04:00
101547dbf4 Code formatting
Some checks failed
Release Tagging / release (pull_request) Successful in 32s
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 32s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Failing after 33s
Rust Build / build (pull_request) Successful in 35s
2025-10-10 14:25:13 -04:00
797430c9d2 Changed name of function 2025-10-10 14:24:04 -04:00
218b0f60a9 Removing comment 2025-10-10 14:19:48 -04:00
c06d546ae7 Updated test 2025-10-10 14:11:01 -04:00
d9e43a80e4 Made modifications to the test and related code 2025-10-10 13:58:29 -04:00
a7a2a8080e Added code to initialize an envvar delimiter 2025-10-10 13:54:10 -04:00
38e0073cbe Added EnvVar (#24)
All checks were successful
Release Tagging / release (push) Successful in 34s
Rust Build / Check (push) Successful in 30s
Rust Build / Test Suite (push) Successful in 32s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 34s
Rust Build / build (push) Successful in 30s
Release Tagging / release (pull_request) Successful in 33s
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (pull_request) Successful in 31s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 35s
Rust Build / build (pull_request) Successful in 31s
Reviewed-on: #24
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-10 17:37:32 +00:00
86c5050c7b Refactoring (#21)
All checks were successful
Rust Build / Check (push) Successful in 33s
Rust Build / Test Suite (push) Successful in 37s
Release Tagging / release (push) Successful in 46s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / Clippy (push) Successful in 36s
Rust Build / build (push) Successful in 40s
Reviewed-on: #21
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-29 20:38:53 +00:00
0f470ef723 Added general environment function (#20)
All checks were successful
Rust Build / Check (push) Successful in 40s
Release Tagging / release (push) Successful in 45s
Rust Build / Test Suite (push) Successful in 34s
Rust Build / Rustfmt (push) Successful in 36s
Rust Build / Clippy (push) Successful in 42s
Rust Build / build (push) Successful in 36s
Reviewed-on: #20
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-29 19:22:10 +00:00
e51df82f09 CORS env variables (#19)
All checks were successful
Release Tagging / release (push) Successful in 41s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 38s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 35s
Rust Build / build (push) Successful in 31s
Reviewed-on: #19
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-09-28 23:08:32 +00:00
d84a8144ae tsk-17: Add ICARUS_AUTH_BASE_API_URL env key (#18)
All checks were successful
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 30s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / build (push) Successful in 30s
Rust Build / Clippy (push) Successful in 34s
Release Tagging / release (push) Successful in 33s
Closes #17

Reviewed-on: #18
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-14 22:58:45 +00:00
3cd42dab6b Service passphrase (#16)
All checks were successful
Rust Build / Check (push) Successful in 28s
Release Tagging / release (push) Successful in 51s
Rust Build / Test Suite (push) Successful in 28s
Rust Build / Clippy (push) Successful in 29s
Rust Build / Rustfmt (push) Successful in 46s
Rust Build / build (push) Successful in 27s
Reviewed-on: #16
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-02 21:26:14 +00:00
e2c83b5219 Removing references of the devel branch (#15)
All checks were successful
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 25s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 30s
Rust Build / build (push) Successful in 27s
Reviewed-on: #15
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-02 21:14:25 +00:00
b414031af0 v0.3 release (#9)
All checks were successful
Rust Build / Check (push) Successful in 30s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Rustfmt (push) Successful in 26s
Rust Build / Clippy (push) Successful in 32s
Rust Build / build (push) Successful in 28s
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 38s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 30s
Reviewed-on: #9
2025-07-23 22:04:06 +00:00
d73fba9899 Version bump (#14)
All checks were successful
Rust Build / Rustfmt (push) Successful in 26s
Rust Build / Clippy (push) Successful in 24s
Release Tagging / release (push) Successful in 30s
Rust Build / Check (push) Successful in 26s
Rust Build / Test Suite (push) Successful in 26s
Rust Build / build (push) Successful in 24s
Rust Build / Check (pull_request) Successful in 24s
Rust Build / Test Suite (pull_request) Successful in 26s
Rust Build / Rustfmt (pull_request) Successful in 25s
Rust Build / Clippy (pull_request) Successful in 25s
Rust Build / build (pull_request) Successful in 26s
Reviewed-on: #14
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 19:06:18 +00:00
020d091446 Rust std change (#13)
All checks were successful
Rust Build / Check (push) Successful in 25s
Rust Build / Rustfmt (push) Successful in 29s
Rust Build / Clippy (push) Successful in 32s
Rust Build / build (push) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 29s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 28s
Release Tagging / release (push) Successful in 28s
Rust Build / Test Suite (push) Successful in 26s
Rust Build / Check (pull_request) Successful in 26s
Reviewed-on: #13
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-06-29 18:58:12 +00:00
84ea6e4c22 Updated version tag (#12)
All checks were successful
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 25s
Rust Build / Test Suite (push) Successful in 27s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 26s
Rust Build / build (push) Successful in 26s
Rust Build / Test Suite (pull_request) Successful in 41s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Successful in 30s
Rust Build / build (pull_request) Successful in 26s
Rust Build / Check (pull_request) Successful in 26s
Reviewed-on: #12
Co-authored-by: kdeng00 <kundeng00@pm.me>
Co-committed-by: kdeng00 <kundeng00@pm.me>
2025-06-12 23:50:08 +00:00
3ee8c1e573 Stable release (#5)
Reviewed-on: #5
2025-06-02 00:13:57 +00:00
9aa16a3f2e First release (#2)
Reviewed-on: #2
2025-05-29 22:55:19 +00:00
11 changed files with 325 additions and 37 deletions

9
.env
View File

@@ -1,5 +1,8 @@
RANDOM_ENV_KEY="YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe"
MODNAR_ENV_KEY="FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain"
SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435 SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435
SECRET_KEY=AmIGoodEnoughForYou? SECRET_KEY=AmIGoodEnoughForYou?
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
ROOT_DIRECTORY=/path/to/root ROOT_DIRECTORY=/path/to/root
POSTGRES_MAIN_USER=myuser POSTGRES_MAIN_USER=myuser
POSTGRES_MAIN_PASSWORD=password POSTGRES_MAIN_PASSWORD=password
@@ -7,3 +10,9 @@ POSTGRES_MAIN_DB=my_db
POSTGRES_MAIN_HOST=localhost POSTGRES_MAIN_HOST=localhost
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB} DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
ICARUS_BASE_API_URL=https://icarus.com ICARUS_BASE_API_URL=https://icarus.com
ICARUS_AUTH_BASE_API_URL=https://auth.icarus.com
APP_ENV=development
BACKEND_PORT=8001
FRONTEND_URL=http://localhost:4200
RUST_LOG=debug
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com

View File

@@ -1,5 +1,8 @@
RANDOM_ENV_KEY="YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe"
MODNAR_ENV_KEY="FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain"
SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435 SECRET_MAIN_KEY=Somesupersecretpassword!!!45345435
SECRET_KEY=AmIGoodEnoughForYou? SECRET_KEY=AmIGoodEnoughForYou?
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
ROOT_DIRECTORY=/path/to/root ROOT_DIRECTORY=/path/to/root
POSTGRES_MAIN_USER=myuser POSTGRES_MAIN_USER=myuser
POSTGRES_MAIN_PASSWORD=password POSTGRES_MAIN_PASSWORD=password
@@ -7,3 +10,9 @@ POSTGRES_MAIN_DB=my_db
POSTGRES_MAIN_HOST=localhost POSTGRES_MAIN_HOST=localhost
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB} DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
ICARUS_BASE_API_URL=https://icarus.com ICARUS_BASE_API_URL=https://icarus.com
ICARUS_AUTH_BASE_API_URL=https://auth.icarus.com
APP_ENV=development
BACKEND_PORT=8001
FRONTEND_URL=http://localhost:4200
RUST_LOG=debug
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com

View File

@@ -3,7 +3,10 @@ name: Release Tagging
on: on:
push: push:
branches: branches:
- devel - main
pull_request:
branches:
- main
jobs: jobs:
release: release:
@@ -17,7 +20,7 @@ jobs:
- name: Install Rust - name: Install Rust
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
components: cargo components: cargo
- name: Extract Version from Cargo.toml - name: Extract Version from Cargo.toml
@@ -28,7 +31,7 @@ jobs:
BRANCH_REF="${GITHUB_REF}" BRANCH_REF="${GITHUB_REF}"
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3) BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH" PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH"
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-950" echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE-006"
echo "Version: $VERSION" echo "Version: $VERSION"
echo "Hash: $PROJECT_COMMIT_HASH" echo "Hash: $PROJECT_COMMIT_HASH"
echo "Branch: $BRANCH_NAME" echo "Branch: $BRANCH_NAME"

View File

@@ -4,11 +4,9 @@ on:
push: push:
branches: branches:
- main - main
- devel
pull_request: pull_request:
branches: branches:
- main - main
- devel
jobs: jobs:
check: check:
@@ -18,7 +16,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: cargo check - run: cargo check
test: test:
@@ -28,7 +26,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: cargo test - run: cargo test
fmt: fmt:
@@ -38,7 +36,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: rustup component add rustfmt - run: rustup component add rustfmt
- run: cargo fmt --all -- --check - run: cargo fmt --all -- --check
@@ -49,7 +47,7 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: rustup component add clippy - run: rustup component add clippy
- run: cargo clippy -- -D warnings - run: cargo clippy -- -D warnings
@@ -60,6 +58,5 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1 - uses: actions-rust-lang/setup-rust-toolchain@v1
with: with:
toolchain: 1.86.0 toolchain: 1.88.0
- run: cargo build - run: cargo build

2
Cargo.lock generated
View File

@@ -297,7 +297,7 @@ checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08"
[[package]] [[package]]
name = "icarus_envy" name = "icarus_envy"
version = "0.2.1" version = "0.4.1"
dependencies = [ dependencies = [
"async-std", "async-std",
"const_format", "const_format",

View File

@@ -1,8 +1,8 @@
[package] [package]
name = "icarus_envy" name = "icarus_envy"
version = "0.2.2" version = "0.4.1"
edition = "2024" edition = "2024"
rust-version = "1.86" rust-version = "1.88"
[dependencies] [dependencies]
dotenvy = { version = "0.15.7" } dotenvy = { version = "0.15.7" }

View File

@@ -1,24 +1,106 @@
pub async fn get_db_url() -> String { pub async fn get_db_url() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::DB_URL).expect(crate::keys::error::DB_URL) let key = crate::keys::DB_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_secret_main_key() -> String { pub async fn get_secret_main_key() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::SECRET_MAIN_KEY).expect(crate::keys::error::SECRET_MAIN_KEY) let key = crate::keys::SECRET_MAIN_KEY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_secret_key() -> String { pub async fn get_service_passphrase() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::SECRET_KEY).expect(crate::keys::error::SECRET_KEY) let key = crate::keys::SERVICE_PASSPHRASE;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_root_directory() -> String { pub async fn get_secret_key() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ROOT_DIRECTORY).expect(crate::keys::error::ROOT_DIRECTORY) let key = crate::keys::SECRET_KEY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
} }
pub async fn get_icarus_base_api_url() -> String { pub async fn get_root_directory() -> crate::EnvVar {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::ICARUS_BASE_API_URL).expect(crate::keys::error::ICARUS_BASE_API_URL) let key = crate::keys::ROOT_DIRECTORY;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_icarus_base_api_url() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::ICARUS_BASE_API_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_icarus_auth_base_api_url() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::ICARUS_AUTH_BASE_API_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_app_env() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::APP_ENV;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_backend_port() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::BACKEND_PORT;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_frontend_url() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::FRONTEND_URL;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_rust_log() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::RUST_LOG;
let value = std::env::var(key).expect(key);
crate::init_envvar(key, &value)
}
pub async fn get_allowed_origins() -> crate::EnvVar {
dotenvy::dotenv().ok();
let key = crate::keys::ALLOWED_ORIGINS;
let value = std::env::var(key).expect(key);
let mut envvar = crate::init_envvar(key, &value);
crate::init_delimiter(&mut envvar, ',');
envvar
}
/// Get environment not specified in the code
pub async fn get_env(environment: &str) -> crate::EnvVar {
dotenvy::dotenv().ok();
let my_error = format!("{environment} {}", crate::keys::error::GENERAL_ERROR);
let value = std::env::var(environment).expect(&my_error);
crate::init_envvar(environment, &value)
} }

View File

@@ -1,27 +1,52 @@
// Environment key for Database management /// Environment key for Database management
pub const DB_URL: &str = "DATABASE_URL"; pub const DB_URL: &str = "DATABASE_URL";
// Environment key for secret main key /// Environment key for secret main key
// Used for the icarus app /// Used for the icarus app
pub const SECRET_MAIN_KEY: &str = "SECRET_MAIN_KEY"; pub const SECRET_MAIN_KEY: &str = "SECRET_MAIN_KEY";
// Environment key for secret key /// Environment key for service logins
// Generic use of secret key that could be found in various apps 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"; pub const SECRET_KEY: &str = "SECRET_KEY";
// Environment key for root directory for the icarus app /// Environment key for root directory for the icarus app
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY"; pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY";
// Environment key for icarus api url /// Environment key for icarus api url
pub const ICARUS_BASE_API_URL: &str = "ICARUS_BASE_API_URL"; pub const ICARUS_BASE_API_URL: &str = "ICARUS_BASE_API_URL";
/// Environment key for icarus auth api url
pub const ICARUS_AUTH_BASE_API_URL: &str = "ICARUS_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 { pub mod error {
use const_format::concatcp; use const_format::concatcp;
pub const GENERAL_ERROR: &str = "must not be set in enviornment file"; 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 DB_URL: &str = concatcp!(super::DB_URL, " ", GENERAL_ERROR);
pub const SECRET_KEY: &str = concatcp!(super::SECRET_KEY, " ", GENERAL_ERROR);
pub const SECRET_MAIN_KEY: &str = concatcp!(super::SECRET_MAIN_KEY, " ", 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 ROOT_DIRECTORY: &str = concatcp!(super::ROOT_DIRECTORY, " ", GENERAL_ERROR);
pub const ICARUS_BASE_API_URL: &str = concatcp!(super::ICARUS_BASE_API_URL, " ", GENERAL_ERROR); pub const ICARUS_BASE_API_URL: &str = concatcp!(super::ICARUS_BASE_API_URL, " ", GENERAL_ERROR);
pub const ICARUS_AUTH_BASE_API_URL: &str =
concatcp!(super::ICARUS_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);
} }

View File

@@ -1,2 +1,39 @@
pub mod environment; pub mod environment;
pub mod keys; 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 mut amount_of_delimiters_found: i32 = 0;
for v in envvar.value.chars() {
if v == delimiter {
amount_of_delimiters_found += 1;
}
}
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;
}
}

15
src/utility.rs Normal file
View File

@@ -0,0 +1,15 @@
/// Take the Environment variable and delimitize it. If the value has a delimiter,
/// extract it into some strings
pub fn delimitize(var: &crate::EnvVar) -> Result<Vec<String>, std::io::Error> {
if var.has_delimiter {
Ok(var
.value
.split(var.delimiter)
.map(|c| c.parse::<String>().unwrap())
.collect())
} else {
Err(std::io::Error::other(
"Environment variable does not have a delimiter",
))
}
}

View File

@@ -4,7 +4,7 @@ mod tests {
fn test_dburl() { fn test_dburl() {
let result = async_std::task::block_on(icarus_envy::environment::get_db_url()); let result = async_std::task::block_on(icarus_envy::environment::get_db_url());
assert_eq!( assert_eq!(
result, "postgres://myuser:password@localhost:5432/my_db", result.value, "postgres://myuser:password@localhost:5432/my_db",
"DATABASE_URL does not match {:?}", "DATABASE_URL does not match {:?}",
result result
); );
@@ -14,17 +14,27 @@ mod tests {
fn test_get_secret_main_key() { fn test_get_secret_main_key() {
let result = async_std::task::block_on(icarus_envy::environment::get_secret_main_key()); let result = async_std::task::block_on(icarus_envy::environment::get_secret_main_key());
assert_eq!( assert_eq!(
result, "Somesupersecretpassword!!!45345435", result.value, "Somesupersecretpassword!!!45345435",
"SECRET_MAIN_KEY does not match {:?}", "SECRET_MAIN_KEY does not match {:?}",
result result
) )
} }
#[test]
fn test_get_service_passphrase() {
let result = async_std::task::block_on(icarus_envy::environment::get_service_passphrase());
assert_eq!(
result.value, "T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO",
"SERVICE_PASSPHRASE does not match {:?}",
result
)
}
#[test] #[test]
fn test_get_secret_key() { fn test_get_secret_key() {
let result = async_std::task::block_on(icarus_envy::environment::get_secret_key()); let result = async_std::task::block_on(icarus_envy::environment::get_secret_key());
assert_eq!( assert_eq!(
result, "AmIGoodEnoughForYou?", result.value, "AmIGoodEnoughForYou?",
"SECRET_KEY does not match {:?}", "SECRET_KEY does not match {:?}",
result result
) )
@@ -34,7 +44,7 @@ mod tests {
fn test_get_root_directory() { fn test_get_root_directory() {
let result = async_std::task::block_on(icarus_envy::environment::get_root_directory()); let result = async_std::task::block_on(icarus_envy::environment::get_root_directory());
assert_eq!( assert_eq!(
result, "/path/to/root", result.value, "/path/to/root",
"ROOT_DIRECTORY does not match {:?}", "ROOT_DIRECTORY does not match {:?}",
result result
) )
@@ -44,9 +54,110 @@ mod tests {
fn test_get_icarus_base_api_url() { fn test_get_icarus_base_api_url() {
let result = async_std::task::block_on(icarus_envy::environment::get_icarus_base_api_url()); let result = async_std::task::block_on(icarus_envy::environment::get_icarus_base_api_url());
assert_eq!( assert_eq!(
result, "https://icarus.com", result.value, "https://icarus.com",
"ICARUS_BASE_API_URL does not match {:?}", "ICARUS_BASE_API_URL does not match {:?}",
result result
) )
} }
#[test]
fn test_get_app_env() {
let result = async_std::task::block_on(icarus_envy::environment::get_app_env());
assert_eq!(
result.value,
"development",
"{} does not match {:?}",
icarus_envy::keys::APP_ENV,
result
)
}
#[test]
fn test_get_backend_port() {
let result = async_std::task::block_on(icarus_envy::environment::get_backend_port());
assert_eq!(
result.value,
"8001",
"{} does not match {:?}",
icarus_envy::keys::BACKEND_PORT,
result
)
}
#[test]
fn test_get_frontend_url() {
let result = async_std::task::block_on(icarus_envy::environment::get_frontend_url());
assert_eq!(
result.value,
"http://localhost:4200",
"{} does not match {:?}",
icarus_envy::keys::FRONTEND_URL,
result
)
}
#[test]
fn test_get_rust_log() {
let result = async_std::task::block_on(icarus_envy::environment::get_rust_log());
assert_eq!(
result.value,
"debug",
"{} does not match {:?}",
icarus_envy::keys::RUST_LOG,
result
)
}
#[test]
fn test_get_allowed_origins() {
let result = async_std::task::block_on(icarus_envy::environment::get_allowed_origins());
assert_eq!(
result.value,
"https://soaricarus.com,https://www.soaricarus.com",
"{} does not match {:?}",
icarus_envy::keys::ALLOWED_ORIGINS,
result
);
assert_eq!(
result.has_delimiter, true,
"The {} variable has an issue finding the delimiter",
result.key
);
match icarus_envy::utility::delimitize(&result) {
Ok(allowed_origins) => {
assert_eq!(
allowed_origins.len(),
2,
"The amount of allowed origins does not match. {} {}",
allowed_origins.len(),
2
)
}
Err(err) => {
assert!(false, "Error: {:?}", err)
}
}
}
#[test]
fn test_get_env() {
let keys = vec![
(
"RANDOM_ENV_KEY",
"YouDon'tWantToButYouGottaChange|It'sGoingToHurtYouTryingToStayTheSame|AreYouInItOrYouInItForTheFame?|I'mTryingToFigureOutWhoLoveMeForMe",
),
(
"MODNAR_ENV_KEY",
"FeelingTheMonsterClimbDeepserInsideOfMe|FeelingHimGnawingMyHeartAwayHungrily|I'llNeverLoseThisPain|NeverDreamOfYouAgain",
),
];
for (key, value) in keys.iter() {
let result = async_std::task::block_on(icarus_envy::environment::get_env(key));
assert_eq!(
result.value, *value,
"{:?} does not match {:?}",
key, result
)
}
}
} }