Comments (6)
@cjlarose looks like it works, really appreciate your quick help, thank you!
from config.
config
will evaluate the YAML file as ERB first, then evaluate the result as YAML. This means that after ERB evaluation, if you want to use multiline strings, they must be encoded in a YAML-friendly way.
For example, your YAML starts off like this:
ecdsa_key: "<%= ENV['ECDSA_KEY'] %>"
Assuming ENV['ECDSA_KEY'] == "hello\nhi\n"
, after ERB evaluation, that ends up looking like
ecdsa_key: "hello
hi
"
config
just takes the result of ERB evaluation and puts it through YAML.load
, so if we load the resulting YAML file, we end up with a Hash that looks like
{"ecdsa_key"=>"hello hi "}
This is basically just because of how YAML string literals are defined to work.
To resolve your issue, I suggest either modifying your YAML file to format the resulting string as a YAML multiline string:
ecdsa_key: |-
<%= ENV['ECDSA_KEY'].gsub(/^/, " " * 2) %>
...which produces
ecdsa_key: |-
hello
hi
...and parses as
{"ecdsa_key"=>"hello\nhi"}
Or alternatively, just using the built-in support for ENV vars provided by config
(there's no need to go from ENV -> YAML -> config
since config
can read ENV directly)
from config.
@cjlarose Thank you for the quick reply.
I'm afraid recovering the private key value using .gsub
is not a reliable solution.
as for built-in support for ENV vars provided by config, how can I validate that the value is present with no use YAML?
from config.
how can I validate that the value is present with no use YAML?
If you'd like to validate that a value was specified for your ecdsa_key, I'd recommend adding a validation contract. Your contract can ensure that a value is specified.
from config.
@cjlarose Thanks for the advice
There is a contract, you can see in the given data above config.validation_contract = ConfigValidation.new
but the problem is the same if, by the reason of using ENV directly, as you have suggested, I do not put the key in the YAML files and at the same time add the presence validation to the validation contract, then the validation will always fail.
Do I understand you correctly you're suggesting using ENV directly and at the same time keep in ecdsa_key: "<%=ENV['ECDSA_KEY']%>
in settings.yml
just for the purpose of the validation?
from config.
Do I understand you correctly you're suggesting using ENV directly and at the same time keep in
ecdsa_key: "<%=ENV['ECDSA_KEY']%>
?settings.yml
just for the purpose of the validation?
Not quite. If you're using ENV directly, it's not necessary to keep anything in the YAML files related to the ECDSA key. Given your configuration, you'd set the ENV var Settings.ecdsa_key
or SETTINGS.ECDSA_KEY
to your key. The validation contract is executed after loading the YAML files and reading ENV vars, so the validation contract should only fail if the ENV var was not specified in your case.
from config.
Related Issues (20)
- Ways to reload config of a running process? HOT 1
- Is it possible to reference another configuration in a YAML file? HOT 2
- Pioneer's question HOT 1
- Preserve newlines while using embedded Ruby HOT 2
- Error using Ruby 3.1.0 : Psych::DisallowedClass: Tried to load unspecified class: Time HOT 2
- avoid Hash monkey patch when loading DeepMerge HOT 2
- Hash sources get clobbered in `Settings.reload!` HOT 1
- ENV variables not loaded with config HOT 12
- Compability with Rails engine HOT 3
- Feature Request: Rake Task to generate env-file HOT 1
- Help with beef please HOT 1
- Released Version 4.1.0 still uses removed method `File.exists?` HOT 7
- minimum, maximum keys are conflicted with active_support methods. HOT 8
- Extend Rails integration to application HOT 3
- Environment variables not loaded anymore after upgrading to Rails 6.1.7.3 HOT 2
- How to use/mock in rspec? HOT 3
- Allow to use custom filename && directory name to store configs HOT 2
- Converting to hash is creating an error (Ruby 3.2.2, config 5.0, Rails 6.1) HOT 1
- Rails integration does not allow multiple YAML files to be specified in the first load HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.