cphill cphill - 1 month ago 14
Node.js Question

Foreman Multiline ENV Variable Error

I am trying to pass the contents of my pem file as a string in my

.env
file using
\n
to translate the form in the pem file to be used in an ENV variable. The issue, however, is that I'm getting an error from this variable and I'm not sure what it means, but I saw where there was an issue closed allowing for multiline so I'm not sure why this error exists.

Here is my terminal command
nf run nodemon app.js


Here is the version
1.4.1


Here is the format of my pem file set within my .env file:

CF_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n
MIIEpAIBAAKCAQEAm7NA5731034RiKsEkuBTrkoBidwFD7hsdfaiohdsfahsdfL99Iw5R4uTA\n
jpPJTOUHTJNMSNF472h42ofnlNflnriNBTPOHNJFRPNSRPFNSRpfPRNFORNFPRSNFpSNFFPNf\n
-----END RSA PRIVATE KEY-----"


This is the error message:

/Users/user/.nvm/versions/node/v4.3.2/lib/node_modules/foreman/lib/envs.js:38
case '"': return /^"([^"]*)"/.exec(val)[1];
^

TypeError: Cannot read property '1' of null
at parseValue (/Users/user/.nvm/versions/node/v4.3.2/lib/node_modules/foreman/lib/envs.js:38:46)

Answer

I don't think that it can work like that. It seems that node foreman scans the file line by line and it is trying to create key-value pairs and seems that is not aware of \n or other methods that can split the line. I don't think that you have to put it on more lines, though. Possibly you can do something like that:

CF_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAm7NA57......\n...."

and it is quite possible that will not work. Why don't you put just the filename in the env vars? Something like:

CF_PRIVATE_KEY_FILENAME="my-file-id-rsa"

and when you boot the application:

var id_rsa_contents = fs.readFileSync(__dirname + proces.env.CF_PRIVATE_KEY_FILENAME);
Comments