@@ -89,18 +89,26 @@ String s3TemporarySessionToken = System.getenv("amazon_s3_session_token_temporar
89
89
String s3TemporaryBucket = System . getenv(" amazon_s3_bucket_temporary" )
90
90
String s3TemporaryBasePath = System . getenv(" amazon_s3_base_path_temporary" )
91
91
92
+ String s3EC2Bucket = System . getenv(" amazon_s3_bucket_ec2" )
93
+ String s3EC2BasePath = System . getenv(" amazon_s3_base_path_ec2" )
94
+
92
95
// If all these variables are missing then we are testing against the internal fixture instead, which has the following
93
96
// credentials hard-coded in.
94
97
95
- if (! s3PermanentAccessKey && ! s3PermanentSecretKey && ! s3PermanentBucket && ! s3PermanentBasePath) {
98
+ if (! s3PermanentAccessKey && ! s3PermanentSecretKey && ! s3PermanentBucket && ! s3PermanentBasePath
99
+ && ! s3EC2Bucket && ! s3EC2BasePath) {
96
100
s3PermanentAccessKey = ' s3_integration_test_permanent_access_key'
97
101
s3PermanentSecretKey = ' s3_integration_test_permanent_secret_key'
98
102
s3PermanentBucket = ' permanent-bucket-test'
99
103
s3PermanentBasePath = ' integration_test'
100
104
105
+ s3EC2Bucket = ' ec2-bucket-test'
106
+ s3EC2BasePath = ' integration_test'
107
+
101
108
useFixture = true
102
109
103
- } else if (! s3PermanentAccessKey || ! s3PermanentSecretKey || ! s3PermanentBucket || ! s3PermanentBasePath) {
110
+ } else if (! s3PermanentAccessKey || ! s3PermanentSecretKey || ! s3PermanentBucket || ! s3PermanentBasePath
111
+ || ! s3EC2Bucket || ! s3EC2BasePath) {
104
112
throw new IllegalArgumentException (" not all options specified to run against external S3 service" )
105
113
}
106
114
@@ -274,24 +282,52 @@ if (useFixture && minioDistribution) {
274
282
integTestMinioRunner. dependsOn(startMinio)
275
283
integTestMinioRunner. finalizedBy(stopMinio)
276
284
// Minio only supports a single access key, see https://github.com/minio/minio/pull/5968
277
- integTestMinioRunner. systemProperty ' tests.rest.blacklist' , ' repository_s3/30_repository_temporary_credentials/*'
285
+ integTestMinioRunner. systemProperty ' tests.rest.blacklist' , [
286
+ ' repository_s3/30_repository_temporary_credentials/*' ,
287
+ ' repository_s3/40_repository_ec2_credentials/*'
288
+ ]. join(" ," )
278
289
279
290
project. check. dependsOn(integTestMinio)
280
291
}
281
292
293
+ File parentFixtures = new File (project. buildDir, " fixtures" )
294
+ File s3FixtureFile = new File (parentFixtures, ' s3Fixture.properties' )
295
+
296
+ task s3FixtureProperties {
297
+ outputs. file(s3FixtureFile)
298
+ def s3FixtureOptions = [
299
+ " tests.seed" : project. testSeed,
300
+ " s3Fixture.permanent_bucket_name" : s3PermanentBucket,
301
+ " s3Fixture.permanent_key" : s3PermanentAccessKey,
302
+ " s3Fixture.temporary_bucket_name" : s3TemporaryBucket,
303
+ " s3Fixture.temporary_key" : s3TemporaryAccessKey,
304
+ " s3Fixture.temporary_session_token" : s3TemporarySessionToken,
305
+ " s3Fixture.ec2_bucket_name" : s3EC2Bucket
306
+ ]
307
+
308
+ doLast {
309
+ file(s3FixtureFile). text = s3FixtureOptions. collect { k , v -> " $k = $v " }. join(" \n " )
310
+ }
311
+ }
312
+
282
313
/* * A task to start the AmazonS3Fixture which emulates an S3 service **/
283
314
task s3Fixture (type : AntFixture ) {
284
315
dependsOn testClasses
316
+ dependsOn s3FixtureProperties
317
+ inputs. file(s3FixtureFile)
318
+
285
319
env ' CLASSPATH' , " ${ -> project.sourceSets.test.runtimeClasspath.asPath } "
286
320
executable = new File (project. runtimeJavaHome, ' bin/java' )
287
- args ' org.elasticsearch.repositories.s3.AmazonS3Fixture' , baseDir, s3PermanentBucket, s3TemporaryBucket
321
+ args ' org.elasticsearch.repositories.s3.AmazonS3Fixture' , baseDir, s3FixtureFile . getAbsolutePath()
288
322
}
289
323
290
324
Map<String , Object > expansions = [
291
325
' permanent_bucket' : s3PermanentBucket,
292
326
' permanent_base_path' : s3PermanentBasePath,
293
327
' temporary_bucket' : s3TemporaryBucket,
294
- ' temporary_base_path' : s3TemporaryBasePath
328
+ ' temporary_base_path' : s3TemporaryBasePath,
329
+ ' ec2_bucket' : s3EC2Bucket,
330
+ ' ec2_base_path' : s3EC2BasePath
295
331
]
296
332
297
333
processTestResources {
@@ -319,6 +355,10 @@ integTestCluster {
319
355
/* Use a closure on the string to delay evaluation until tests are executed */
320
356
setting ' s3.client.integration_test_permanent.endpoint' , " http://${ -> s3Fixture.addressAndPort} "
321
357
setting ' s3.client.integration_test_temporary.endpoint' , " http://${ -> s3Fixture.addressAndPort} "
358
+ setting ' s3.client.integration_test_ec2.endpoint' , " http://${ -> s3Fixture.addressAndPort} "
359
+
360
+ // to redirect InstanceProfileCredentialsProvider to custom auth point
361
+ systemProperty " com.amazonaws.sdk.ec2MetadataServiceEndpointOverride" , " http://${ -> s3Fixture.addressAndPort} "
322
362
} else {
323
363
println " Using an external service to test the repository-s3 plugin"
324
364
}
0 commit comments