Skip to content

Commit

Permalink
fix: TW-81869 add support for passing configuration property that all…
Browse files Browse the repository at this point in the history
…ows using plain HTTP for upload

Merge-request: TC-MR-6395
Merged-by: Andrei Efimov <Andrei.Efimov@jetbrains.com>
  • Loading branch information
wayfarer-rus authored and qodana-bot committed Aug 4, 2023
1 parent 3deacf7 commit e4b240c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ private static String extractCorrectedRegion(@NotNull final Throwable e) {
}
}

public static boolean isAllowPlainHttpUpload(Map<String, String> params) {
if (params.containsKey(ALLOW_HTTP_CONNECTION_FOR_UPLOAD)) {
return Boolean.parseBoolean(params.get(ALLOW_HTTP_CONNECTION_FOR_UPLOAD));
}

return TeamCityProperties.getBoolean(ALLOW_HTTP_CONNECTION_FOR_UPLOAD, false);
}

@Deprecated
public interface WithS3<T, E extends Throwable> {
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static S3Util.S3AdvancedConfiguration configuration(@NotNull final Map<St
.withUrlTtlSeconds(jetbrains.buildServer.artifacts.s3.S3Util.getUrlTtlSeconds(sharedConfigurationParameters))
.withConsistencyCheckEnabled(jetbrains.buildServer.artifacts.s3.S3Util.isConsistencyCheckEnabled(sharedConfigurationParameters))
.withAcl(jetbrains.buildServer.artifacts.s3.S3Util.getAcl(artifactStorageSettings, sharedConfigurationParameters))
.allowPlainHttpUpload(jetbrains.buildServer.artifacts.s3.S3Util.isAllowPlainHttpUpload(sharedConfigurationParameters))
.withShutdownClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import jetbrains.buildServer.artifacts.s3.exceptions.FileUploadFailedException;
import jetbrains.buildServer.artifacts.s3.publish.errors.*;
import jetbrains.buildServer.http.HttpUserAgent;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import jetbrains.buildServer.util.HTTPRequestBuilder;
import jetbrains.buildServer.util.StringUtil;
import jetbrains.buildServer.util.ThreadUtil;
Expand All @@ -38,13 +37,15 @@ public class LowLevelS3Client implements AutoCloseable {
private final Map<String, String> myAdditionalHeaders;
private final ExecutorService myExecutorService;
private final int myConnectionTimeout;
private final boolean myAllowPlainHttpUpload;

public LowLevelS3Client(@NotNull final S3Configuration s3Config) {
myExecutorService = ExecutorsFactory.newFixedDaemonExecutor(S3Constants.S3_STORAGE_TYPE, s3Config.getNThreadsForFileParts());
myConnectionTimeout = s3Config.getAdvancedConfiguration().getConnectionTimeout() * 1000;
myCheckConsistency = s3Config.getAdvancedConfiguration().isConsistencyCheckEnabled();
myAdditionalHeaders = new HashMap<>();
myAdditionalHeaders.put("x-amz-acl", s3Config.getAcl().toString());
myAllowPlainHttpUpload = s3Config.getAdvancedConfiguration().isAllowPlainHttpUpload();
}

@NotNull
Expand Down Expand Up @@ -90,15 +91,14 @@ private String parseEtags(@NotNull final HttpResponseAdapter response) {
@NotNull
private CompletableFuture<String> put(@NotNull final String url, @NotNull final EntityProducer requestEntity, @Nullable String digest, @NotNull final Map<String, String> headers)
throws URISyntaxException {
final boolean allowHttp = TeamCityProperties.getBoolean(S3Constants.ALLOW_HTTP_CONNECTION_FOR_UPLOAD, false);
final HTTPRequestBuilder requestBuilder = new HTTPRequestBuilder(url);
requestBuilder
.withMethod(HttpMethod.PUT)
.withHeader(HttpHeaders.USER_AGENT, HttpUserAgent.getUserAgent())
.withHeader("Accept", "application/xml")
.withData(requestEntity)
.withTimeout(myConnectionTimeout)
.allowNonSecureConnection(allowHttp);
.allowNonSecureConnection(myAllowPlainHttpUpload);

headers.forEach(requestBuilder::withHeader);
if (myCheckConsistency && digest != null) {
Expand Down

0 comments on commit e4b240c

Please sign in to comment.