Skip to content

Profile support #6

@ArtemGet

Description

@ArtemGet

I would like to add support for profiles:
src\resources\application.yaml

profile: {MY_PROFILE:local}
db:
  url: {DB_URL}
  login: {DB_LOGIN}
  pass: {DB_PASS}

src\resources\application-local.yaml

db:
  url: my URL for local development  
  login: my login for local development  
  pass: my password for local development  

The idea is that when retrieving a parameter, we take the value not from the main config file but from the file specified in the profile.

Currently, to achieve this functionality, we'd have to write something like:

String dbUrl = new EVal(
    "db.url",
    String.format(
        "src/resources/application-%s.yaml",
        new EVal("profile").value()
    )
).value();

In general, things could get even worse because here we can't tell whether a profile exists or if the user forgot to specify its value (or if the value isn't set in the environment).

Ideally, I'd like to see something like:

String dbUrl = new EValProf("db.url").value();

or

String dbUrl = new EValProf("db.url", "path_to_application.yaml").value();

And, of course, error handling needs to be taken care of:

  • If the profile attribute is missing in application.yaml, simply fetch the attribute as usual—from application.yaml.
  • If the profile attribute exists but its value is empty (or if it references an environment variable with no default value and that variable is empty), throw a clear error to the user when value() is called.
  • If the profile attribute exists, reuse the EVal class with the new path (as described at the beginning) and retrieve the desired value from the appropriate YAML file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions