-
Notifications
You must be signed in to change notification settings - Fork 735
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
Modify GitHubBuilder to resolve user credentials from the system environ... #131
Modify GitHubBuilder to resolve user credentials from the system environ... #131
Conversation
Kohsuke Kawaguchi » github-api #237 SUCCESS |
25d60e0
to
7ad908b
Compare
Kohsuke Kawaguchi » github-api #238 SUCCESS |
…ronment Using the Jenkins EnvInject or Credentials Binding Plugins its possible to pass credentials as Environment Variables. Its useful for Github.connect() to be able to directly read the values of the 'login', 'password' and 'oauth' properties directly from the environment. This commit modifies the base Github.connect() method to resolve credentials in two steps: 1. ~/.github credentials file if it exists. 2. login, password or oauth variables from the environment A further fromEnvironment() method is provided to support loading from non-standard variable names. The old Github.connect() method would throw an IOException if the ~/.github file did not exist. Now it will fail silently instead dropping back to the anonymous users access level. Added new unit tests into GitHubTest.
7ad908b
to
4d6c5c1
Compare
Kohsuke Kawaguchi » github-api #239 SUCCESS |
The first version of this pull request tried to resolve the system environment variables through System.getProperties() instead of System.getenv(). I've rewritten the commit in the pull request to read from the environment. I copied some code from stack overflow that is used to modify the in memory environment to test that the GitHubBuilder does resolve the values from the environment properly. |
I hesitate to merge this incase it would break people depending on GitHub.connect() throwing a FileNotFoundException if ~/.github does not exist. I will plan on adding another commit that will check if the connection could be configured using the environment and if not then still throw the file not found exception. |
With the previous change if no credentials were defined Github.connect() would fall back on an anonymous connection. This commit changes the behaviour back to what it was before so that if there are no credentials defined in the ~/.github file and no credentials defined in the environment an IOException is thrown to alert the method caller. The caller can call Github.connectAnonymously() if that scenario is allowed. This should handle most cases unless callers are depending on the FileNotFoundException being specifically thrown instead of an IOException.
Kohsuke Kawaguchi » github-api #242 SUCCESS |
…nment Modify GitHubBuilder to resolve user credentials from the system environ...
...ment
Using the Jenkins EnvInject or Credentials Binding Plugins its possible to
pass credentials as Environment Variables.
Its useful for Github.connect() to be able to directly read the values of the
login, password and oauth properties from the environment.
This commit modifies the base Github.connect() method to resolve credentials
in two steps:
A further fromEnvironment() method is provided to support
loading from non-standard variable names.
The old Github.connect() method would throw an IOException if the ~/.github file
did not exist. Now it will fail silently instead dropping back to the anonymous
users access level.