diff --git a/README.md b/README.md index 2f6e04b61f0a8..f4b0cbd09712a 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ The following settings are supported: * `bucket`: The name of the bucket to be used for snapshots. (Mandatory) * `region`: The region where bucket is located. Defaults to US Standard * `endpoint`: The endpoint to the S3 API. Defaults to AWS's default S3 endpoint. Note that setting a region overrides the endpoint setting. -* `protocol`: The protocol to use (`http` or `https`). Defaults to `https`. +* `protocol`: The protocol to use (`http` or `https`). Defaults to value of `cloud.aws.protocol` or `cloud.aws.s3.protocol`. * `base_path`: Specifies the path within bucket to repository data. Defaults to root directory. * `access_key`: The access key to use for authentication. Defaults to value of `cloud.aws.access_key`. * `secret_key`: The secret key to use for authentication. Defaults to value of `cloud.aws.secret_key`. @@ -266,8 +266,10 @@ The bucket needs to exist to register a repository for snapshots. If you did not ### Using other S3 endpoint -If you are using any S3 api compatible service, you can set the endpoint you want to use by setting `cloud.aws.s3.endpoint` -to your URL provider. +If you are using any S3 api compatible service, you can set a global endpoint by setting `cloud.aws.s3.endpoint` +to your URL provider. Note that this setting will be used for all S3 repositories. + +Different `endpoint`, `region` and `protocol` settings can be set on a per-repository basis (see [S3 Repository](#s3-repository) section for detail). ## Testing diff --git a/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java b/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java index 076c0f308e758..e2f9d17eb70ee 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java +++ b/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java @@ -60,7 +60,7 @@ public synchronized AmazonS3 client() { String account = componentSettings.get("access_key", settings.get("cloud.account")); String key = componentSettings.get("secret_key", settings.get("cloud.key")); - return getClient(endpoint, "https", account, key, null); + return getClient(endpoint, null, account, key, null); } @Override @@ -94,7 +94,8 @@ private synchronized AmazonS3 getClient(String endpoint, String protocol, String ClientConfiguration clientConfiguration = new ClientConfiguration(); if (protocol == null) { - protocol = "https"; + protocol = componentSettings.get("protocol", "https").toLowerCase(); + protocol = componentSettings.get("s3.protocol", protocol).toLowerCase(); } if ("http".equals(protocol)) { diff --git a/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java b/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java index 4a4daef1da97a..7632576d36b34 100644 --- a/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java +++ b/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java @@ -80,9 +80,7 @@ public S3Repository(RepositoryName name, RepositorySettings repositorySettings, } String endpoint = repositorySettings.settings().get("endpoint", componentSettings.get("endpoint")); - String protocol = componentSettings.get("protocol", "https").toLowerCase(); - protocol = componentSettings.get("s3.protocol", protocol).toLowerCase(); - protocol = repositorySettings.settings().get("protocol", protocol); + String protocol = repositorySettings.settings().get("protocol", componentSettings.get("protocol")); String region = repositorySettings.settings().get("region", componentSettings.get("region")); if (region == null) { diff --git a/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java b/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java index 42777c8ff41c0..eeca09ed2f879 100644 --- a/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java +++ b/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java @@ -287,10 +287,11 @@ public void testRepositoryWithCustomEndpointProtocol() { logger.info("--> creating s3 repostoriy with endpoint [{}], bucket[{}] and path [{}]", bucketSettings.get("endpoint"), bucketSettings.get("bucket"), basePath); PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") .setType("s3").setSettings(ImmutableSettings.settingsBuilder() - .put("protocol", bucketSettings.get("protocol")) + .put("bucket", bucketSettings.get("bucket")) .put("endpoint", bucketSettings.get("endpoint")) .put("access_key", bucketSettings.get("access_key")) .put("secret_key", bucketSettings.get("secret_key")) + .put("base_path", basePath) ).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); assertRepositoryIsOperational(client, "test-repo"); @@ -445,7 +446,8 @@ public void cleanRepositoryFiles(String basePath) { Settings[] buckets = { settings.getByPrefix("repositories.s3."), settings.getByPrefix("repositories.s3.private-bucket."), - settings.getByPrefix("repositories.s3.remote-bucket.") + settings.getByPrefix("repositories.s3.remote-bucket."), + settings.getByPrefix("repositories.s3.external-bucket.") }; for (Settings bucket : buckets) { String endpoint = bucket.get("endpoint", settings.get("repositories.s3.endpoint"));