1- import com.bettercloud.vault.VaultConfig
2- import com.bettercloud.vault.Vault
3-
4- initscript {
5- repositories {
6- mavenCentral()
7- }
8- dependencies {
9- classpath ' com.bettercloud:vault-java-driver:4.1.0'
10- }
11- }
12-
13- boolean USE_ARTIFACTORY = false
14-
15- if (System . getenv(' VAULT_ADDR' ) == null ) {
16- // When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
17- if (System . getenv(' CI' ) == null ) {
18- return
19- }
20-
21- throw new GradleException (" You must set the VAULT_ADDR environment variable to use this init script." )
22- }
23-
24- if (System . getenv(' VAULT_ROLE_ID' ) == null && System . getenv(' VAULT_SECRET_ID' ) == null && System . getenv(' VAULT_TOKEN' ) == null ) {
25- // When trying to reproduce errors outside of CI, it can be useful to allow this to just return rather than blowing up
26- if (System . getenv(' CI' ) == null ) {
27- return
28- }
29-
30- throw new GradleException (" You must set either the VAULT_ROLE_ID and VAULT_SECRET_ID environment variables, " +
31- " or the VAULT_TOKEN environment variable to use this init script." )
32- }
33-
34- final String vaultPathPrefix = System . getenv(' VAULT_ADDR' ) ==~ / .+vault-ci.+\. dev.*/ ? " secret/ci/elastic-elasticsearch/migrated" : " secret/elasticsearch-ci"
35-
36- final String vaultToken = System . getenv(' VAULT_TOKEN' ) ?: new Vault (
37- new VaultConfig ()
38- .address(System . env. VAULT_ADDR )
39- .engineVersion(1 )
40- .build()
41- )
42- .withRetries(5 , 1000 )
43- .auth()
44- .loginByAppRole(" approle" , System . env. VAULT_ROLE_ID , System . env. VAULT_SECRET_ID )
45- .getAuthClientToken()
46-
47- final Vault vault = new Vault (
48- new VaultConfig ()
49- .address(System . env. VAULT_ADDR )
50- .engineVersion(1 )
51- .token(vaultToken)
52- .build()
53- )
54- .withRetries(5 , 1000 )
55-
56-
57- if (USE_ARTIFACTORY ) {
58- final Map<String , String > artifactoryCredentials = vault. logical()
59- .read(" ${ vaultPathPrefix} /artifactory.elstc.co" )
60- .getData()
61- logger. info(" Using elastic artifactory repos" )
62- Closure configCache = {
63- return {
64- name " artifactory-gradle-release"
65- url " https://artifactory.elstc.co/artifactory/gradle-release"
66- credentials {
67- username artifactoryCredentials. get(" username" )
68- password artifactoryCredentials. get(" token" )
69- }
70- }
71- }
72- settingsEvaluated { settings ->
73- settings. pluginManagement {
74- repositories {
75- maven configCache()
76- }
77- }
78- }
79- projectsLoaded {
80- allprojects {
81- buildscript {
82- repositories {
83- maven configCache()
84- }
85- }
86- repositories {
87- maven configCache()
88- }
89- }
90- }
91- }
92-
931gradle. settingsEvaluated { settings ->
942 settings. pluginManager. withPlugin(" com.gradle.develocity" ) {
953 settings. develocity {
@@ -98,14 +6,10 @@ gradle.settingsEvaluated { settings ->
986 }
997}
1008
101-
1029final String buildCacheUrl = System . getProperty(' org.elasticsearch.build.cache.url' )
10310final boolean buildCachePush = Boolean . valueOf(System . getProperty(' org.elasticsearch.build.cache.push' , ' false' ))
10411
10512if (buildCacheUrl) {
106- final Map<String , String > buildCacheCredentials = System . getenv(" GRADLE_BUILD_CACHE_USERNAME" ) ? [:] : vault. logical()
107- .read(" ${ vaultPathPrefix} /gradle-build-cache" )
108- .getData()
10913 gradle. settingsEvaluated { settings ->
11014 settings. buildCache {
11115 local {
@@ -116,11 +20,10 @@ if (buildCacheUrl) {
11620 url = buildCacheUrl
11721 push = buildCachePush
11822 credentials {
119- username = System . getenv(" GRADLE_BUILD_CACHE_USERNAME" ) ?: buildCacheCredentials . get( " username " )
120- password = System . getenv(" GRADLE_BUILD_CACHE_PASSWORD" ) ?: buildCacheCredentials . get( " password " )
23+ username = System . getenv(" GRADLE_BUILD_CACHE_USERNAME" )
24+ password = System . getenv(" GRADLE_BUILD_CACHE_PASSWORD" )
12125 }
12226 }
12327 }
12428 }
12529}
126-
0 commit comments