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

Env var values not being loaded without a config file definition #48

Closed
joao-zanutto opened this issue Apr 2, 2024 · 5 comments · Fixed by #54
Closed

Env var values not being loaded without a config file definition #48

joao-zanutto opened this issue Apr 2, 2024 · 5 comments · Fixed by #54
Labels
enhancement New feature or request

Comments

@joao-zanutto
Copy link
Contributor

@wwoytenko I encountered a problem where environment variables are not being loaded if their config isn't defined in a config file. It seems that this is a known Viper issue: spf13/viper#584

I'll come up with a PR to solve this issue, changing the common.tmp_dir default definition.

We can also utilize this PR to set a default behavior for storage config. I see these possible scenarios

  • Define default storage to directory storage on ~/dumps -- this would allow Docker users to map a volume to /home/greenmask/dumps and use it without needing to specify the storage.directory.path configuration
  • Require storage configuration and error out in case none is provided
@wwoytenko
Copy link
Contributor

@joao-zanutto thank you for your research. You're right. We can overcome this issue by manually registering ENV vars. It is completed in #51 . Rebase from the actual main branch and adapt your PR #49 last changes.

About the next points

Define default storage to directory storage on ~/dumps -- this would allow Docker users to map a volume to /home/greenmask/dumps and use it without needing to specify the storage.directory.path configuration

Agree. You can add it into #49

Require storage configuration and error out in case none is provided

Looks like I have done it in #51

@wwoytenko wwoytenko added the enhancement New feature or request label Apr 4, 2024
@joao-zanutto
Copy link
Contributor Author

joao-zanutto commented Apr 4, 2024

@wwoytenko following my previous implementation and your own, we would need to statically bind each env to have it working, however, I was thinking in making the bind dynamically using the Config struct.

I tried a few solution, (like the one described in this comment spf13/viper#584 (comment)) but ended up finding a new build flag we can add to make it work out of the box.

There is a new private function bindStruct() that is being called inside the Unmarshall() function, but since it has some retrocompability issues, it was put behind this -tags=viper_bind_struct build arg. (See spf13/viper#1429)

I already built and test locally and it is working, however it doesn't work for the S3 storage parameters because it's defined as a pointer and the function can't parse it properly (See spf13/viper#1429 (comment)). Is there a chance we can remove the pointer definition se we don't have to statically define each S3 parameter as its own env and bind them individually?

@wwoytenko
Copy link
Contributor

I think you can easily get rid of the pointers. It should work as expected, verify that all is okay and NewConfig function calls correctly

@wwoytenko
Copy link
Contributor

Leave a comment in the code and Makefile as well so we would determine why it uses build flags

@joao-zanutto
Copy link
Contributor Author

I think you can easily get rid of the pointers. It should work as expected, verify that all is okay and NewConfig function calls correctly

I did as you instructed but may have missed something because I cannot make it work correctly and I'm having difficult troubleshooting it. May I have your assistance in #55 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants