Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit f58bd6a

Browse files
committed
Allow innit to take in env variables
This changes allows innit to take in env variables. This can be configured by environment variable or command line argument with the new "mode" type. It contains two variants: "env" and "ssm". If the mode is not provided, it defaults to "ssm", which ensures innit runs as it does on main today. If "env" is provided, then innit will take in environment variables to configure all services rather than using ssm. The environment variable use case may not be that interesting on its own, but innit being able to be used across several verticals and cloud providers in the future helps standardize the SI initialization procedure. Theorhetically, a secrets manager provided by a helm chart on a k8s cluster can do the same thing. For now, innit's env var use case is valuable. We'll see how long that will remain to be the case. Signed-off-by: Nick Gerace <nick@systeminit.com>
1 parent b9cd8d4 commit f58bd6a

File tree

21 files changed

+373
-59
lines changed

21 files changed

+373
-59
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/innit/src/args.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use innit_server::{
88
Config,
99
ConfigError,
1010
ConfigFile,
11+
Mode,
1112
StandardConfigFile,
1213
};
1314
use si_service::prelude::*;
@@ -78,6 +79,15 @@ pub(crate) struct Args {
7879
/// The address and port to bind the HTTP server to [example: 0.0.0.0:80]
7980
#[arg(long, env)]
8081
pub(crate) socket_addr: Option<String>,
82+
83+
/// Mode for parameter storage backend [options: env, ssm]
84+
#[arg(
85+
long = "mode",
86+
env = "SI_INNIT_MODE",
87+
default_value = "ssm",
88+
hide_env_values = true
89+
)]
90+
pub(crate) mode: Mode,
8191
}
8292

8393
impl TryFrom<Args> for Config {
@@ -91,6 +101,7 @@ impl TryFrom<Args> for Config {
91101
if let Some(socket_addr) = args.socket_addr {
92102
config_map.set("socket_addr", socket_addr);
93103
}
104+
config_map.set("mode", args.mode.to_string());
94105
})?
95106
.try_into()
96107
}

lib/bedrock-server/src/routes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde_json::{
1515
Value,
1616
json,
1717
};
18-
use si_data_ssm::ParameterStoreClientError;
18+
use si_data_ssm::SsmParameterStoreClientError;
1919
use thiserror::Error;
2020

