pub struct Settings {
pub env: HashMap<String, String>,
pub profiles: HashMap<String, Profile>,
}Expand description
Settings loaded from $HOME/.omni-dev/settings.json.
Fields§
§env: HashMap<String, String>Environment variable overrides — the default bundle, consulted only when no profile is active.
profiles: HashMap<String, Profile>Named profiles. Selecting one replaces the base env in the fallback
chain (isolated / AWS-faithful); see Settings::resolve_with.
Implementations§
Source§impl Settings
impl Settings
Sourcepub fn load_from_path<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load_from_path<P: AsRef<Path>>(path: P) -> Result<Self>
Loads settings from a specific path.
Sourcepub fn get_settings_path() -> Result<PathBuf>
pub fn get_settings_path() -> Result<PathBuf>
Returns the default settings path.
Sourcepub fn get_env_var(&self, key: &str) -> Option<String>
pub fn get_env_var(&self, key: &str) -> Option<String>
Returns an environment variable with fallback to settings, honouring the
active profile from OMNI_DEV_PROFILE.
Sourcepub fn resolve_with<E: EnvSource>(
&self,
raw: &E,
active: Option<&str>,
key: &str,
) -> Option<String>
pub fn resolve_with<E: EnvSource>( &self, raw: &E, active: Option<&str>, key: &str, ) -> Option<String>
Isolated / AWS-faithful resolution: raw (the process environment) wins;
then the active profile’s env if active is set, else the base env.
The base map is not consulted when a profile is active, so a missing
key fails loud rather than silently reusing a default credential against
the wrong tenant.
This is the pure seam: production wrappers pass &SystemEnv; tests pass
a MapEnv and an explicit active, mutating no process-global state.
Sourcepub fn resolve_with_source<E: EnvSource>(
&self,
raw: &E,
active: Option<&str>,
key: &str,
) -> Option<(String, EnvValueSource)>
pub fn resolve_with_source<E: EnvSource>( &self, raw: &E, active: Option<&str>, key: &str, ) -> Option<(String, EnvValueSource)>
Like Settings::resolve_with, but also reports which layer supplied
the value: the raw process environment, the active profile’s env, or
the base env (issue #1143). Same precedence, same profile isolation.
A EnvValueSource::CliFlag attribution is layered on top by
get_env_var_sourced, which knows about flag exports; this resolver
only distinguishes what it can see.
Sourcepub fn upsert_env_vars(path: &Path, vars: &[(&str, &str)]) -> Result<()>
pub fn upsert_env_vars(path: &Path, vars: &[(&str, &str)]) -> Result<()>
Merges the given key/value pairs into the base env object of the
settings file at path — Settings::upsert_env_vars_in with no
profile.
Sourcepub fn upsert_env_vars_in(
path: &Path,
profile: Option<&str>,
vars: &[(&str, &str)],
) -> Result<()>
pub fn upsert_env_vars_in( path: &Path, profile: Option<&str>, vars: &[(&str, &str)], ) -> Result<()>
Merges the given key/value pairs into the env object targeted by
profile — profiles.<name>.env when Some, the base env when
None — creating the file, its parent directory, and any missing
intermediate objects as needed. Writes therefore land where
Settings::resolve_with will look for them (issue #1116).
A profile absent from the file is created rather than rejected; the
CLI validates the active profile before dispatch, so this only affects
library callers.
The file is read and written as a generic JSON value, so every other
field (other profiles, unknown keys) is preserved verbatim. Because the
env maps hold credentials, the write is hardened: parent directory
0700, file 0600 (see [write_settings]).
Sourcepub fn remove_env_vars(path: &Path, keys: &[&str]) -> Result<bool>
pub fn remove_env_vars(path: &Path, keys: &[&str]) -> Result<bool>
Removes the given keys from the base env object of the settings file
at path — Settings::remove_env_vars_in with no profile.
Sourcepub fn remove_env_vars_in(
path: &Path,
profile: Option<&str>,
keys: &[&str],
) -> Result<bool>
pub fn remove_env_vars_in( path: &Path, profile: Option<&str>, keys: &[&str], ) -> Result<bool>
Removes the given keys from the env object targeted by profile
(profiles.<name>.env when Some, the base env when None),
leaving all other settings — including the same keys in other env
maps — intact.
Returns true if any key was present in the targeted map and removed
(the file is rewritten, hardened as in
Settings::upsert_env_vars_in), false when the file did not
exist, the targeted map was absent, or it contained none of the keys
(the file is left untouched).
Sourcepub fn validate_profile(&self, name: &str) -> Result<()>
pub fn validate_profile(&self, name: &str) -> Result<()>
Validates that name is a known profile, returning a hard error that
lists the known profiles (sorted) otherwise. Called once at the CLI
boundary so a typo never silently falls back to base credentials.