Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid value #45

Open
emtudo opened this issue Jun 16, 2021 · 6 comments
Open

Invalid value #45

emtudo opened this issue Jun 16, 2021 · 6 comments

Comments

@emtudo
Copy link

emtudo commented Jun 16, 2021

I try read private key

example:

-----BEGIN EC PRIVATE KEY-----\ncontent\n-----END EC PRIVATE KEY-----

And i received no valid valor, because valor "\n" is replace to "\\n"

@iloveitaly
Copy link
Collaborator

@emtudo could you post the code that is causing the issue?

@emtudo
Copy link
Author

emtudo commented Jun 16, 2021

config :starkbank,
  language: "pt-BR",
  project: [
    environment: :sandbox,
    id: System.get_env("STARKBANK_PROJECT_ID"),
    private_key: System.get_env("STARKBANK_PROJECT_PRIVATE_KEY")
  ],
  organization: [
    environment: :sandbox,
    id: System.get_env("STARKBANK_ORGANIZATION_ID"),
    private_key: System.get_env("STARKBANK_ORGANIZATION_PRIVATE_KEY")
  ]

System.get_env("STARKBANK_ORGANIZATION_PRIVATE_KEY") and System.get_env("STARKBANK_PROJECT_PRIVATE_KEY")

has invalid value. When I see values, has two , and has invalid value.

@emtudo
Copy link
Author

emtudo commented Jun 16, 2021

By the way, thanks for an excellent tool.

Forgive me for not thanking you sooner.

@emtudo
Copy link
Author

emtudo commented Jun 16, 2021

my env, example:


STARKBANK_PROJECT_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----\ncontent\n-----END EC PRIVATE KEY-----"
STARKBANK_ORGANIZATION_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----\ncontent\n-----END EC PRIVATE KEY-----"

@iloveitaly
Copy link
Collaborator

@emtudo Interesting! I'm guessing this code needs to be modified:

def parse_contents(contents) do

Best way to fix this would be writing a failing test for this and then modifying that method to ensure the value is parsed correctly. I don't have the time, but you are welcome to give it a shot!

@grzuy
Copy link

grzuy commented Apr 7, 2022

Facing a similar issue brought me here, but not sure that those escaped newlines are responsibility of dotenv.

In fact, without event using dotenv, just plain iex with env var in the shell command you do get those escaped newline characters:

➜  STARKBANK_PROJECT_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----\ncontent\n-----END EC PRIVATE KEY-----" iex
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1]

Interactive Elixir (1.13.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> System.get_env("STARKBANK_PROJECT_PRIVATE_KEY")
"-----BEGIN EC PRIVATE KEY-----\\ncontent\\n-----END EC PRIVATE KEY-----"

So dotenv stripping those away would be moving away from how shell env var works.

It seems that in order to better support PEM values in env vars, a better option would be supporting something multi-line strings in .env and/or heredocs.

Related: https://stackoverflow.com/questions/70022774/system-get-env-in-elixir-and-new-line-n.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants