Skip to content

Commit 38923b8

Browse files
author
Xu Zhang
committed
Update Format, add new settings into the setting test
1 parent 7499e3a commit 38923b8

File tree

8 files changed

+21
-20
lines changed

8 files changed

+21
-20
lines changed

plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/AwsS3Service.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,5 @@ interface CLOUD_S3 {
154154
Setting<String> ENDPOINT_SETTING = Setting.simpleString("cloud.aws.s3.endpoint", Property.NodeScope);
155155
}
156156

157-
AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries);
158157
AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, EncryptionMaterials clientSideEncryptionMaterials);
159158
}

plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/InternalAwsS3Service.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ public InternalAwsS3Service(Settings settings) {
6262
}
6363

6464
@Override
65-
public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries) {
66-
return client(endpoint, protocol, region, account, key, maxRetries, null);
67-
}
65+
public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries,
66+
EncryptionMaterials clientSideEncryptionMaterials) {
6867

69-
@Override
70-
public AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, EncryptionMaterials clientSideEncryptionMaterials) {
7168
if (Strings.isNullOrEmpty(endpoint)) {
7269
// We need to set the endpoint based on the region
7370
if (region != null) {
@@ -144,8 +141,7 @@ private synchronized AmazonS3 getClient(String endpoint, Protocol protocol, Stri
144141
credentials,
145142
encryptionMaterialsProvider,
146143
clientConfiguration,
147-
cryptoConfiguration
148-
);
144+
cryptoConfiguration);
149145
} else {
150146
client = new AmazonS3Client(credentials, clientConfiguration);
151147
}

plugins/repository-s3/src/main/java/org/elasticsearch/cloud/aws/blobstore/DefaultS3OutputStream.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.elasticsearch.cloud.aws.blobstore;
2121

2222
import com.amazonaws.AmazonClientException;
23-
import com.amazonaws.services.s3.AmazonS3EncryptionClient;
24-
import com.amazonaws.services.s3.Headers;
2523
import com.amazonaws.services.s3.model.AbortMultipartUploadRequest;
2624
import com.amazonaws.services.s3.model.AmazonS3Exception;
2725
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;

plugins/repository-s3/src/main/java/org/elasticsearch/plugin/repository/s3/S3RepositoryPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public void onModule(SettingsModule settingsModule) {
147147
settingsModule.registerSetting(S3Repository.Repository.STORAGE_CLASS_SETTING);
148148
settingsModule.registerSetting(S3Repository.Repository.CANNED_ACL_SETTING);
149149
settingsModule.registerSetting(S3Repository.Repository.BASE_PATH_SETTING);
150-
151150
settingsModule.registerSetting(S3Repository.Repository.CLIENT_PRIVATE_KEY);
152151
settingsModule.registerSetting(S3Repository.Repository.CLIENT_PUBLIC_KEY);
153152
settingsModule.registerSetting(S3Repository.Repository.CLIENT_SYMMETRIC_KEY);

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ public interface Repository {
247247
* base_path
248248
* @see Repositories#BASE_PATH_SETTING
249249
*/
250-
251250
Setting<String> BASE_PATH_SETTING = Setting.simpleString("base_path", Property.NodeScope);
252251

253252
/**
@@ -319,15 +318,15 @@ public S3Repository(RepositoryName name, RepositorySettings repositorySettings,
319318
String storageClass = getValue(repositorySettings, Repository.STORAGE_CLASS_SETTING, Repositories.STORAGE_CLASS_SETTING);
320319
String cannedACL = getValue(repositorySettings, Repository.CANNED_ACL_SETTING, Repositories.CANNED_ACL_SETTING);
321320

322-
logger.debug("using bqucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}], cannedACL [{}], storageClass [{}]",
321+
logger.debug("using bucket [{}], region [{}], endpoint [{}], protocol [{}], chunk_size [{}], server_side_encryption [{}], buffer_size [{}], max_retries [{}], cannedACL [{}], storageClass [{}]",
323322
bucket, region, endpoint, protocol, chunkSize, serverSideEncryption, bufferSize, maxRetries, cannedACL, storageClass);
324323

325324
String key = getValue(repositorySettings, Repository.KEY_SETTING, Repositories.KEY_SETTING);
326325
String secret = getValue(repositorySettings, Repository.SECRET_SETTING, Repositories.SECRET_SETTING);
327326

328327
// parse and validate the client side encryption setting
329328
String symmetricKeyBase64 = getValue(repositorySettings, Repository.CLIENT_SYMMETRIC_KEY, Repositories.CLIENT_SYMMETRIC_KEY);
330-
String publicKeyBase64 =getValue(repositorySettings, Repository.CLIENT_PUBLIC_KEY, Repositories.CLIENT_PUBLIC_KEY);
329+
String publicKeyBase64 = getValue(repositorySettings, Repository.CLIENT_PUBLIC_KEY, Repositories.CLIENT_PUBLIC_KEY);
331330
String privateKeyBase64 = getValue(repositorySettings, Repository.CLIENT_PRIVATE_KEY, Repositories.CLIENT_PRIVATE_KEY);
332331

333332
EncryptionMaterials clientSideEncryptionMaterials = initClientSideEncryption(symmetricKeyBase64, publicKeyBase64, privateKeyBase64, name);
@@ -366,7 +365,7 @@ private EncryptionMaterials initClientSideEncryption(String symmetricKey, String
366365
EncryptionMaterials clientSideEncryptionMaterials = null;
367366

368367
if (Strings.isNullOrEmpty(symmetricKey) == false && (Strings.isNullOrEmpty(publicKey) == false || Strings.isNullOrEmpty(privateKey) == false)) {
369-
throw new RepositoryException(name.name(), "Client-side encryption: You can't specify an symmetric key AND a public/private key pair");
368+
throw new RepositoryException(name.name(), "Client-side encryption: You can't specify a symmetric key AND a public/private key pair");
370369
}
371370

372371
if (Strings.isNullOrEmpty(symmetricKey) == false || Strings.isNullOrEmpty(publicKey) == false || Strings.isNullOrEmpty(privateKey) == false) {
@@ -380,7 +379,7 @@ private EncryptionMaterials initClientSideEncryption(String symmetricKey, String
380379
if (Strings.isNullOrEmpty(symmetricKey) == false) {
381380
clientSideEncryptionMaterials = new EncryptionMaterials(new SecretKeySpec(Base64.decode(symmetricKey), "AES"));
382381
} else {
383-
if (Strings.isNullOrEmpty(publicKey)|| Strings.isNullOrEmpty(privateKey)){
382+
if (Strings.isNullOrEmpty(publicKey) || Strings.isNullOrEmpty(privateKey)) {
384383
String missingKey = Strings.isNullOrEmpty(publicKey) ? "public key" : "private key";
385384
throw new RepositoryException(name.name(), "Client-side encryption: " + missingKey + " is missing");
386385
}

plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/RepositoryS3SettingsTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class RepositoryS3SettingsTests extends ESTestCase {
9797
.put(Repository.STORAGE_CLASS_SETTING.getKey(), "repository-class")
9898
.put(Repository.CANNED_ACL_SETTING.getKey(), "repository-acl")
9999
.put(Repository.BASE_PATH_SETTING.getKey(), "repository-basepath")
100+
100101
.build();
101102

102103
/**
@@ -125,6 +126,9 @@ public void testRepositorySettingsGlobalOnly() {
125126
assertThat(getValue(repositorySettings, Repository.STORAGE_CLASS_SETTING, Repositories.STORAGE_CLASS_SETTING), isEmptyString());
126127
assertThat(getValue(repositorySettings, Repository.CANNED_ACL_SETTING, Repositories.CANNED_ACL_SETTING), isEmptyString());
127128
assertThat(getValue(repositorySettings, Repository.BASE_PATH_SETTING, Repositories.BASE_PATH_SETTING), isEmptyString());
129+
assertThat(getValue(repositorySettings, Repository.CLIENT_SYMMETRIC_KEY, Repositories.CLIENT_SYMMETRIC_KEY), isEmptyString());
130+
assertThat(getValue(repositorySettings, Repository.CLIENT_PRIVATE_KEY, Repositories.CLIENT_PRIVATE_KEY), isEmptyString());
131+
assertThat(getValue(repositorySettings, Repository.CLIENT_PUBLIC_KEY, Repositories.CLIENT_PUBLIC_KEY), isEmptyString());
128132
}
129133

130134
/**
@@ -153,6 +157,9 @@ public void testRepositorySettingsGlobalOverloadedByS3() {
153157
assertThat(getValue(repositorySettings, Repository.STORAGE_CLASS_SETTING, Repositories.STORAGE_CLASS_SETTING), isEmptyString());
154158
assertThat(getValue(repositorySettings, Repository.CANNED_ACL_SETTING, Repositories.CANNED_ACL_SETTING), isEmptyString());
155159
assertThat(getValue(repositorySettings, Repository.BASE_PATH_SETTING, Repositories.BASE_PATH_SETTING), isEmptyString());
160+
assertThat(getValue(repositorySettings, Repository.CLIENT_SYMMETRIC_KEY, Repositories.CLIENT_SYMMETRIC_KEY), isEmptyString());
161+
assertThat(getValue(repositorySettings, Repository.CLIENT_PRIVATE_KEY, Repositories.CLIENT_PRIVATE_KEY), isEmptyString());
162+
assertThat(getValue(repositorySettings, Repository.CLIENT_PUBLIC_KEY, Repositories.CLIENT_PUBLIC_KEY), isEmptyString());
156163
}
157164

158165
/**
@@ -329,6 +336,7 @@ private Settings buildSettings(Settings... global) {
329336

330337
private void internalTestInvalidChunkBufferSizeSettings(ByteSizeValue buffer, ByteSizeValue chunk, String expectedMessage)
331338
throws IOException {
339+
332340
Settings nodeSettings = buildSettings(AWS, S3, REPOSITORIES);
333341
RepositorySettings s3RepositorySettings = new RepositorySettings(nodeSettings, Settings.builder()
334342
.put(Repository.BUFFER_SIZE_SETTING.getKey(), buffer)

plugins/repository-s3/src/test/java/org/elasticsearch/cloud/aws/TestAwsS3Service.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import com.amazonaws.Protocol;
2222
import com.amazonaws.services.s3.AmazonS3;
23+
import com.amazonaws.services.s3.model.EncryptionMaterials;
2324
import org.elasticsearch.ElasticsearchException;
2425
import org.elasticsearch.common.inject.Inject;
2526
import org.elasticsearch.common.settings.Settings;
@@ -51,8 +52,8 @@ public TestAwsS3Service(Settings settings) {
5152

5253

5354
@Override
54-
public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries) {
55-
return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries));
55+
public synchronized AmazonS3 client(String endpoint, Protocol protocol, String region, String account, String key, Integer maxRetries, EncryptionMaterials clientSideEncryptionMaterials) {
56+
return cachedWrapper(super.client(endpoint, protocol, region, account, key, maxRetries, clientSideEncryptionMaterials));
5657
}
5758

5859
private AmazonS3 cachedWrapper(AmazonS3 client) {

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void testSimpleWorkflow() {
104104
logger.info("--> creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath);
105105
PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo")
106106
.setType("s3").setSettings(settings
107-
).get();
107+
).get();
108108
assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
109109

110110
createIndex("test-idx-1", "test-idx-2", "test-idx-3");
@@ -209,6 +209,7 @@ public void testEncryption() {
209209
S3Repository.Repositories.REGION_SETTING.get(settings),
210210
S3Repository.Repositories.KEY_SETTING.get(settings),
211211
S3Repository.Repositories.SECRET_SETTING.get(settings),
212+
null,
212213
null);
213214

214215
String bucketName = bucket.get("bucket");
@@ -553,7 +554,7 @@ public void cleanRepositoryFiles(String basePath) {
553554
// We check that settings has been set in elasticsearch.yml integration test file
554555
// as described in README
555556
assertThat("Your settings in elasticsearch.yml are incorrects. Check README file.", bucketName, notNullValue());
556-
AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, protocol, region, accessKey, secretKey, null);
557+
AmazonS3 client = internalCluster().getInstance(AwsS3Service.class).client(endpoint, protocol, region, accessKey, secretKey, null, null);
557558
try {
558559
ObjectListing prevListing = null;
559560
//From http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingJava.html

0 commit comments

Comments
 (0)