0

I have an array of ENV variables defined as below in my .env file:

WEBHOOK_SIGNATURES=
  -value_1
  -value_2
  -value_3

I also have an external_service.yml custom configuration file to which I would like to add this array of values so I can access them via Rails.configuration.x.external_service.webhook_signatures instead of ENV["WEBHOOK_SIGNATURES"]

default: &default
  webhook_signatures: <%= ENV['WEBHOOK_SIGNATURES'] %>

production:
  <<: *default

development:
  <<: *default

test:
  <<: *default

The problem is that Rails.configuration.x.external_service.webhook_signatures is returning nil.

Is there a proper way to define an array of values for a custom configuration file?

EDIT: In the end I defined it in the external_service.yml file as follow:

webhook_signatures: <%= ENV['WEBHOOK_SIGNATURES']&.split(',')&.map(&:strip) %>

It works, effectively converting the multiline variable in the .env to an array of values available using Rails.configuration.x.external_service.webhook_signatures .

If there's a better, less nasty way I'd appreciate the insight.

pinkfloyd90
  • 588
  • 3
  • 17

1 Answers1

0

The dotenv gem does not support YAML format in the .env file. You can use "s to include newlines within your string if you wanted to, and then you can split on the newline, or just separate your values with , or anything else you can rely on not being embedded within your values (then split it as you're already on the path to doing).

smathy
  • 26,283
  • 5
  • 48
  • 68