dwyl / dwyl/learn-environment-variables
Multi-line Environment Variables e.g: RSA Private Keys
- Dominant language
- JavaScript
- Stars
- 206
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Description
One of our Apps [`github-backup`](https://github.com/dwyl/github-backup) requires the use of an RSA Private Key as an environment variable:

e.g:

simply copy-pasting the key from the `.pem` into an `.env` file or attempting to export it in the terminal e.g:
```text
export PRIVATE_KEY=-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA04up8hoqzS1+
...
l48DlnUtMdMrWvBlRFPzU+hU9wDhb3F0CATQdvYo2mhzyUs8B1ZSQz2Vy==
-----END RSA PRIVATE KEY-----
```
Does not work ... because of the line breaks.
I did a bit of googling but did not find a workable solution ...
e.g: https://stackoverflow.com/questions/43082918/how-to-sett-multiline-rsa-private-key-environment-variable-for-aws-elastic-beans

Error:
```
-----END RSA PRIVATE KEY-----': not a valid identifier
```
followed the instructions in: http://blog.vawter.com/2016/02/10/Create-an-Environment-Variable-from-a-Private-Key
Created a file called `keytoenvar.sh` with the following lines:
```bash
#!/usr/bin/env bash
file=$2
name=$1
export $name="$(awk 'BEGIN{}{out=out$0"\n"}END{print out}' $file| sed 's/\n$//')"
```

then ran the following command:
```sh
source keytoenvar.sh PRIVATE_KEY ./gitbu.2018-03-23.private-key.pem
```
That _works_ but it seems like a "_long-winded_" approach ... 🤔
Does anyone know of a _simpler_ way of doing this?
(_I'm trying to make it as "**beginner friendly**" as possible..._)
@SimonLab / @Cleop relates to GitBu environment variables specifically the GitHub App `PRIVATE_KEY`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.