Class ConfigUtils

java.lang.Object
ubic.gemma.core.config.ConfigUtils

public final class ConfigUtils extends Object
Shared configuration helpers.

Implements the *_FILE indirection pattern used by Postgres, Redis, Mongo containers and by systemd's LoadCredential= mechanism: for any env var FOO, if a sibling FOO_FILE is set, its value is treated as a path whose contents (trimmed) become the resolved value. If FOO_FILE is unset, fall back to FOO directly.

This lets a podman Quadlet on Rocky Linux do:

    [Service]
    LoadCredential=db.password:/etc/gemma/db.password
    Environment=GEMMA_DB_PASSWORD_FILE=%d/db.password
and have the Java side pick the secret up without it ever appearing in process env or systemctl show output.

Failure is fail-fast: a _FILE pointer to a missing or unreadable file throws IllegalStateException at startup rather than silently falling through to the bare env var.

  • Field Details

    • FILE_INDIRECTION_SUFFIX

      public static final String FILE_INDIRECTION_SUFFIX
      Suffix appended to an env-var name to indicate "value lives in this file on disk".
      See Also:
  • Method Details

    • resolveEnvVar

      @Nullable public static String resolveEnvVar(String name)
      Resolve an environment variable, honouring the *_FILE indirection pattern.
      Parameters:
      name - env-var name, e.g. GEMMA_DB_PASSWORD
      Returns:
      the resolved value (from <name>_FILE contents if set, else from <name>), or null if neither is set
      Throws:
      IllegalStateException - if <name>_FILE is set but the file cannot be read
    • resolveEnvVar

      @Nullable public static String resolveEnvVar(String name, Function<String,String> envSource)
      Test-friendly form: resolve against an arbitrary env source instead of System.getenv().

      Useful for unit tests since System.setenv() is not supported on most JVMs.