mirror of
https://github.com/serai-dex/serai.git
synced 2025-03-22 23:28:46 +00:00
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:
parent
845c2842b5
commit
0a367bfbda
11 changed files with 54 additions and 4 deletions
3
.github/workflows/tests.yml
vendored
3
.github/workflows/tests.yml
vendored
|
@ -23,7 +23,8 @@ jobs:
|
||||||
GITHUB_CI=true cargo test --all-features \
|
GITHUB_CI=true cargo test --all-features \
|
||||||
-p std-shims \
|
-p std-shims \
|
||||||
-p zalloc \
|
-p zalloc \
|
||||||
-p serai-db
|
-p serai-db \
|
||||||
|
-p serai-env
|
||||||
|
|
||||||
test-crypto:
|
test-crypto:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -8653,6 +8653,10 @@ dependencies = [
|
||||||
"rocksdb",
|
"rocksdb",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serai-env"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serai-in-instructions-pallet"
|
name = "serai-in-instructions-pallet"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -8699,6 +8703,7 @@ dependencies = [
|
||||||
"rocksdb",
|
"rocksdb",
|
||||||
"schnorr-signatures",
|
"schnorr-signatures",
|
||||||
"serai-db",
|
"serai-db",
|
||||||
|
"serai-env",
|
||||||
"serai-primitives",
|
"serai-primitives",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -8800,6 +8805,7 @@ dependencies = [
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"serai-client",
|
"serai-client",
|
||||||
"serai-db",
|
"serai-db",
|
||||||
|
"serai-env",
|
||||||
"serai-message-queue",
|
"serai-message-queue",
|
||||||
"serai-processor-messages",
|
"serai-processor-messages",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -3,6 +3,7 @@ members = [
|
||||||
"common/std-shims",
|
"common/std-shims",
|
||||||
"common/zalloc",
|
"common/zalloc",
|
||||||
"common/db",
|
"common/db",
|
||||||
|
"common/env",
|
||||||
|
|
||||||
"crypto/transcript",
|
"crypto/transcript",
|
||||||
|
|
||||||
|
|
13
common/env/Cargo.toml
vendored
Normal file
13
common/env/Cargo.toml
vendored
Normal 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
15
common/env/LICENSE
vendored
Normal 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
8
common/env/src/lib.rs
vendored
Normal 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()
|
||||||
|
}
|
|
@ -43,6 +43,8 @@ allow-osi-fsf-free = "neither"
|
||||||
default = "deny"
|
default = "deny"
|
||||||
|
|
||||||
exceptions = [
|
exceptions = [
|
||||||
|
{ allow = ["AGPL-3.0"], name = "serai-env" },
|
||||||
|
|
||||||
{ allow = ["AGPL-3.0"], name = "ethereum-serai" },
|
{ allow = ["AGPL-3.0"], name = "ethereum-serai" },
|
||||||
|
|
||||||
{ allow = ["AGPL-3.0"], name = "serai-message-queue" },
|
{ allow = ["AGPL-3.0"], name = "serai-message-queue" },
|
||||||
|
|
|
@ -35,6 +35,8 @@ tokio = { version = "1", features = ["full"] }
|
||||||
serai-db = { path = "../common/db", features = ["rocksdb"] }
|
serai-db = { path = "../common/db", features = ["rocksdb"] }
|
||||||
rocksdb = "0.21"
|
rocksdb = "0.21"
|
||||||
|
|
||||||
|
serai-env = { path = "../common/env" }
|
||||||
|
|
||||||
serai-primitives = { path = "../substrate/primitives" }
|
serai-primitives = { path = "../substrate/primitives" }
|
||||||
|
|
||||||
jsonrpsee = { version = "0.16", features = ["server"] }
|
jsonrpsee = { version = "0.16", features = ["server"] }
|
||||||
|
|
|
@ -100,10 +100,10 @@ fn ack_message(service: Service, id: u64, _signature: SchnorrSignature<Ristretto
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// Open the DB
|
// Open the DB
|
||||||
let db =
|
let db =
|
||||||
Arc::new(rocksdb::TransactionDB::open_default(std::env::var("DB_PATH").unwrap()).unwrap());
|
Arc::new(rocksdb::TransactionDB::open_default(serai_env::var("DB_PATH").unwrap()).unwrap());
|
||||||
|
|
||||||
let read_key = |str| {
|
let read_key = |str| {
|
||||||
let Ok(key) = std::env::var(str) else { None? };
|
let Ok(key) = serai_env::var(str) else { None? };
|
||||||
|
|
||||||
let mut repr = <<Ristretto as Ciphersuite>::G as GroupEncoding>::Repr::default();
|
let mut repr = <<Ristretto as Ciphersuite>::G as GroupEncoding>::Repr::default();
|
||||||
repr.as_mut().copy_from_slice(&hex::decode(key).unwrap());
|
repr.as_mut().copy_from_slice(&hex::decode(key).unwrap());
|
||||||
|
|
|
@ -55,6 +55,7 @@ log = "0.4"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
|
||||||
serai-db = { path = "../common/db", default-features = false }
|
serai-db = { path = "../common/db", default-features = false }
|
||||||
|
serai-env = { path = "../common/env" }
|
||||||
serai-client = { path = "../substrate/client", default-features = false }
|
serai-client = { path = "../substrate/client", default-features = false }
|
||||||
|
|
||||||
messages = { package = "serai-processor-messages", path = "./messages" }
|
messages = { package = "serai-processor-messages", path = "./messages" }
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
|
||||||
time::Duration,
|
time::Duration,
|
||||||
collections::{VecDeque, HashMap},
|
collections::{VecDeque, HashMap},
|
||||||
};
|
};
|
||||||
|
@ -25,6 +24,8 @@ use serai_client::{
|
||||||
|
|
||||||
use messages::{SubstrateContext, CoordinatorMessage, ProcessorMessage};
|
use messages::{SubstrateContext, CoordinatorMessage, ProcessorMessage};
|
||||||
|
|
||||||
|
use serai_env as env;
|
||||||
|
|
||||||
mod plan;
|
mod plan;
|
||||||
pub use plan::*;
|
pub use plan::*;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue