Giter VIP home page Giter VIP logo

Comments (6)

TimoMoss avatar TimoMoss commented on June 10, 2024 2

@cjlarose looks like it works, really appreciate your quick help, thank you!

from config.

cjlarose avatar cjlarose commented on June 10, 2024

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.

TimoMoss avatar TimoMoss commented on June 10, 2024

@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.

cjlarose avatar cjlarose commented on June 10, 2024

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.

TimoMoss avatar TimoMoss commented on June 10, 2024

@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.

cjlarose avatar cjlarose commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.