-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add support for fetcing private key from an environment variable #40
base: master
Are you sure you want to change the base?
Conversation
This looks tentatively ok to me, but any reason you think this library should handle something from the environment when it could be easily handled from the application? If we do decide to merge it (it’s a minor change) what’s your thoughts on adding some error handling in case the env variable is empty? Then I’d see a little more value as we’d be able to return an appropriate error without the calling app having to also handle that. |
Fetching from env became a need as I'm developing a little lambda API that uses the private key to authenticate and I don't want to package the key in app for sec reasons. I'll add some logic to check if the env is empty 😎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry just on mobile, but “if !ok” is probably better.
I still don’t see exactly why this needs to be done within the library, your explanation was sound, storing these in environment is perfectly acceptable for many reasons, but I’d have thought the application itself should have been handling all this.
Having said that, we do handle opening from file for the user, so it seems ok to open from environment too. If you could make that minor change I’ll merge.
Thank you for the contribution and time you spent on this.
And thank you for making my life a lot easier with this lib! |
I would +1 this. I'm in the same boat, running a GitHub webhook on AWS Lambda. My current hack is to read pass the key into an environment variable for the lambda, and then writing that out to a file before running |
Any updates regarding this? I can provide hands-on help if needed to get this merged :) I'm currently in a similar situation with a hacky solution (read the file's content from a k8s secret, write it into a file, then shove it down to |
FWIW, to support environment variables you can do something like: itr, err := ghinstallation.New(http.DefaultTransport, appID, installationID, []byte(os.GetEnv("MY_ENV_VAR"))) This PR provides a wrapper around this, but you can still use env variables today without it 🤷 Similar for k8s secrets: s, err := client.Secrets("namespace").Get(ctx, "my-secret", metav1.GetOptions{})
if err != nil {
...
}
itr, err := ghinstallation.New(http.DefaultTransport, appID, installationID, s.Data["my-key"]) (or if you're using file projection you can use |
To be honest, you are absolutely correct! For some reason I had missed this Thanks for pointing this out! |
Add support for fetching private key from an environment variable.