Use VAULT_TOKEN environment variable if it exists (#45525)

(cherry picked from commit b57f2ff68049a4d86ab37399531616b7ad26cfd9)
This commit is contained in:
Mark Vieira 2019-09-30 15:05:07 -07:00
parent f4e32a5f5f
commit 45605cfd7a
No known key found for this signature in database
GPG Key ID: CA947EF7E6D4B105
1 changed files with 8 additions and 6 deletions

View File

@ -12,14 +12,16 @@ initscript {
boolean USE_ARTIFACTORY=false
['VAULT_ADDR', 'VAULT_ROLE_ID', 'VAULT_SECRET_ID'].each {
if (System.env."$it" == null) {
throw new GradleException("$it must be set!")
}
if (System.getenv('VAULT_ADDR') == null) {
throw new GradleException("You must set the VAULT_ADDR environment variable to use this init script.")
}
final String vaultToken = new Vault(
if (System.getenv('VAULT_ROLE_ID') == null && System.getenv('VAULT_SECRET_ID') == null && System.getenv('VAULT_TOKEN') == null) {
throw new GradleException("You must set either the VAULT_ROLE_ID and VAULT_SECRET_ID environment variables, " +
"or the VAULT_TOKEN environment variable to use this init script.")
}
final String vaultToken = System.getenv('VAULT_TOKEN') ?: new Vault(
new VaultConfig()
.address(System.env.VAULT_ADDR)
.engineVersion(1)