Compare commits

...

23 Commits

Author SHA1 Message Date
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
c90f9fb0b4 Refactoring const construction (#11)
All checks were successful
Release Tagging / release (push) Successful in 32s
Rust Build / Check (push) Successful in 27s
Rust Build / Test Suite (push) Successful in 29s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 28s
Rust Build / build (push) Successful in 26s
Rust Build / Check (pull_request) Successful in 26s
Rust Build / Test Suite (pull_request) Successful in 28s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 27s
Rust Build / build (pull_request) Successful in 25s
Reviewed-on: #11
Co-authored-by: kdeng00 <kundeng00@pm.me>
Co-committed-by: kdeng00 <kundeng00@pm.me>
2025-06-12 23:34:09 +00:00
7df6fe5821 Added test (#10)
All checks were successful
Release Tagging / release (push) Successful in 31s
Rust Build / Check (push) Successful in 26s
Rust Build / Test Suite (push) Successful in 26s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 26s
Rust Build / Rustfmt (pull_request) Successful in 27s
Rust Build / Clippy (pull_request) Successful in 28s
Rust Build / build (pull_request) Successful in 27s
Rust Build / build (push) Successful in 27s
Rust Build / Check (pull_request) Successful in 26s
Rust Build / Test Suite (pull_request) Successful in 28s
Reviewed-on: #10
Co-authored-by: kdeng00 <kundeng00@pm.me>
Co-committed-by: kdeng00 <kundeng00@pm.me>
2025-06-12 21:26:22 +00:00
e7e6fd904b Add icarus_base_api_url_env (#8)
All checks were successful
Release Tagging / release (push) Successful in 31s
Reviewed-on: #8
Co-authored-by: kdeng00 <kundeng00@pm.me>
Co-committed-by: kdeng00 <kundeng00@pm.me>
2025-06-12 19:14:27 +00:00
3ee8c1e573 Stable release (#5)
Reviewed-on: #5
2025-06-02 00:13:57 +00:00
dbe4dc67cb DBURL name change (#7)
All checks were successful
Release Tagging / release (push) Successful in 31s
Reviewed-on: #7
Co-authored-by: kdeng00 <kundeng00@pm.me>
Co-committed-by: kdeng00 <kundeng00@pm.me>
2025-06-01 01:26:37 +00:00
9aa16a3f2e First release (#2)
Reviewed-on: #2
2025-05-29 22:55:19 +00:00
11 changed files with 450 additions and 43 deletions

10
.env
View File

@@ -1,8 +1,18 @@
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
POSTGRES_MAIN_DB=my_db 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_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,8 +1,18 @@
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
POSTGRES_MAIN_DB=my_db 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_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

@@ -0,0 +1,62 @@
name: Rust Build
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
check:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
- run: cargo check
test:
name: Test Suite
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
- run: cargo test
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
- run: rustup component add clippy
- run: cargo clippy -- -D warnings
build:
name: build
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.88.0
- run: cargo build

29
Cargo.lock generated
View File

@@ -168,6 +168,26 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "const_format"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126f97965c8ad46d6d9163268ff28432e8f6a1196a55578867832e3049df63dd"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d57c2eccfb16dbac1f4e61e206105db5820c9d26c3c472bc17c774259ef7744"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.21" version = "0.8.21"
@@ -277,9 +297,10 @@ checksum = "f154ce46856750ed433c8649605bf7ed2de3bc35fd9d2a9f30cddd873c80cb08"
[[package]] [[package]]
name = "icarus_envy" name = "icarus_envy"
version = "0.1.0" version = "0.4.0"
dependencies = [ dependencies = [
"async-std", "async-std",
"const_format",
"dotenvy", "dotenvy",
] ]
@@ -458,6 +479,12 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]] [[package]]
name = "value-bag" name = "value-bag"
version = "1.11.1" version = "1.11.1"

View File

@@ -1,11 +1,12 @@
[package] [package]
name = "icarus_envy" name = "icarus_envy"
version = "0.1.0" version = "0.4.0"
edition = "2024" edition = "2024"
rust-version = "1.86" rust-version = "1.88"
[dependencies] [dependencies]
dotenvy = { version = "0.15.7" } dotenvy = { version = "0.15.7" }
const_format = { version = "0.2.34" }
[dev-dependencies] [dev-dependencies]
async-std = { version = "1.13.1" } async-std = { version = "1.13.1" }

View File

@@ -1,20 +1,106 @@
pub async fn get_db_url() -> crate::EnvVar {
pub async fn get_db_url() -> String {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
std::env::var(crate::keys::DBURL).expect(crate::keys::error::ERROR) 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_root_directory() -> crate::EnvVar {
dotenvy::dotenv().ok();
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,21 +1,52 @@
// TODO: Change this to snake case /// Environment key for Database management
// Environment key for Database management pub const DB_URL: &str = "DATABASE_URL";
pub const DBURL: &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
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 {
pub const ERROR: &str = "DATABASE_URL must be set in .env"; use const_format::concatcp;
pub const SECRET_KEY: &str = "SECRET_KEY must be set in environment file";
pub const SECRET_MAIN_KEY: &str = "SECRET_MAIN_KEY must not be set in environment file"; pub const GENERAL_ERROR: &str = "must not be set in enviornment file";
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY must not be set in environment 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 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,17 +1,43 @@
pub mod environment; pub mod environment;
pub mod keys; pub mod keys;
pub mod utility;
pub fn add(left: u64, right: u64) -> u64 { #[derive(Debug, Default, Clone)]
left + right pub struct EnvVar {
pub key: String,
pub value: String,
pub has_delimiter: bool,
pub delimiter: char,
} }
#[cfg(test)] pub fn init_envvar(key: &str, value: &str) -> EnvVar {
mod tests { EnvVar {
use super::*; key: key.to_string(),
value: value.to_string(),
#[test] has_delimiter: false,
fn it_works() { ..Default::default()
let result = add(2, 2); }
assert_eq!(result, 4); }
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 = if amount_of_delimiters_found >= 1 {
true
} else {
false
};
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

@@ -1,27 +1,163 @@
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]
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!(result, "postgres://myuser:password@localhost:5432/my_db", "DATABASE_URL does not match {:?}", result); assert_eq!(
result.value, "postgres://myuser:password@localhost:5432/my_db",
"DATABASE_URL does not match {:?}",
result
);
} }
#[test] #[test]
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!(result, "Somesupersecretpassword!!!45345435", "SECRET_MAIN_KEY does not match {:?}", result) assert_eq!(
result.value, "Somesupersecretpassword!!!45345435",
"SECRET_MAIN_KEY does not match {:?}",
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!(result, "AmIGoodEnoughForYou?", "SECRET_KEY does not match {:?}", result) assert_eq!(
result.value, "AmIGoodEnoughForYou?",
"SECRET_KEY does not match {:?}",
result
)
} }
#[test] #[test]
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!(result, "/path/to/root", "ROOT_DIRECTORY does not match {:?}", result) assert_eq!(
result.value, "/path/to/root",
"ROOT_DIRECTORY does not match {:?}",
result
)
}
#[test]
fn test_get_icarus_base_api_url() {
let result = async_std::task::block_on(icarus_envy::environment::get_icarus_base_api_url());
assert_eq!(
result.value, "https://icarus.com",
"ICARUS_BASE_API_URL does not match {:?}",
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
)
}
} }
} }