2121
use super::{
@@ -62,7 +62,7 @@ pub fn public_routes(state: AppState) -> Router {
6262
#[derive(Debug, Error)]
6363
pub enum AppError {
6464
#[error("parameter store client error: {0}")]
65-
ParameterStoreClient(#[from] ParameterStoreClientError),
65+
ParameterStoreClient(#[from] SsmParameterStoreClientError),
6666
#[error("server error: {0}")]
6767
Server(#[from] ServerError),
6868
}

lib/innit-core/BUCK

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ rust_library(
44
name = "innit-core",
55
deps = [
66
"//lib/config-file:config-file",
7-
87
"//third-party/rust:aws-sdk-ssm",
9-
"//third-party/rust:chrono",
10-
"//third-party/rust:serde",
11-
"//third-party/rust:serde_json",
12-
"//third-party/rust:ulid"
8+
"//third-party/rust:serde"
139
],
1410
srcs = glob([
1511
"src/**/*.rs",

lib/innit-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ rust-version.workspace = true
99
publish.workspace = true
1010

1111
[dependencies]
12-
aws-sdk-ssm = { workspace = true }
1312
config-file = { path = "../../lib/config-file" }
1413
serde = { workspace = true }

lib/innit-core/src/lib.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use aws_sdk_ssm::types::{
2-
Parameter as AwsParameter,
3-
ParameterType as AwsParameterType,
4-
};
51
use config_file::parameter_provider::{
62
Parameter as ParameterProviderParameter,
73
ParameterType as ParameterProviderParameterType,
@@ -18,19 +14,6 @@ pub struct Parameter {
1814
pub r#type: Option<ParameterType>,
1915
}
2016

21-
impl From<AwsParameter> for Parameter {
22-
fn from(p: AwsParameter) -> Self {
23-
Self {
24-
name: p.name().unwrap_or_default().to_string(),
25-
value: p.value().map(|s| s.to_string()),
26-
r#type: p.r#type().map(|t| match t {
27-
AwsParameterType::StringList => ParameterType::StringList,
28-
_ => ParameterType::String,
29-
}),
30-
}
31-
}
32-
}
33-
3417
impl From<Parameter> for ParameterProviderParameter {
3518
fn from(p: Parameter) -> Self {
3619
Self {

lib/innit-server/BUCK

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ rust_library(
1010
"//lib/si-settings:si-settings",
1111
"//lib/si-std:si-std",
1212
"//lib/si-tls:si-tls",
13-
1413
"//lib/telemetry-rs:telemetry",
14+
"//third-party/rust:async-trait",
15+
"//third-party/rust:aws-sdk-ssm",
1516
"//third-party/rust:axum",
1617
"//third-party/rust:dashmap",
1718
"//third-party/rust:derive_builder",
@@ -21,6 +22,7 @@ rust_library(
2122
"//third-party/rust:remain",
2223
"//third-party/rust:serde",
2324
"//third-party/rust:serde_json",
25+
"//third-party/rust:strum",
2426
"//third-party/rust:thiserror",
2527
"//third-party/rust:tokio",
2628
"//third-party/rust:tokio-rustls",

lib/innit-server/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rust-version.workspace = true
99
publish.workspace = true
1010

1111
[dependencies]
12+
async-trait = { workspace = true }
1213
axum = { workspace = true }
1314
buck2-resources = { path = "../../lib/buck2-resources" }
1415
dashmap = { workspace = true }
@@ -24,6 +25,7 @@ si-data-ssm = { path = "../../lib/si-data-ssm" }
2425
si-settings = { path = "../../lib/si-settings" }
2526
si-std = { path = "../../lib/si-std" }
2627
si-tls = { path = "../../lib/si-tls" }
28+
strum = { workspace = true }
2729
telemetry = { path = "../../lib/telemetry-rs" }
2830
thiserror = { workspace = true }
2931
tokio = { workspace = true }

lib/innit-server/src/app_state.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use axum::extract::FromRef;
2-
use si_data_ssm::ParameterStoreClient;
32
use tokio_util::sync::CancellationToken;
43

5-
use crate::parameter_cache::ParameterCache;
4+
use crate::{
5+
parameter_cache::ParameterCache,
6+
parameter_storage::ParameterStore,
7+
};
68

79
#[remain::sorted]
810
#[derive(Debug, Eq, PartialEq)]
@@ -11,20 +13,20 @@ pub enum ShutdownSource {}
1113
#[derive(Clone, Debug, FromRef)]
1214
pub struct AppState {
1315
pub parameter_cache: ParameterCache,
14-
pub parameter_store_client: ParameterStoreClient,
16+
pub parameter_storage: ParameterStore,
1517
shutdown_token: CancellationToken,
1618
}
1719

1820
impl AppState {
1921
#[allow(clippy::too_many_arguments)]
2022
pub fn new(
2123
parameter_cache: ParameterCache,
22-
parameter_store_client: ParameterStoreClient,
24+
parameter_storage: ParameterStore,
2325
shutdown_token: CancellationToken,
2426
) -> Self {
2527
Self {
2628
parameter_cache,
27-
parameter_store_client,
29+
parameter_storage,
2830
shutdown_token,
2931
}
3032
}

lib/innit-server/src/config.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use si_std::{
1919
CanonicalFileError,
2020
};
2121
use si_tls::CertificateSource;
22+
use strum::{
23+
Display,
24+
EnumString,
25+
};
2226
use telemetry::prelude::*;
2327
use thiserror::Error;
2428
use ulid::Ulid;
@@ -49,7 +53,19 @@ impl ConfigError {
4953

5054
type Result<T> = std::result::Result<T, ConfigError>;
5155

52-
/// The config for the forklift server.
56+
#[remain::sorted]
57+
#[derive(
58+
Debug, Default, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, EnumString, Display,
59+
)]
60+
#[serde(rename_all = "lowercase")]
61+
#[strum(serialize_all = "lowercase")]
62+
pub enum Mode {
63+
Env,
64+
#[default]
65+
Ssm,
66+
}
67+
68+
/// The config for the server.
5369
#[derive(Debug, Builder)]
5470
pub struct Config {
5571
#[builder(default = "default_cache_ttl()")]
@@ -78,6 +94,9 @@ pub struct Config {
7894

7995
#[builder(default)]
8096
dev_mode: bool,
97+
98+
#[builder(default = "Mode::default()")]
99+
mode: Mode,
81100
}
82101

83102
impl StandardConfig for Config {
@@ -124,6 +143,10 @@ impl Config {
124143
pub fn client_ca_arns(&self) -> Option<&Vec<String>> {
125144
self.client_ca_arns.as_ref()
126145
}
146+
147+
pub fn mode(&self) -> Mode {
148+
self.mode
149+
}
127150
}
128151

129152
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -147,6 +170,9 @@ pub struct ConfigFile {
147170

148171
#[serde(default)]
149172
pub dev_mode: bool,
173+
174+
#[serde(default)]
175+
mode: Mode,
150176
}
151177

152178
impl Default for ConfigFile {
@@ -161,6 +187,7 @@ impl Default for ConfigFile {
161187
socket_addr: get_default_socket_addr(),
162188
test_endpoint: default_test_endpoint(),
163189
dev_mode: false,
190+
mode: Mode::default(),
164191
}
165192
}
166193
}
@@ -182,6 +209,7 @@ impl TryFrom<ConfigFile> for Config {
182209
config.instance_id(value.instance_id);
183210
config.quiescent_period(Duration::from_secs(value.quiescent_period_secs));
184211
config.dev_mode(value.dev_mode);
212+
config.mode(value.mode);
185213
config.build().map_err(Into::into)
186214
}
187215
}

0 commit comments

Comments
 (0)