Package ai.mindconnect.common.util
Class EnvVarResolver
java.lang.Object
ai.mindconnect.common.util.EnvVarResolver
Resolves
${VAR_NAME} and ${VAR_NAME:default} placeholders
in string values by looking them up in environment variables.
Rules:
${MY_VAR}— expands to the env var value; throws if absent.${MY_VAR:fallback}— expands to the env var value, orfallbackif the var is not set.- A
nullinput returnsnull. - A value with no placeholders is returned unchanged.
- Multiple placeholders in a single value are all expanded.
"${OPENAI_API_KEY}" or
"${LLM_BASE_URL:http://localhost:11434}".-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsPlaceholder(String value) True ifvaluecontains at least one${VAR}/${VAR:default}placeholder.static StringExpands all${…}placeholders invalueusing environment variables.static StringSame asresolve(String)but accepts an explicit env map — useful for testing without touching real environment variables.
-
Method Details
-
containsPlaceholder
True ifvaluecontains at least one${VAR}/${VAR:default}placeholder. Use this to decide whether a value should be treated as a deferred reference (resolved at use time) rather than a literal — e.g. so a stored secret placeholder is not encrypted. -
resolve
Expands all${…}placeholders invalueusing environment variables. Returnsnullifvalueisnull.- Throws:
IllegalStateException- if a placeholder has no default and the environment variable is not set
-
resolve
Same asresolve(String)but accepts an explicit env map — useful for testing without touching real environment variables.
-