-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support serving of Virtual Host requests
- Loading branch information
Showing
20 changed files
with
295 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
trino-s3-proxy/src/main/java/io/trino/s3/proxy/server/collections/MultiMapHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.s3.proxy.server.collections; | ||
|
||
import jakarta.ws.rs.core.MultivaluedHashMap; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.function.BiFunction; | ||
|
||
public class MultiMapHelper | ||
{ | ||
public static <V> MultivaluedMap<String, V> lowercase(MultivaluedMap<String, V> map) | ||
{ | ||
return lowercase(map, (ignored, values) -> values); | ||
} | ||
|
||
public static <V> MultivaluedMap<String, V> lowercase(MultivaluedMap<String, V> map, BiFunction<String, List<V>, List<V>> valueMapper) | ||
{ | ||
MultivaluedMap<String, V> result = new MultivaluedHashMap<>(); | ||
map.forEach((name, values) -> result.put(name.toLowerCase(Locale.ROOT), valueMapper.apply(name.toLowerCase(Locale.ROOT), values))); | ||
return result; | ||
} | ||
|
||
private MultiMapHelper() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
trino-s3-proxy/src/main/java/io/trino/s3/proxy/server/rest/ParsedS3Request.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.s3.proxy.server.rest; | ||
|
||
import com.google.common.base.Splitter; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.core.UriBuilder; | ||
import org.glassfish.jersey.server.ContainerRequest; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
import static io.trino.s3.proxy.server.collections.MultiMapHelper.lowercase; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
public record ParsedS3Request( | ||
String bucketName, | ||
String keyInBucket, | ||
MultivaluedMap<String, String> requestHeaders, | ||
MultivaluedMap<String, String> requestQueryParameters, | ||
String httpVerb) | ||
{ | ||
public ParsedS3Request | ||
{ | ||
requireNonNull(bucketName, "bucketName is null"); | ||
requireNonNull(keyInBucket, "keyInBucket is null"); | ||
requestHeaders = lowercase(requireNonNull(requestHeaders, "requestHeaders is null")); | ||
requireNonNull(requestQueryParameters, "requestQueryParameters is null"); | ||
requireNonNull(httpVerb, "httpVerb is null"); | ||
} | ||
|
||
public static ParsedS3Request fromRequest(String requestPath, MultivaluedMap<String, String> requestHeaders, MultivaluedMap<String, String> requestQueryParameters, String httpVerb, Optional<String> serverHostName) | ||
{ | ||
MultivaluedMap<String, String> headers = lowercase(requestHeaders); | ||
return serverHostName | ||
.flatMap(serverHostNameValue -> { | ||
String lowercaseServerHostName = serverHostNameValue.toLowerCase(Locale.ROOT); | ||
return Optional.ofNullable(headers.getFirst("host")) | ||
.map(value -> UriBuilder.fromUri("http://" + value.toLowerCase(Locale.ROOT)).build().getHost()) | ||
.filter(value -> value.endsWith(lowercaseServerHostName)) | ||
.map(value -> value.substring(0, value.length() - lowercaseServerHostName.length())) | ||
.map(value -> value.endsWith(".") ? value.substring(0, value.length() - 1) : value); | ||
}) | ||
.map(bucket -> new ParsedS3Request(bucket, requestPath, headers, requestQueryParameters, httpVerb)) | ||
.orElseGet(() -> { | ||
List<String> parts = Splitter.on("/").limit(2).splitToList(requestPath); | ||
if (parts.size() <= 1) { | ||
return new ParsedS3Request(requestPath, "", headers, requestQueryParameters, httpVerb); | ||
} | ||
return new ParsedS3Request(parts.get(0), parts.get(1), headers, requestQueryParameters, httpVerb); | ||
}); | ||
} | ||
|
||
public static ParsedS3Request fromRequest(String requestPath, ContainerRequest request, Optional<String> serverHostName) | ||
{ | ||
return fromRequest(requestPath, request.getHeaders(), request.getUriInfo().getQueryParameters(), request.getMethod(), serverHostName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
trino-s3-proxy/src/main/java/io/trino/s3/proxy/server/rest/TrinoS3ProxyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.trino.s3.proxy.server.rest; | ||
|
||
import io.airlift.configuration.Config; | ||
import io.airlift.configuration.ConfigDescription; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.Optional; | ||
|
||
public class TrinoS3ProxyConfig | ||
{ | ||
private Optional<String> hostName = Optional.empty(); | ||
|
||
@Config("s3proxy.hostname") | ||
@ConfigDescription("Hostname to use for REST operations, virtual-host style addressing is only supported if this is set") | ||
public TrinoS3ProxyConfig setHostName(String hostName) | ||
{ | ||
this.hostName = Optional.ofNullable(hostName); | ||
return this; | ||
} | ||
|
||
@NotNull | ||
public Optional<String> getHostName() | ||
{ | ||
return hostName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.