Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/src/main/java/org/entcore/common/s3/S3Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@

public S3Client(Vertx vertx, URI uri, String accessKey, String secretKey, String region, String bucket, String ssec, boolean keepAlive,
int timeout, int threshold, long openDelay, int poolSize) {
this(vertx, uri, accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize, false);
}

public S3Client(Vertx vertx, URI uri, String accessKey, String secretKey, String region, String bucket, String ssec, boolean keepAlive,

Check warning on line 91 in common/src/main/java/org/entcore/common/s3/S3Client.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 13 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=edificeio_entcore&issues=AZ0BuG2ZX7DOvjq5kYfz&open=AZ0BuG2ZX7DOvjq5kYfz&pullRequest=978
int timeout, int threshold, long openDelay, int poolSize, boolean trustAll) {
this.vertx = vertx;
this.host = uri.getHost();
this.accessKey = accessKey;
this.secretKey = secretKey;
this.region = region;
this.defaultBucket = bucket;
this.ssec = ssec;
this.httpClient = new ResilientHttpClient(vertx, uri, keepAlive, timeout, threshold, openDelay, poolSize);
this.httpClient = new ResilientHttpClient(vertx, uri, keepAlive, timeout, threshold, openDelay, poolSize, trustAll);
}

public void getFileStats(String id, Handler<AsyncResult<FileStats>> handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ public class ResilientHttpClient implements HttpClient {
private final URI uri;
private final boolean keepAlive;
private final int poolSize;
private final boolean trustAll;
private AtomicInteger errorsCount = new AtomicInteger(0);
private AtomicBoolean closedCircuit = new AtomicBoolean(false);
private Handler<HalfOpenResult> halfOpenHandler;

public ResilientHttpClient(Vertx vertx, URI uri, boolean keepAlive, int timeout, int threshold, long openDelay, int poolSize) {
this(vertx, uri, keepAlive, timeout, threshold, openDelay, poolSize, false);
}

public ResilientHttpClient(Vertx vertx, URI uri, boolean keepAlive, int timeout, int threshold, long openDelay, int poolSize, boolean trustAll) {
this.vertx = vertx;
this.timeout = timeout;
this.threshold = threshold;
this.openDelay = openDelay;
this.uri = uri;
this.keepAlive = keepAlive;
this.poolSize = poolSize;
this.trustAll = trustAll;
reconfigure();
}

Expand Down Expand Up @@ -232,6 +238,8 @@ private void reconfigure() {
.setDefaultPort(port)
.setMaxPoolSize(poolSize)
.setSsl("https".equals(uri.getScheme()))
.setTrustAll(trustAll)
.setVerifyHost(!trustAll)
.setKeepAlive(keepAlive)
.setConnectTimeout(timeout);
this.httpClient = vertx.createHttpClient(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@
int threshold = s3.getInteger("threshold", 100);
long openDelay = s3.getLong("openDelay", 10000l);
int poolSize = s3.getInteger("poolSize", 16);
boolean trustAll = s3.getBoolean("trustAll", false);

Check failure on line 151 in common/src/main/java/org/entcore/common/storage/StorageFactory.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "trustAll" 3 times.

See more on https://sonarcloud.io/project/issues?id=edificeio_entcore&issues=AZ0BuG8DX7DOvjq5kYf2&open=AZ0BuG8DX7DOvjq5kYf2&pullRequest=978
try {
storage = new S3Storage(vertx, new URI(uri), accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize);
storage = new S3Storage(vertx, new URI(uri), accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize, trustAll);
} catch (URISyntaxException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -205,8 +206,9 @@
final String accessKey = s3fallback.getString("access-key");
final String secretKey = s3fallback.getString("secret-key");
if (isNotEmpty(host) && isNotEmpty(name) && isNotEmpty(region) && isNotEmpty(accessKey) && isNotEmpty(secretKey)) {
final boolean trustAllFallback = s3fallback.getBoolean("trustAll", false);
S3FallbackStorage s3FallbackStorage = new S3FallbackStorage(
vertx, host, name, multiBuckets, nbStorageFolder, region, accessKey, secretKey);
vertx, host, name, multiBuckets, nbStorageFolder, region, accessKey, secretKey, trustAllFallback);
((FileStorage) storage).setFallbackStorage(s3FallbackStorage);
}
}
Expand All @@ -220,8 +222,9 @@
final int bucketMaxAge = s3fallbacks3fs.getInteger("bucketMaxAge", 2);

if (isNotEmpty(uri) && isNotEmpty(bucket) && isNotEmpty(region) && isNotEmpty(accessKey) && isNotEmpty(secretKey)) {
final boolean trustAllS3fs = s3fallbacks3fs.getBoolean("trustAll", false);
S3FallbackS3FSStorage s3FallbackS3FSStorage = new S3FallbackS3FSStorage(
vertx, uri, bucket, region, accessKey, secretKey, ssecKey, bucketMaxAge);
vertx, uri, bucket, region, accessKey, secretKey, ssecKey, bucketMaxAge, trustAllS3fs);
((FileStorage) storage).setFallbackStorage(s3FallbackS3FSStorage);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
private static final Logger log = LoggerFactory.getLogger(S3FallbackS3FSStorage.class);

public S3FallbackS3FSStorage(Vertx vertx, String uri, String bucket, String region, String accessKey, String secretKey, String ssecKey, int bucketMaxAge) {
this(vertx, uri, bucket, region, accessKey, secretKey, ssecKey, bucketMaxAge, false);
}

public S3FallbackS3FSStorage(Vertx vertx, String uri, String bucket, String region, String accessKey, String secretKey, String ssecKey, int bucketMaxAge, boolean trustAll) {

Check warning on line 33 in common/src/main/java/org/entcore/common/storage/impl/S3FallbackS3FSStorage.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 9 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=edificeio_entcore&issues=AZ0BuG7JX7DOvjq5kYf1&open=AZ0BuG7JX7DOvjq5kYf1&pullRequest=978
this.bucket = bucket;
this.bucketMaxAge = bucketMaxAge;

this.s3Client = new S3Client(vertx, URI.create(uri), accessKey, secretKey, region, bucket, ssecKey);
this.s3Client = new S3Client(vertx, URI.create(uri), accessKey, secretKey, region, bucket, ssecKey,
false, 10000, 100, 10000L, 16, trustAll);
this.fs = vertx.fileSystem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public class S3FallbackS3LegacyStorage implements FallbackStorage {
private static final Logger log = LoggerFactory.getLogger(S3FallbackS3LegacyStorage.class);

public S3FallbackS3LegacyStorage(Vertx vertx, JsonObject s3, JsonObject s3fallback) {
this.s3Client = new S3Client(vertx, URI.create(s3.getString("uri")), s3.getString("accessKey"), s3.getString("secretKey"), s3.getString("region"), s3.getString("bucket"), s3.getString("ssec"));
this.s3FallbackClient = new S3Client(vertx, URI.create(s3fallback.getString("uri")), s3fallback.getString("accessKey"), s3fallback.getString("secretKey"), s3fallback.getString("region"), s3fallback.getString("bucket"), s3fallback.getString("ssec"));
this.s3Client = new S3Client(vertx, URI.create(s3.getString("uri")), s3.getString("accessKey"), s3.getString("secretKey"), s3.getString("region"), s3.getString("bucket"), s3.getString("ssec"),
false, 10000, 100, 10000L, 16, s3.getBoolean("trustAll", false));
this.s3FallbackClient = new S3Client(vertx, URI.create(s3fallback.getString("uri")), s3fallback.getString("accessKey"), s3fallback.getString("secretKey"), s3fallback.getString("region"), s3fallback.getString("bucket"), s3fallback.getString("ssec"),
false, 10000, 100, 10000L, 16, s3fallback.getBoolean("trustAll", false));

this.bucket = s3fallback.getString("bucket");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public class S3FallbackS3S3Storage implements FallbackStorage {
private static final Logger log = LoggerFactory.getLogger(S3FallbackS3S3Storage.class);

public S3FallbackS3S3Storage(Vertx vertx, JsonObject s3, JsonObject s3fallback) {
this.s3Client = new S3Client(vertx, URI.create(s3.getString("uri")), s3.getString("accessKey"), s3.getString("secretKey"), s3.getString("region"), s3.getString("bucket"), s3.getString("ssec"));
this.s3FallbackClient = new S3Client(vertx, URI.create(s3fallback.getString("uri")), s3fallback.getString("accessKey"), s3fallback.getString("secretKey"), s3fallback.getString("region"), s3fallback.getString("bucket"), s3fallback.getString("ssec"));
this.s3Client = new S3Client(vertx, URI.create(s3.getString("uri")), s3.getString("accessKey"), s3.getString("secretKey"), s3.getString("region"), s3.getString("bucket"), s3.getString("ssec"),
false, 10000, 100, 10000L, 16, s3.getBoolean("trustAll", false));
this.s3FallbackClient = new S3Client(vertx, URI.create(s3fallback.getString("uri")), s3fallback.getString("accessKey"), s3fallback.getString("secretKey"), s3fallback.getString("region"), s3fallback.getString("bucket"), s3fallback.getString("ssec"),
false, 10000, 100, 10000L, 16, s3fallback.getBoolean("trustAll", false));

this.bucket = s3fallback.getString("bucket");
this.bucketMaxAge = s3fallback.getInteger("bucketMaxAge", 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@
private static final Logger log = LoggerFactory.getLogger(S3Storage.class);

public S3Storage(Vertx vertx, URI uri, String accessKey, String secretKey, String region, String bucket, String ssec, boolean keepAlive, int timeout, int threshold, long openDelay, int poolSize) {
this(vertx, uri, accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize, false);
}

public S3Storage(Vertx vertx, URI uri, String accessKey, String secretKey, String region, String bucket, String ssec, boolean keepAlive, int timeout, int threshold, long openDelay, int poolSize, boolean trustAll) {

Check warning on line 77 in common/src/main/java/org/entcore/common/storage/impl/S3Storage.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 13 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=edificeio_entcore&issues=AZ0BuG6zX7DOvjq5kYf0&open=AZ0BuG6zX7DOvjq5kYf0&pullRequest=978
this.bucket = bucket;
this.s3Client = new S3Client(vertx, uri, accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize);
this.s3Client = new S3Client(vertx, uri, accessKey, secretKey, region, bucket, ssec, keepAlive, timeout, threshold, openDelay, poolSize, trustAll);
this.fs = vertx.fileSystem();
}

Expand Down
3 changes: 2 additions & 1 deletion directory/src/main/java/org/entcore/directory/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public void handle(HttpServerRequest request) {
s3.getInteger("timeout", 10000),
s3.getInteger("threshold", 100),
s3.getLong("openDelay", 10000l),
s3.getInteger("poolSize", 16)
s3.getInteger("poolSize", 16),
s3.getBoolean("trustAll", false)
);
} catch (URISyntaxException e) {
log.error("S3avatar URI error", e);
Expand Down