Skip to content

Commit d148a85

Browse files
blobstore: override proxy configs (#318)
Co-authored-by: Sandeep Pal <50725353+sandeepvinayak@users.noreply.github.com>
1 parent baea8cb commit d148a85

File tree

13 files changed

+478
-18
lines changed

13 files changed

+478
-18
lines changed

blob/blob-aws/src/main/java/com/salesforce/multicloudj/blob/aws/AwsBlobClient.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,21 @@ private static S3Client buildS3Client(Builder builder) {
9393
if (builder.getEndpoint() != null) {
9494
b.endpointOverride(builder.getEndpoint());
9595
}
96-
if (builder.getProxyEndpoint() != null) {
97-
ProxyConfiguration proxyConfig = ProxyConfiguration.builder()
98-
.endpoint(builder.getProxyEndpoint())
99-
.build();
96+
if (builder.getProxyEndpoint() != null
97+
|| builder.getUseSystemPropertyProxyValues() != null
98+
|| builder.getUseEnvironmentVariableProxyValues() != null) {
99+
ProxyConfiguration.Builder proxyConfigBuilder = ProxyConfiguration.builder();
100+
if (builder.getProxyEndpoint() != null) {
101+
proxyConfigBuilder.endpoint(builder.getProxyEndpoint());
102+
}
103+
if (builder.getUseSystemPropertyProxyValues() != null) {
104+
proxyConfigBuilder.useSystemPropertyValues(builder.getUseSystemPropertyProxyValues());
105+
}
106+
if (builder.getUseEnvironmentVariableProxyValues() != null) {
107+
proxyConfigBuilder.useEnvironmentVariableValues(builder.getUseEnvironmentVariableProxyValues());
108+
}
100109
b.httpClient(ApacheHttpClient.builder()
101-
.proxyConfiguration(proxyConfig)
110+
.proxyConfiguration(proxyConfigBuilder.build())
102111
.build());
103112
}
104113
if (builder.getRetryConfig() != null) {

blob/blob-aws/src/main/java/com/salesforce/multicloudj/blob/aws/AwsBlobStore.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ protected static boolean shouldConfigureHttpClient(Builder builder) {
110110
return builder.getProxyEndpoint() != null
111111
|| builder.getMaxConnections() != null
112112
|| builder.getSocketTimeout() != null
113-
|| builder.getIdleConnectionTimeout() != null;
113+
|| builder.getIdleConnectionTimeout() != null
114+
|| builder.getUseSystemPropertyProxyValues() != null
115+
|| builder.getUseEnvironmentVariableProxyValues() != null;
114116
}
115117

116118
@Override
@@ -627,10 +629,20 @@ private static S3Client buildS3Client(Builder builder) {
627629
*/
628630
private static SdkHttpClient generateHttpClient(Builder builder) {
629631
ApacheHttpClient.Builder httpClientBuilder = ApacheHttpClient.builder();
630-
if (builder.getProxyEndpoint() != null) {
631-
httpClientBuilder.proxyConfiguration(ProxyConfiguration.builder()
632-
.endpoint(builder.getProxyEndpoint())
633-
.build());
632+
if (builder.getProxyEndpoint() != null
633+
|| builder.getUseSystemPropertyProxyValues() != null
634+
|| builder.getUseEnvironmentVariableProxyValues() != null) {
635+
ProxyConfiguration.Builder proxyConfigBuilder = ProxyConfiguration.builder();
636+
if (builder.getProxyEndpoint() != null) {
637+
proxyConfigBuilder.endpoint(builder.getProxyEndpoint());
638+
}
639+
if (builder.getUseSystemPropertyProxyValues() != null) {
640+
proxyConfigBuilder.useSystemPropertyValues(builder.getUseSystemPropertyProxyValues());
641+
}
642+
if (builder.getUseEnvironmentVariableProxyValues() != null) {
643+
proxyConfigBuilder.useEnvironmentVariableValues(builder.getUseEnvironmentVariableProxyValues());
644+
}
645+
httpClientBuilder.proxyConfiguration(proxyConfigBuilder.build());
634646
}
635647
if(builder.getMaxConnections() != null) {
636648
httpClientBuilder.maxConnections(builder.getMaxConnections());

blob/blob-aws/src/main/java/com/salesforce/multicloudj/blob/aws/async/AwsAsyncBlobStore.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,28 @@ private static void applyCommonConfig(S3AsyncClientBuilder builder, Builder conf
509509

510510
// Configure HTTP client if any settings are specified
511511
if (config.getProxyEndpoint() != null || config.getMaxConnections() != null ||
512-
config.getSocketTimeout() != null || config.getIdleConnectionTimeout() != null) {
512+
config.getSocketTimeout() != null || config.getIdleConnectionTimeout() != null ||
513+
config.getUseSystemPropertyProxyValues() != null || config.getUseEnvironmentVariableProxyValues() != null) {
513514

514515
NettyNioAsyncHttpClient.Builder httpClientBuilder = NettyNioAsyncHttpClient.builder();
515516

516517
// Configure proxy if specified
517-
if (config.getProxyEndpoint() != null) {
518-
ProxyConfiguration proxyConfig = ProxyConfiguration.builder()
519-
.scheme(config.getProxyEndpoint().getScheme())
520-
.host(config.getProxyEndpoint().getHost())
521-
.port(config.getProxyEndpoint().getPort())
522-
.build();
523-
httpClientBuilder.proxyConfiguration(proxyConfig);
518+
if (config.getProxyEndpoint() != null
519+
|| config.getUseSystemPropertyProxyValues() != null
520+
|| config.getUseEnvironmentVariableProxyValues() != null) {
521+
ProxyConfiguration.Builder proxyConfigBuilder = ProxyConfiguration.builder();
522+
if (config.getProxyEndpoint() != null) {
523+
proxyConfigBuilder.scheme(config.getProxyEndpoint().getScheme())
524+
.host(config.getProxyEndpoint().getHost())
525+
.port(config.getProxyEndpoint().getPort());
526+
}
527+
if (config.getUseSystemPropertyProxyValues() != null) {
528+
proxyConfigBuilder.useSystemPropertyValues(config.getUseSystemPropertyProxyValues());
529+
}
530+
if (config.getUseEnvironmentVariableProxyValues() != null) {
531+
proxyConfigBuilder.useEnvironmentVariableValues(config.getUseEnvironmentVariableProxyValues());
532+
}
533+
httpClientBuilder.proxyConfiguration(proxyConfigBuilder.build());
524534
}
525535

526536
// Configure max connections if specified

blob/blob-aws/src/test/java/com/salesforce/multicloudj/blob/aws/AwsBlobClientTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,53 @@ void testBuildS3ClientWithRetryConfigWithTotalTimeout() {
233233
assertEquals("aws", client.getProviderId());
234234
}
235235

236+
@Test
237+
void testBuildS3ClientWithUseSystemPropertyProxyValues() {
238+
var client = new AwsBlobClient.Builder()
239+
.withRegion("us-east-2")
240+
.withUseSystemPropertyProxyValues(false)
241+
.build();
242+
243+
assertNotNull(client);
244+
assertEquals("aws", client.getProviderId());
245+
}
246+
247+
@Test
248+
void testBuildS3ClientWithUseEnvironmentVariableProxyValues() {
249+
var client = new AwsBlobClient.Builder()
250+
.withRegion("us-east-2")
251+
.withUseEnvironmentVariableProxyValues(false)
252+
.build();
253+
254+
assertNotNull(client);
255+
assertEquals("aws", client.getProviderId());
256+
}
257+
258+
@Test
259+
void testBuildS3ClientWithBothProxyOverrideFlags() {
260+
var client = new AwsBlobClient.Builder()
261+
.withRegion("us-east-2")
262+
.withUseSystemPropertyProxyValues(false)
263+
.withUseEnvironmentVariableProxyValues(false)
264+
.build();
265+
266+
assertNotNull(client);
267+
assertEquals("aws", client.getProviderId());
268+
}
269+
270+
@Test
271+
void testBuildS3ClientWithProxyEndpointAndOverrideFlags() {
272+
var client = new AwsBlobClient.Builder()
273+
.withRegion("us-east-2")
274+
.withProxyEndpoint(URI.create("https://proxy.endpoint.com:443"))
275+
.withUseSystemPropertyProxyValues(true)
276+
.withUseEnvironmentVariableProxyValues(false)
277+
.build();
278+
279+
assertNotNull(client);
280+
assertEquals("aws", client.getProviderId());
281+
}
282+
236283
@Test
237284
void testCreateBucket() {
238285
String bucketName = "test-bucket";

blob/blob-aws/src/test/java/com/salesforce/multicloudj/blob/aws/AwsBlobStoreTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ void testShouldConfigureHttpClient() {
229229
.withIdleConnectionTimeout(Duration.ofSeconds(10));
230230
assertTrue(AwsBlobStore.shouldConfigureHttpClient((AwsBlobStore.Builder)builderWithIdleConnectionTimeout));
231231

232+
var builderWithUseSystemPropertyProxyValues = new AwsBlobStore.Builder()
233+
.withTransformerSupplier(transformerSupplier)
234+
.withBucket("bucket-1").withRegion("us-east-2")
235+
.withUseSystemPropertyProxyValues(false);
236+
assertTrue(AwsBlobStore.shouldConfigureHttpClient((AwsBlobStore.Builder)builderWithUseSystemPropertyProxyValues));
237+
238+
var builderWithUseEnvVarProxyValues = new AwsBlobStore.Builder()
239+
.withTransformerSupplier(transformerSupplier)
240+
.withBucket("bucket-1").withRegion("us-east-2")
241+
.withUseEnvironmentVariableProxyValues(false);
242+
assertTrue(AwsBlobStore.shouldConfigureHttpClient((AwsBlobStore.Builder)builderWithUseEnvVarProxyValues));
243+
232244
var builderWithNoOverrides = new AwsBlobStore.Builder()
233245
.withTransformerSupplier(transformerSupplier)
234246
.withBucket("bucket-1").withRegion("us-east-2");
@@ -1243,6 +1255,61 @@ void testBuildS3ClientWithoutRetryConfig() {
12431255
assertEquals("bucket-1", store.getBucket());
12441256
}
12451257

1258+
@Test
1259+
void testBuildS3ClientWithUseSystemPropertyProxyValues() {
1260+
var store = new AwsBlobStore.Builder()
1261+
.withTransformerSupplier(transformerSupplier)
1262+
.withBucket("bucket-1")
1263+
.withRegion("us-east-2")
1264+
.withUseSystemPropertyProxyValues(false)
1265+
.build();
1266+
1267+
assertNotNull(store);
1268+
assertEquals("bucket-1", store.getBucket());
1269+
}
1270+
1271+
@Test
1272+
void testBuildS3ClientWithUseEnvironmentVariableProxyValues() {
1273+
var store = new AwsBlobStore.Builder()
1274+
.withTransformerSupplier(transformerSupplier)
1275+
.withBucket("bucket-1")
1276+
.withRegion("us-east-2")
1277+
.withUseEnvironmentVariableProxyValues(false)
1278+
.build();
1279+
1280+
assertNotNull(store);
1281+
assertEquals("bucket-1", store.getBucket());
1282+
}
1283+
1284+
@Test
1285+
void testBuildS3ClientWithBothProxyOverrideFlags() {
1286+
var store = new AwsBlobStore.Builder()
1287+
.withTransformerSupplier(transformerSupplier)
1288+
.withBucket("bucket-1")
1289+
.withRegion("us-east-2")
1290+
.withUseSystemPropertyProxyValues(false)
1291+
.withUseEnvironmentVariableProxyValues(false)
1292+
.build();
1293+
1294+
assertNotNull(store);
1295+
assertEquals("bucket-1", store.getBucket());
1296+
}
1297+
1298+
@Test
1299+
void testBuildS3ClientWithProxyEndpointAndOverrideFlags() {
1300+
var store = new AwsBlobStore.Builder()
1301+
.withTransformerSupplier(transformerSupplier)
1302+
.withBucket("bucket-1")
1303+
.withRegion("us-east-2")
1304+
.withProxyEndpoint(URI.create("https://proxy.endpoint.com:443"))
1305+
.withUseSystemPropertyProxyValues(true)
1306+
.withUseEnvironmentVariableProxyValues(false)
1307+
.build();
1308+
1309+
assertNotNull(store);
1310+
assertEquals("bucket-1", store.getBucket());
1311+
}
1312+
12461313
@Test
12471314
void testGetObjectLock_Success() {
12481315
// Given

blob/blob-aws/src/test/java/com/salesforce/multicloudj/blob/aws/async/AwsAsyncBlobStoreTest.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,61 @@ void testBuildS3AsyncClientWithoutRetryConfig() {
14771477
assertEquals(BUCKET, store.getBucket());
14781478
}
14791479

1480+
@Test
1481+
void testBuildS3AsyncClientWithUseSystemPropertyProxyValues() {
1482+
var store = new AwsAsyncBlobStore.Builder()
1483+
.withBucket(BUCKET)
1484+
.withRegion(REGION)
1485+
.withUseSystemPropertyProxyValues(false)
1486+
.build();
1487+
1488+
assertNotNull(store);
1489+
assertInstanceOf(AwsAsyncBlobStore.class, store);
1490+
assertEquals(BUCKET, store.getBucket());
1491+
}
1492+
1493+
@Test
1494+
void testBuildS3AsyncClientWithUseEnvironmentVariableProxyValues() {
1495+
var store = new AwsAsyncBlobStore.Builder()
1496+
.withBucket(BUCKET)
1497+
.withRegion(REGION)
1498+
.withUseEnvironmentVariableProxyValues(false)
1499+
.build();
1500+
1501+
assertNotNull(store);
1502+
assertInstanceOf(AwsAsyncBlobStore.class, store);
1503+
assertEquals(BUCKET, store.getBucket());
1504+
}
1505+
1506+
@Test
1507+
void testBuildS3AsyncClientWithBothProxyOverrideFlags() {
1508+
var store = new AwsAsyncBlobStore.Builder()
1509+
.withBucket(BUCKET)
1510+
.withRegion(REGION)
1511+
.withUseSystemPropertyProxyValues(false)
1512+
.withUseEnvironmentVariableProxyValues(false)
1513+
.build();
1514+
1515+
assertNotNull(store);
1516+
assertInstanceOf(AwsAsyncBlobStore.class, store);
1517+
assertEquals(BUCKET, store.getBucket());
1518+
}
1519+
1520+
@Test
1521+
void testBuildS3AsyncClientWithProxyEndpointAndOverrideFlags() {
1522+
var store = new AwsAsyncBlobStore.Builder()
1523+
.withBucket(BUCKET)
1524+
.withRegion(REGION)
1525+
.withProxyEndpoint(URI.create("https://proxy.example.com:443"))
1526+
.withUseSystemPropertyProxyValues(true)
1527+
.withUseEnvironmentVariableProxyValues(false)
1528+
.build();
1529+
1530+
assertNotNull(store);
1531+
assertInstanceOf(AwsAsyncBlobStore.class, store);
1532+
assertEquals(BUCKET, store.getBucket());
1533+
}
1534+
14801535
@Test
14811536
void testBuildS3CrtAsyncClientWithRetryConfig() {
14821537
// Test CRT client with retry config

blob/blob-client/src/main/java/com/salesforce/multicloudj/blob/async/client/AsyncBucketClient.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,28 @@ public Builder withRetryConfig(RetryConfig retryConfig) {
596596
return this;
597597
}
598598

599+
/**
600+
* Method to control whether system property values should be used for proxy configuration.
601+
* @param useSystemPropertyProxyValues Whether to use system property values for proxy configuration
602+
* @return An instance of self
603+
*/
604+
@Override
605+
public Builder withUseSystemPropertyProxyValues(Boolean useSystemPropertyProxyValues) {
606+
super.withUseSystemPropertyProxyValues(useSystemPropertyProxyValues);
607+
return this;
608+
}
609+
610+
/**
611+
* Method to control whether environment variable values should be used for proxy configuration.
612+
* @param useEnvironmentVariableProxyValues Whether to use environment variable values for proxy configuration
613+
* @return An instance of self
614+
*/
615+
@Override
616+
public Builder withUseEnvironmentVariableProxyValues(Boolean useEnvironmentVariableProxyValues) {
617+
super.withUseEnvironmentVariableProxyValues(useEnvironmentVariableProxyValues);
618+
return this;
619+
}
620+
599621
/**
600622
* {@inheritDoc}
601623
*/

blob/blob-client/src/main/java/com/salesforce/multicloudj/blob/client/BucketClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,26 @@ public BlobBuilder withRetryConfig(RetryConfig retryConfig) {
662662
return this;
663663
}
664664

665+
/**
666+
* Method to control whether system property values should be used for proxy configuration.
667+
* @param useSystemPropertyProxyValues Whether to use system property values for proxy configuration
668+
* @return An instance of self
669+
*/
670+
public BlobBuilder withUseSystemPropertyProxyValues(Boolean useSystemPropertyProxyValues) {
671+
this.blobStoreBuilder.withUseSystemPropertyProxyValues(useSystemPropertyProxyValues);
672+
return this;
673+
}
674+
675+
/**
676+
* Method to control whether environment variable values should be used for proxy configuration.
677+
* @param useEnvironmentVariableProxyValues Whether to use environment variable values for proxy configuration
678+
* @return An instance of self
679+
*/
680+
public BlobBuilder withUseEnvironmentVariableProxyValues(Boolean useEnvironmentVariableProxyValues) {
681+
this.blobStoreBuilder.withUseEnvironmentVariableProxyValues(useEnvironmentVariableProxyValues);
682+
return this;
683+
}
684+
665685
/**
666686
* Builds and returns an instance of BucketClient.
667687
* @return An instance of BucketClient.

blob/blob-client/src/main/java/com/salesforce/multicloudj/blob/driver/BlobBuilder.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public abstract class BlobBuilder<T extends SdkService> implements SdkProvider.B
2727
private CredentialsOverrider credentialsOverrider;
2828
private Properties properties = new Properties();
2929
private RetryConfig retryConfig;
30+
private Boolean useSystemPropertyProxyValues;
31+
private Boolean useEnvironmentVariableProxyValues;
3032

3133
public BlobBuilder<T> providerId(String providerId) {
3234
this.providerId = providerId;
@@ -88,4 +90,30 @@ public BlobBuilder<T> withRetryConfig(RetryConfig retryConfig) {
8890
return this;
8991
}
9092

93+
/**
94+
* Method to control whether system property values (e.g., http.proxyHost, http.proxyPort,
95+
* https.proxyHost, https.proxyPort) should be used for proxy configuration.
96+
* When set to false, these system properties will be ignored.
97+
*
98+
* @param useSystemPropertyProxyValues Whether to use system property values for proxy configuration
99+
* @return An instance of self
100+
*/
101+
public BlobBuilder<T> withUseSystemPropertyProxyValues(Boolean useSystemPropertyProxyValues) {
102+
this.useSystemPropertyProxyValues = useSystemPropertyProxyValues;
103+
return this;
104+
}
105+
106+
/**
107+
* Method to control whether environment variable values (e.g., HTTP_PROXY, HTTPS_PROXY,
108+
* NO_PROXY) should be used for proxy configuration.
109+
* When set to false, these environment variables will be ignored.
110+
*
111+
* @param useEnvironmentVariableProxyValues Whether to use environment variable values for proxy configuration
112+
* @return An instance of self
113+
*/
114+
public BlobBuilder<T> withUseEnvironmentVariableProxyValues(Boolean useEnvironmentVariableProxyValues) {
115+
this.useEnvironmentVariableProxyValues = useEnvironmentVariableProxyValues;
116+
return this;
117+
}
118+
91119
}

0 commit comments

Comments
 (0)