Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d06c8fdf49 | ||
|
|
349056db6e | ||
|
|
208539f559 | ||
|
|
ab91c3fa4f | ||
|
|
b315e89480 | ||
|
|
bb04f4417d | ||
|
|
6805b15f0e | ||
|
|
8f0d123db5 | ||
|
|
38e0073cbe | ||
|
|
86c5050c7b | ||
|
|
0f470ef723 | ||
|
|
e51df82f09 | ||
|
|
d84a8144ae | ||
|
|
3cd42dab6b | ||
|
|
e2c83b5219 | ||
|
|
b414031af0 | ||
|
|
d73fba9899 | ||
|
|
020d091446 | ||
|
|
84ea6e4c22 | ||
|
|
c90f9fb0b4 | ||
|
|
7df6fe5821 | ||
|
|
e7e6fd904b | ||
|
|
3ee8c1e573 | ||
|
|
dbe4dc67cb | ||
|
|
6c37c19a57 | ||
|
|
596d2afdaa | ||
|
|
f0726b83c9 | ||
|
|
b89633e394
|
@@ -0,0 +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_KEY=AmIGoodEnoughForYou?
|
||||
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
|
||||
ROOT_DIRECTORY=/path/to/root
|
||||
POSTGRES_MAIN_USER=myuser
|
||||
POSTGRES_MAIN_PASSWORD=password
|
||||
POSTGRES_MAIN_DB=my_db
|
||||
POSTGRES_MAIN_HOST=localhost
|
||||
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
||||
SOARICARUS_BASE_API_URL=https://soaricarus.com
|
||||
SOARICARUS_AUTH_BASE_API_URL=https://auth.soaricarus.com
|
||||
APP_ENV=development
|
||||
BACKEND_PORT=8001
|
||||
FRONTEND_URL=http://localhost:4200
|
||||
RUST_LOG=debug
|
||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||
+18
@@ -0,0 +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_KEY=AmIGoodEnoughForYou?
|
||||
SERVICE_PASSPHRASE=T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO
|
||||
ROOT_DIRECTORY=/path/to/root
|
||||
POSTGRES_MAIN_USER=myuser
|
||||
POSTGRES_MAIN_PASSWORD=password
|
||||
POSTGRES_MAIN_DB=my_db
|
||||
POSTGRES_MAIN_HOST=localhost
|
||||
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
||||
SOARICARUS_BASE_API_URL=https://soaricarus.com
|
||||
SOARICARUS_AUTH_BASE_API_URL=https://auth.soaricarus.com
|
||||
APP_ENV=development
|
||||
BACKEND_PORT=8001
|
||||
FRONTEND_URL=http://localhost:4200
|
||||
RUST_LOG=debug
|
||||
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||
@@ -3,22 +3,26 @@ name: Release Tagging
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- devel
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # Important for git describe --tags
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.86.0
|
||||
toolchain: 1.97
|
||||
components: cargo
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Extract Version from Cargo.toml
|
||||
id: version
|
||||
@@ -28,7 +32,7 @@ jobs:
|
||||
BRANCH_REF="${GITHUB_REF}"
|
||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||
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 "Hash: $PROJECT_COMMIT_HASH"
|
||||
echo "Branch: $BRANCH_NAME"
|
||||
@@ -0,0 +1,67 @@
|
||||
name: sienvy Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
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
|
||||
- run: rustup component add rustfmt
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- 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
|
||||
- run: rustup component add clippy
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- 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
|
||||
Generated
+83
@@ -0,0 +1,83 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "const_format"
|
||||
version = "0.2.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4481a617ad9a412be3b97c5d403fef8ed023103368908b9c50af598ff467cc1e"
|
||||
dependencies = [
|
||||
"const_format_proc_macros",
|
||||
"konst",
|
||||
]
|
||||
|
||||
[[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]]
|
||||
name = "dotenvy"
|
||||
version = "0.15.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
|
||||
|
||||
[[package]]
|
||||
name = "konst"
|
||||
version = "0.2.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "128133ed7824fcd73d6e7b17957c5eb7bacb885649bd8c69708b2331a10bcefb"
|
||||
dependencies = [
|
||||
"konst_macro_rules",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "konst_macro_rules"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sienvy"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
+7
-3
@@ -1,7 +1,11 @@
|
||||
[package]
|
||||
name = "icarus_envy"
|
||||
version = "0.1.0"
|
||||
name = "sienvy"
|
||||
version = "0.8.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.86"
|
||||
rust-version = "1.95"
|
||||
|
||||
[dependencies]
|
||||
dotenvy = { version = "0.15.7" }
|
||||
const_format = { version = "0.2.36" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
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.
|
||||
@@ -0,0 +1,6 @@
|
||||
# sienvy
|
||||
This is a library used to retrieve environment variables associated with various
|
||||
icarus projects. Rather than having the various icarus projects such as icarus,
|
||||
icarus_auth, songparser, and others, have environment code, it would be more
|
||||
efficient to consolidate it. Especially, if there are commonly used environment
|
||||
variables used throughout the apps.
|
||||
@@ -0,0 +1,106 @@
|
||||
pub fn get_db_url() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::DB_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub fn get_secret_main_key() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::SECRET_MAIN_KEY;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub fn get_service_passphrase() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::SERVICE_PASSPHRASE;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub fn get_secret_key() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::SECRET_KEY;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub 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 fn get_soaricarus_base_api_url() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::SOARICARUS_BASE_API_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub fn get_soaricarus_auth_base_api_url() -> crate::EnvVar {
|
||||
dotenvy::dotenv().ok();
|
||||
let key = crate::keys::SOARICARUS_AUTH_BASE_API_URL;
|
||||
let value = std::env::var(key).expect(key);
|
||||
|
||||
crate::init_envvar(key, &value)
|
||||
}
|
||||
|
||||
pub 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 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 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 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 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 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)
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/// Environment key for Database management
|
||||
pub const DB_URL: &str = "DATABASE_URL";
|
||||
|
||||
/// Environment key for secret main key
|
||||
/// Used for the soaricarus 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 soaricarus app
|
||||
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY";
|
||||
|
||||
/// Environment key for soaricarus api url
|
||||
pub const SOARICARUS_BASE_API_URL: &str = "SOARICARUS_BASE_API_URL";
|
||||
|
||||
/// Environment key for soaricarus auth api url
|
||||
pub const SOARICARUS_AUTH_BASE_API_URL: &str = "SOARICARUS_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 SOARICARUS_BASE_API_URL: &str =
|
||||
concatcp!(super::SOARICARUS_BASE_API_URL, " ", GENERAL_ERROR);
|
||||
pub const SOARICARUS_AUTH_BASE_API_URL: &str =
|
||||
concatcp!(super::SOARICARUS_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);
|
||||
}
|
||||
+35
-10
@@ -1,14 +1,39 @@
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
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,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
))
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_dburl() {
|
||||
let result = sienvy::environment::get_db_url();
|
||||
assert_eq!(
|
||||
result.value, "postgres://myuser:password@localhost:5432/my_db",
|
||||
"DATABASE_URL does not match {:?}",
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_secret_main_key() {
|
||||
let result = sienvy::environment::get_secret_main_key();
|
||||
assert_eq!(
|
||||
result.value, "Somesupersecretpassword!!!45345435",
|
||||
"SECRET_MAIN_KEY does not match {:?}",
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_service_passphrase() {
|
||||
let result = sienvy::environment::get_service_passphrase();
|
||||
assert_eq!(
|
||||
result.value, "T5OCHDHadAtuOWIqRAS7u8XHDDkzKT1Uvvw7mGMkNzKjVdlHA8xGdILf2adDHspO",
|
||||
"SERVICE_PASSPHRASE does not match {:?}",
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_secret_key() {
|
||||
let result = sienvy::environment::get_secret_key();
|
||||
assert_eq!(
|
||||
result.value, "AmIGoodEnoughForYou?",
|
||||
"SECRET_KEY does not match {:?}",
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_root_directory() {
|
||||
let result = sienvy::environment::get_root_directory();
|
||||
assert_eq!(
|
||||
result.value, "/path/to/root",
|
||||
"ROOT_DIRECTORY does not match {:?}",
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_soaricarus_base_api_url() {
|
||||
let result = sienvy::environment::get_soaricarus_base_api_url();
|
||||
assert_eq!(
|
||||
result.value, "https://soaricarus.com",
|
||||
"SOARICARUS_BASE_API_URL does not match {:?}",
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_app_env() {
|
||||
let result = sienvy::environment::get_app_env();
|
||||
assert_eq!(
|
||||
result.value,
|
||||
"development",
|
||||
"{} does not match {:?}",
|
||||
sienvy::keys::APP_ENV,
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_backend_port() {
|
||||
let result = sienvy::environment::get_backend_port();
|
||||
assert_eq!(
|
||||
result.value,
|
||||
"8001",
|
||||
"{} does not match {:?}",
|
||||
sienvy::keys::BACKEND_PORT,
|
||||
result
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn test_get_frontend_url() {
|
||||
let result = sienvy::environment::get_frontend_url();
|
||||
assert_eq!(
|
||||
result.value,
|
||||
"http://localhost:4200",
|
||||
"{} does not match {:?}",
|
||||
sienvy::keys::FRONTEND_URL,
|
||||
result
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn test_get_rust_log() {
|
||||
let result = sienvy::environment::get_rust_log();
|
||||
assert_eq!(
|
||||
result.value,
|
||||
"debug",
|
||||
"{} does not match {:?}",
|
||||
sienvy::keys::RUST_LOG,
|
||||
result
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn test_get_allowed_origins() {
|
||||
let result = sienvy::environment::get_allowed_origins();
|
||||
assert_eq!(
|
||||
result.value,
|
||||
"https://soaricarus.com,https://www.soaricarus.com",
|
||||
"{} does not match {:?}",
|
||||
sienvy::keys::ALLOWED_ORIGINS,
|
||||
result
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
result.has_delimiter, true,
|
||||
"The {} variable has an issue finding the delimiter",
|
||||
result.key
|
||||
);
|
||||
|
||||
match sienvy::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 = sienvy::environment::get_env(key);
|
||||
assert_eq!(
|
||||
result.value, *value,
|
||||
"{:?} does not match {:?}",
|
||||
key, result
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user