Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve ~ or $HOME when using get_env's default fallback #314

Open
dbowling opened this issue Jan 13, 2025 · 0 comments
Open

Unable to resolve ~ or $HOME when using get_env's default fallback #314

dbowling opened this issue Jan 13, 2025 · 0 comments

Comments

@dbowling
Copy link

We use an environment variable to define where to look up the file for the dotenv provider.

We want to set this to default to a specific location in the users home directory (e.g. ~/default.env) but Teller does not expand ~ or $HOME.

Example (does not work):

providers:
  dotenv:
    kind: dotenv
    maps:
      - id: default
        path: >-
          {{ get_env(
            name="TELLER_ENV_FILE",default="~/default.env")
          }}

The following error is given via the CLI, even when ~/default.env exists:

$ teller show
Error: failed to open file `~/default.env`

Caused by:
    No such file or directory (os error 2)

Location:
    /private/tmp/teller-20240519-8895-wwtpqa/teller-2.0.7/teller-cli/src/cli.rs:296:23

It would be great if Teller could parse the default value in order to resolve at least the home directory of the user.

Workarounds

Require the user to define the environment variable

This is not ideal since it requires extra setup by default.

Use Tera template engine

I've found that I can rewrite the .teller.yml file with Terra. My new teller config ends up looking like this:

# {% set home_dir = get_env(name="HOME") -%}
# {% set default_teller_file = home_dir ~ 'default.env' %}

providers:
  dotenv:
    kind: dotenv
    maps:
      - id: default
        path: >-
          {{ get_env(
            name="TELLER_ENV_FILE",default=default_teller_file)
          }}

This does indeed work, since it requires no interpolation.

Note: I added #'s before each of the set lines because it isn't valid yaml and my IDE kept complaining.

Conclusion

If Teller is interested in supporting variable expansion, that would solve this issue nicely.

If not, then the Terra template workaround can work to solve this problem, but there is no clear path to guide a Teller user on how to do this (as a non-rust user, it took me some effort to even figure out that Terra parses the config file.) The documentation could be updated with such a strategy.

If you are interested in a PR being contributed to document the technique, I'd be happy to provide one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant