From 5e7dc579ab1c226a27f33dd59c0c88211527875f Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Sat, 17 Dec 2016 11:08:47 -0600 Subject: [PATCH] Authentication creds can be provided via env vars This makes it easier in some contexts like ci tools to provide the credentials to the build. This resolves #135. --- .../ajoberstar/grgit/auth/AuthConfig.groovy | 83 ++++++++++++------- .../grgit/auth/TransportOpUtil.groovy | 2 +- .../grgit/auth/AuthConfigSpec.groovy | 28 ++++--- 3 files changed, 69 insertions(+), 44 deletions(-) diff --git a/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy b/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy index af4d018f..21dbe834 100644 --- a/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/auth/AuthConfig.groovy @@ -50,6 +50,16 @@ import org.ajoberstar.grgit.exception.GrgitException * * *

+ * Hardcoded credentials can alternately be provided with environment variables. + * These take a lower precedence than the system properties, but all other + * considerations are the same. + *

+ * + * + *

* In order to add a non-standard SSH key to use as your credentials, * use the following property. *

@@ -90,14 +100,35 @@ class AuthConfig { static final String SSH_PRIVATE_KEY_OPTION = 'org.ajoberstar.grgit.auth.ssh.private' static final String SSH_SESSION_CONFIG_OPTION_PREFIX = 'org.ajoberstar.grgit.auth.session.config.' + static final String USERNAME_ENV_VAR = 'GRGIT_USER' + static final String PASSWORD_ENV_VAR = 'GRGIT_PASS' + + private final Map props + private final Map env + + private AuthConfig(Map props, Map env) { + this.props = props + this.env = env + } + /** * Set of all authentication options that are allowed in this * configuration. */ - final Set