Add common crate to access env variables

In the future, we should use a proper secret store (not just env variables).
This lets us update one block of code and not n in the future.
This commit is contained in:
Luke Parker
2023-07-17 00:50:46 -04:00
parent 845c2842b5
commit 0a367bfbda
11 changed files with 54 additions and 4 deletions

13
common/env/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "serai-env"
version = "0.1.0"
description = "A common library for Serai apps to access environment variables"
license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/common/env"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
keywords = []
edition = "2021"
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

15
common/env/LICENSE vendored Normal file
View File

@@ -0,0 +1,15 @@
AGPL-3.0-only license
Copyright (c) 2023 Luke Parker
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License Version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

8
common/env/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,8 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
// Obtain a variable from the Serai environment/secret store.
pub fn var(variable: &str) -> Option<String> {
// TODO: Move this to Kubernetes
std::env::var(variable).ok()
}