palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

can't edit rails credentials with "required" validation #141

Closed uchouhan closed 11 months ago

uchouhan commented 12 months ago

What did you do?

added a rails credential called my_credential added a required :my_credential to the MyConfig class

What did you expect to happen?

be able to edit credential rails credentials:edit -e local

What actually happened?

raises a validation error The following config parameters for MyConfig(config_name: my) are missing or empty: my_credential

Additional context

passing in an environment variable works MY_CREDENTIAL=test rails credentials:edit -e local however, not all our credentials will have environment variables

Environment

Ruby Version: 3.2.2

Framework Version (Rails, whatever): 7.0.8

Anyway Config Version: 2.5.4

Samsinite commented 11 months ago

@uchouhan since bin/rails credentials:edit loads the rails environment, it is going to load the config and run the required validations, causing the error you mentioned if it is not defined. I would imagine the only way around this would be a change the bin/rails command to not call the railties that anyway_config uses, when rails runs credentials:edit.