OSC / ood_appkit

https://osc.github.io/Open-OnDemand/
MIT License
1 stars 2 forks source link

Add custom config_for method #50

Closed ericfranz closed 4 years ago

ericfranz commented 6 years ago

See https://apidock.com/rails/Rails/Application/config_for

The code:

  1. finds the first config path in paths["config"] that exists, and looks for the config specified by the name argument to config_for
  2. loads via ERB then YAML, and returns the hash from the key Rails.env

Two problems here:

  1. The result is that if you have options that should appear in all envs you have to do something like this:

    default: &default
      service_url: https://my_service.example.com
    development:
      <<: *default
    test:
      <<: *default
    production:
      service_url: <%= ENV['APP_SERVICE_URL'] %>
  2. If we add /etc/ to the paths["config"], only /etc will ever be used, or only the root of the app

A custom config_for could do two things differently:

  1. load default first, and then load env, so the yaml anchoring is redundant and can be removed. Thus the example above would be reduced to:

    default:
      service_url: https://my_service.example.com
    production:
      service_url: <%= ENV['APP_SERVICE_URL'] %>
  2. Search for configs in both /etc/ and root of the app (i.e. all of the paths in config). So if the root config appears, use that, otherwise, use /etc/

Such a method could be useful inside Configuration objects that individual OOD apps use.

ericfranz commented 4 years ago

Not doing.