Skip to content

Commit

Permalink
feat: Allow specifying a different protocol for proxies. (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-todorov committed Jul 26, 2023
1 parent 2f394b4 commit 51b68d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/content/reference/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A complete list of environment variables which can be set to configure the client.

| Key | Default | Description |
| ------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------|
|-------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------|
| s3fs.access.key | none | <small>AWS access key, used to identify the user interacting with AWS</small> |
| s3fs.secret.key | none | <small>AWS secret access key, used to authenticate the user interacting with AWS</small> |
| s3fs.request.metric.collector.class | TODO | <small>Fully-qualified class name to instantiate an AWS SDK request/response metric collector</small> |
Expand All @@ -14,6 +14,7 @@ A complete list of environment variables which can be set to configure the clien
| s3fs.max.retry.error | TODO | <small>Maximum number of times that a single request should be retried, assuming it fails for a retryable error</small> |
| s3fs.protocol | TODO | <small>Protocol (HTTP or HTTPS) to use when connecting to AWS</small> |
| s3fs.proxy.domain | none | <small>For NTLM proxies: The Windows domain name to use when authenticating with the proxy</small> |
| s3fs.proxy.protocol | none | <small>Proxy connection protocol.</small> |
| s3fs.proxy.host | none | <small>Proxy host name either from the configured endpoint or from the "http.proxyHost" system property</small> |
| s3fs.proxy.password | none | <small>The password to use when connecting through a proxy</small> |
| s3fs.proxy.port | none | <small>Proxy port either from the configured endpoint or from the "http.proxyPort" system property</small> |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public abstract class S3Factory

public static final String PROXY_WORKSTATION = "s3fs.proxy.workstation";

/**
* Allows you to specify the proxy protocol (http, https, etc)
*/
public static final String PROXY_PROTOCOL = "s3fs.proxy.protocol";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.carlspring.cloud.storage.s3fs;

import static org.assertj.core.api.Assertions.assertThat;
import static org.carlspring.cloud.storage.s3fs.S3Factory.*;
import static org.junit.jupiter.api.Assertions.*;
import static software.amazon.awssdk.core.client.config.SdkAdvancedClientOption.*;
Expand Down Expand Up @@ -32,8 +33,7 @@ void neverTrustTheDefaults()
Properties props = new Properties();
props.setProperty(ACCESS_KEY, "some_access_key");
props.setProperty(SECRET_KEY, "super_secret_key");
props.setProperty(REQUEST_METRIC_COLLECTOR_CLASS,
"org.carlspring.cloud.storage.s3fs.util.NoOpRequestMetricCollector");
props.setProperty(REQUEST_METRIC_COLLECTOR_CLASS, "org.carlspring.cloud.storage.s3fs.util.NoOpRequestMetricCollector");
props.setProperty(CONNECTION_TIMEOUT, "10");
props.setProperty(MAX_CONNECTIONS, "50");
props.setProperty(MAX_ERROR_RETRY, "3");
Expand Down Expand Up @@ -76,13 +76,13 @@ void neverTrustTheDefaults()

ProxyConfiguration proxyConfiguration = clientFactory.getProxyConfiguration(props);

assertEquals("127.0.0.1", proxyConfiguration.host());
assertEquals(12345, proxyConfiguration.port());
assertEquals("proxy_username", proxyConfiguration.username());
assertEquals("proxy_password", proxyConfiguration.password());
assertEquals("localhost", proxyConfiguration.ntlmDomain());
assertEquals("what.does.this.do.localhost", proxyConfiguration.ntlmWorkstation());
assertEquals("https", proxyConfiguration.scheme());
assertThat(proxyConfiguration.host()).isEqualTo(props.getProperty(PROXY_HOST));
assertThat(proxyConfiguration.port()).isEqualTo(Integer.valueOf(props.getProperty(PROXY_PORT)));
assertThat(proxyConfiguration.username()).isEqualTo(props.getProperty(PROXY_USERNAME));
assertThat(proxyConfiguration.password()).isEqualTo(props.getProperty(PROXY_PASSWORD));
assertThat(proxyConfiguration.ntlmDomain()).isEqualTo(props.getProperty(PROXY_DOMAIN));
assertThat(proxyConfiguration.ntlmWorkstation()).isEqualTo(props.getProperty(PROXY_WORKSTATION));
assertThat(proxyConfiguration.scheme()).isEqualTo(props.getProperty(PROXY_PROTOCOL));

S3Configuration serviceConfiguration = clientFactory.getServiceConfiguration(props);
assertTrue(serviceConfiguration.pathStyleAccessEnabled());
Expand Down Expand Up @@ -198,11 +198,12 @@ void overrideHostAndPort()
}

@Test
void differntProtocols()
void shouldAllowUsingHTTPProxyAndHTTPSProtocolForS3Connections()
{
S3ClientFactory clientFactory = new ExposingS3ClientFactory();

Properties props = new Properties();
props.setProperty(REGION, "eu-central-1");
props.setProperty(PROTOCOL, "https");
props.setProperty(PROXY_DOMAIN, "localhost");
props.setProperty(PROXY_HOST, "127.0.0.1");
Expand All @@ -216,6 +217,6 @@ void differntProtocols()
assertEquals("https", endpoint.getScheme());

ProxyConfiguration proxyConfiguration = clientFactory.getProxyConfiguration(props);
assertEquals("http",proxyConfiguration.scheme());
assertEquals("http", proxyConfiguration.scheme());
}
}

0 comments on commit 51b68d1

Please sign in to comment.