Modify GitHubBuilder to resolve user credentials from the system environment

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.
This commit is contained in:
Michael O'Cleirigh
2014-09-29 11:41:14 -04:00
parent d228a5fb93
commit 4d6c5c14f1
3 changed files with 184 additions and 5 deletions

View File

@@ -128,10 +128,10 @@ public class GitHub {
}
/**
* Obtains the credential from "~/.github"
* Obtains the credential from "~/.github" or from the System Environment Properties.
*/
public static GitHub connect() throws IOException {
return GitHubBuilder.fromPropertyFile().build();
return GitHubBuilder.fromCredentials().build();
}
/**