Skip to content

Commit 2be6b68

Browse files
committed
feat: inventory on fromenv
1 parent 62ca5cb commit 2be6b68

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "init4-bin-base"
44
description = "Internal utilities for binaries produced by the init4 team"
55
keywords = ["init4", "bin", "base"]
66

7-
version = "0.1.3"
7+
version = "0.2.0"
88
edition = "2021"
99
rust-version = "1.81"
1010
authors = ["init4", "James Prestwich"]

src/perms/builders.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ impl Builders {
175175
impl FromEnv for Builders {
176176
type Error = BuilderConfigError;
177177

178+
fn inventory() -> Vec<&'static str> {
179+
let mut v = vec![BUILDERS];
180+
v.extend(SlotAuthzConfig::inventory());
181+
v
182+
}
183+
178184
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
179185
let s = String::from_env_var(BUILDERS)
180186
.map_err(FromEnvErr::infallible_into::<BuilderConfigError>)?;

src/perms/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ impl SlotAuthzConfig {
7676
impl FromEnv for SlotAuthzConfig {
7777
type Error = SlotAuthzConfigError;
7878

79+
fn inventory() -> Vec<&'static str> {
80+
let mut v = vec![BLOCK_QUERY_CUTOFF, BLOCK_QUERY_START];
81+
v.extend(SlotCalculator::inventory());
82+
v
83+
}
84+
7985
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
8086
let calc = SlotCalculator::from_env().map_err(FromEnvErr::from)?;
8187
let block_query_cutoff = u8::from_env_var(BLOCK_QUERY_CUTOFF)

src/utils/calc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ impl SlotCalculator {
125125
impl FromEnv for SlotCalculator {
126126
type Error = SlotCalcEnvError;
127127

128+
fn inventory() -> Vec<&'static str> {
129+
vec![START_TIMESTAMP, SLOT_OFFSET, SLOT_DURATION]
130+
}
131+
128132
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
129133
let start_timestamp = u64::from_env_var(START_TIMESTAMP)
130134
.map_err(|e| e.map(SlotCalcEnvError::StartTimestamp))?;

src/utils/from_env.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ pub trait FromEnv: core::fmt::Debug + Sized + 'static {
9393
/// Error type produced when loading from the environment.
9494
type Error: core::error::Error;
9595

96+
/// Get the environment variable names for this type.
97+
fn inventory() -> Vec<&'static str>;
98+
9699
/// Load from the environment.
97100
fn from_env() -> Result<Self, FromEnvErr<Self::Error>>;
98101
}

src/utils/metrics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ impl From<u16> for MetricsConfig {
4040
impl FromEnv for MetricsConfig {
4141
type Error = std::num::ParseIntError;
4242

43+
fn inventory() -> Vec<&'static str> {
44+
vec![METRICS_PORT]
45+
}
46+
4347
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
4448
match u16::from_env_var(METRICS_PORT).map(Self::from) {
4549
Ok(cfg) => Ok(cfg),

src/utils/otlp.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ pub struct OtelConfig {
110110
impl FromEnv for OtelConfig {
111111
type Error = url::ParseError;
112112

113+
fn inventory() -> Vec<&'static str> {
114+
vec![OTEL_ENDPOINT, OTEL_LEVEL, OTEL_TIMEOUT, OTEL_ENVIRONMENT]
115+
}
116+
113117
fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
114118
// load endpoint from env. ignore empty values (shortcut return None), parse, and print the error if any using inspect_err
115119
let endpoint = Url::from_env_var(OTEL_ENDPOINT).inspect_err(|e| eprintln!("{e}"))?;

0 commit comments

Comments
 (0)