allow endpoint to be missing when secure endpoint is set

pull/61/merge
Ka-Hing Cheung 2015-05-11 18:28:49 -07:00 zatwierdzone przez Andrew Gaul
rodzic 6e4ebad1c8
commit f17d968a33
4 zmienionych plików z 59 dodań i 23 usunięć

Wyświetl plik

@ -57,18 +57,21 @@ public final class Main {
String endpoint = properties.getProperty(Constants.PROPERTY_ENDPOINT);
String s3ProxyEndpointString = properties.getProperty(
S3ProxyConstants.PROPERTY_ENDPOINT);
String secureEndpoint = properties.getProperty(S3ProxyConstants.PROPERTY_SECURE_ENDPOINT);
String secureEndpoint = properties.getProperty(
S3ProxyConstants.PROPERTY_SECURE_ENDPOINT);
String s3ProxyAuthorization = properties.getProperty(
S3ProxyConstants.PROPERTY_AUTHORIZATION);
if (provider == null || identity == null || credential == null ||
s3ProxyEndpointString == null ||
(s3ProxyEndpointString == null && secureEndpoint == null) ||
s3ProxyAuthorization == null) {
System.err.println("Properties file must contain:\n" +
Constants.PROPERTY_PROVIDER + "\n" +
Constants.PROPERTY_IDENTITY + "\n" +
Constants.PROPERTY_CREDENTIAL + "\n" +
S3ProxyConstants.PROPERTY_AUTHORIZATION + "\n" +
"and one of\n" +
S3ProxyConstants.PROPERTY_ENDPOINT + "\n" +
S3ProxyConstants.PROPERTY_AUTHORIZATION);
S3ProxyConstants.PROPERTY_SECURE_ENDPOINT);
System.exit(1);
}
@ -101,13 +104,14 @@ public final class Main {
builder = builder.endpoint(endpoint);
}
BlobStoreContext context = builder.build(BlobStoreContext.class);
URI s3ProxyEndpoint = new URI(s3ProxyEndpointString);
S3Proxy s3Proxy;
try {
S3Proxy.Builder s3ProxyBuilder = S3Proxy.builder()
.blobStore(context.getBlobStore())
.endpoint(s3ProxyEndpoint);
.blobStore(context.getBlobStore());
if (s3ProxyEndpointString != null) {
s3ProxyBuilder.endpoint(new URI(s3ProxyEndpointString));
}
if (secureEndpoint != null) {
s3ProxyBuilder.secureEndpoint(new URI(secureEndpoint));
}

Wyświetl plik

@ -40,6 +40,8 @@ import org.jclouds.blobstore.BlobStore;
public final class S3Proxy {
private final Server server;
private final S3ProxyHandler handler;
private final boolean listenHTTP;
private final boolean listenHTTPS;
static {
// Prevent Jetty from rewriting headers:
@ -48,29 +50,41 @@ public final class S3Proxy {
}
S3Proxy(Builder builder) {
requireNonNull(builder.endpoint);
checkArgument(builder.endpoint != null ||
builder.secureEndpoint != null,
"Must provide endpoint or secure-endpoint");
// TODO: allow service paths?
checkArgument(builder.endpoint.getPath().isEmpty(),
"endpoint path must be empty, was: %s",
builder.endpoint.getPath());
checkArgument(Strings.isNullOrEmpty(builder.identity) ^
!Strings.isNullOrEmpty(builder.credential),
"Must provide both identity and credential");
if (builder.endpoint.getScheme().equals("https:")) {
if (builder.endpoint != null) {
checkArgument(builder.endpoint.getPath().isEmpty(),
"endpoint path must be empty, was: %s",
builder.endpoint.getPath());
}
if (builder.secureEndpoint != null) {
checkArgument(builder.secureEndpoint.getPath().isEmpty(),
"secure-endpoint path must be empty, was: %s",
builder.secureEndpoint.getPath());
requireNonNull(builder.keyStorePath,
"Must provide keyStorePath with HTTPS endpoint");
requireNonNull(builder.keyStorePassword,
"Must provide keyStorePassword with HTTPS endpoint");
}
checkArgument(Strings.isNullOrEmpty(builder.identity) ^
!Strings.isNullOrEmpty(builder.credential),
"Must provide both identity and credential");
server = new Server();
HttpConnectionFactory httpConnectionFactory =
new HttpConnectionFactory();
ServerConnector connector;
connector = new ServerConnector(server, httpConnectionFactory);
connector.setHost(builder.endpoint.getHost());
connector.setPort(builder.endpoint.getPort());
server.addConnector(connector);
if (builder.endpoint != null) {
connector = new ServerConnector(server, httpConnectionFactory);
connector.setHost(builder.endpoint.getHost());
connector.setPort(builder.endpoint.getPort());
server.addConnector(connector);
listenHTTP = true;
} else {
listenHTTP = false;
}
if (builder.secureEndpoint != null) {
SslContextFactory sslContextFactory = new SslContextFactory();
@ -81,6 +95,9 @@ public final class S3Proxy {
connector.setHost(builder.secureEndpoint.getHost());
connector.setPort(builder.secureEndpoint.getPort());
server.addConnector(connector);
listenHTTPS = true;
} else {
listenHTTPS = false;
}
handler = new S3ProxyHandler(builder.blobStore, builder.identity,
builder.credential, Optional.fromNullable(builder.virtualHost));
@ -150,11 +167,25 @@ public final class S3Proxy {
}
public int getPort() {
return ((ServerConnector) server.getConnectors()[0]).getLocalPort();
if (listenHTTP) {
return ((ServerConnector) server.getConnectors()[0]).getLocalPort();
} else {
return -1;
}
}
public int getSecurePort() {
return ((ServerConnector) server.getConnectors()[1]).getLocalPort();
if (listenHTTPS) {
ServerConnector connector;
if (listenHTTP) {
connector = (ServerConnector) server.getConnectors()[1];
} else {
connector = (ServerConnector) server.getConnectors()[0];
}
return connector.getLocalPort();
}
return -1;
}
public String getState() {

Wyświetl plik

@ -153,8 +153,9 @@ public final class S3AwsSdkTest {
// reset endpoint to handle zero port
s3Endpoint = new URI("https", s3Endpoint.getUserInfo(),
s3Endpoint.getHost(), s3Proxy.getSecurePort(), s3Endpoint.getPath(),
s3Endpoint.getQuery(), s3Endpoint.getFragment());
s3Endpoint.getHost(), s3Proxy.getSecurePort(),
s3Endpoint.getPath(), s3Endpoint.getQuery(),
s3Endpoint.getFragment());
}
@After

Wyświetl plik

@ -14,7 +14,7 @@ popd
# launch S3Proxy using HTTP and a fixed port
sed "s,^\(s3proxy.endpoint\)=.*,\1=http://127.0.0.1:${S3PROXY_PORT}," \
< src/test/resources/s3proxy.conf > target/s3proxy.conf
< src/test/resources/s3proxy.conf | grep -v secure-endpoint > target/s3proxy.conf
$S3PROXY_BIN --properties target/s3proxy.conf &
S3PROXY_PID=$!