@@ -89,18 +89,26 @@ String s3TemporarySessionToken = System.getenv("amazon_s3_session_token_temporar
8989String s3TemporaryBucket = System . getenv(" amazon_s3_bucket_temporary" )
9090String s3TemporaryBasePath = System . getenv(" amazon_s3_base_path_temporary" )
9191
92+ String s3EC2Bucket = System . getenv(" amazon_s3_bucket_ec2" )
93+ String s3EC2BasePath = System . getenv(" amazon_s3_base_path_ec2" )
94+
9295// If all these variables are missing then we are testing against the internal fixture instead, which has the following
9396// credentials hard-coded in.
9497
95- if (! s3PermanentAccessKey && ! s3PermanentSecretKey && ! s3PermanentBucket && ! s3PermanentBasePath) {
98+ if (! s3PermanentAccessKey && ! s3PermanentSecretKey && ! s3PermanentBucket && ! s3PermanentBasePath
99+ && ! s3EC2Bucket && ! s3EC2BasePath) {
96100 s3PermanentAccessKey = ' s3_integration_test_permanent_access_key'
97101 s3PermanentSecretKey = ' s3_integration_test_permanent_secret_key'
98102 s3PermanentBucket = ' permanent-bucket-test'
99103 s3PermanentBasePath = ' integration_test'
100104
105+ s3EC2Bucket = ' ec2-bucket-test'
106+ s3EC2BasePath = ' integration_test'
107+
101108 useFixture = true
102109
103- } else if (! s3PermanentAccessKey || ! s3PermanentSecretKey || ! s3PermanentBucket || ! s3PermanentBasePath) {
110+ } else if (! s3PermanentAccessKey || ! s3PermanentSecretKey || ! s3PermanentBucket || ! s3PermanentBasePath
111+ || ! s3EC2Bucket || ! s3EC2BasePath) {
104112 throw new IllegalArgumentException (" not all options specified to run against external S3 service" )
105113}
106114
@@ -274,24 +282,52 @@ if (useFixture && minioDistribution) {
274282 integTestMinioRunner. dependsOn(startMinio)
275283 integTestMinioRunner. finalizedBy(stopMinio)
276284 // 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(" ," )
278289
279290 project. check. dependsOn(integTestMinio)
280291}
281292
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+
282313/* * A task to start the AmazonS3Fixture which emulates an S3 service **/
283314task s3Fixture (type : AntFixture ) {
284315 dependsOn testClasses
316+ dependsOn s3FixtureProperties
317+ inputs. file(s3FixtureFile)
318+
285319 env ' CLASSPATH' , " ${ -> project.sourceSets.test.runtimeClasspath.asPath } "
286320 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()
288322}
289323
290324Map<String , Object > expansions = [
291325 ' permanent_bucket' : s3PermanentBucket,
292326 ' permanent_base_path' : s3PermanentBasePath,
293327 ' temporary_bucket' : s3TemporaryBucket,
294- ' temporary_base_path' : s3TemporaryBasePath
328+ ' temporary_base_path' : s3TemporaryBasePath,
329+ ' ec2_bucket' : s3EC2Bucket,
330+ ' ec2_base_path' : s3EC2BasePath
295331]
296332
297333processTestResources {
@@ -319,6 +355,10 @@ integTestCluster {
319355 /* Use a closure on the string to delay evaluation until tests are executed */
320356 setting ' s3.client.integration_test_permanent.endpoint' , " http://${ -> s3Fixture.addressAndPort} "
321357 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} "
322362 } else {
323363 println " Using an external service to test the repository-s3 plugin"
324364 }
0 commit comments