mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(s3): virtual-hosted style addressing support (#805)
*.s3.localhost.floci.io, *.localhost.localstack.cloud, and
*.s3.localhost.localstack.cloud as virtual-hosted style regardless of
FLOCI_HOSTNAME — fixes 405 when SDK uses endpointOverride("http://localhost:4566")
without forcePathStyle (closes #801)
- EmbeddedDnsServer ships localhost.localstack.cloud and localhost.floci.io
as built-in suffixes so spawned containers resolve these domains to Floci's
IP without extra config
- Compatibility test S3VirtualHostStyleTest covers the full virtual-host path
end-to-end; TestFixtures.s3VirtualHostClient() prefers s3.localhost.floci.io,
falls back to s3.localhost.localstack.cloud, or uses FLOCI_S3_VHOST_ENDPOINT
in Docker
- run-docker-tests.sh and compatibility.yml inject --dns <floci-ip> and
FLOCI_S3_VHOST_ENDPOINT=http://floci:4566 into test containers
- S3 and migrate-from-localstack docs updated with virtual-hosted style details
This commit is contained in:
1 parent
ec9631e8c5
commit
c8c77c9e6e
11 files changed
+462
-15
No files matched your search
@@ -240,6 +240,64 @@ public final class TestFixtures {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* S3 client using virtual-hosted style addressing (no forcePathStyle).
|
||||
*
|
||||
* <p>The endpoint base is resolved in priority order:
|
||||
* <ol>
|
||||
* <li>{@code FLOCI_S3_VHOST_ENDPOINT} env var — set this to {@code http://floci:4566}
|
||||
* in Docker test environments and point the test container's DNS at the Floci
|
||||
* container so that {@code <bucket>.floci} resolves via Floci's embedded DNS.</li>
|
||||
* <li>{@code s3.localhost.floci.io} — Floci's own public wildcard DNS, resolves to 127.0.0.1.</li>
|
||||
* <li>{@code s3.localhost.localstack.cloud} — LocalStack's public wildcard DNS, fallback.</li>
|
||||
* </ol>
|
||||
*/
|
||||
public static S3Client s3VirtualHostClient() {
|
||||
URI virtualHostEndpoint;
|
||||
String vhostEndpoint = System.getenv("FLOCI_S3_VHOST_ENDPOINT");
|
||||
if (vhostEndpoint != null && !vhostEndpoint.trim().isEmpty()) {
|
||||
virtualHostEndpoint = URI.create(vhostEndpoint);
|
||||
} else {
|
||||
int port = ENDPOINT.getPort() > 0 ? ENDPOINT.getPort() : 80;
|
||||
String host = resolveVirtualHostBase(port);
|
||||
virtualHostEndpoint = URI.create("http://" + host + ":" + port);
|
||||
}
|
||||
return S3Client.builder()
|
||||
.endpointOverride(virtualHostEndpoint)
|
||||
.region(REGION)
|
||||
.credentialsProvider(CREDENTIALS)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the S3 virtual-host endpoint is resolvable.
|
||||
* When {@code FLOCI_S3_VHOST_ENDPOINT} is set the environment is
|
||||
* assumed to have working DNS (e.g. --dns pointing at Floci).
|
||||
*/
|
||||
public static boolean isS3VirtualHostResolvable() {
|
||||
String vhostEndpoint = System.getenv("FLOCI_S3_VHOST_ENDPOINT");
|
||||
if (vhostEndpoint != null && !vhostEndpoint.trim().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return isDnsResolvable("s3.localhost.floci.io") || isDnsResolvable("s3.localhost.localstack.cloud");
|
||||
}
|
||||
|
||||
private static String resolveVirtualHostBase(int port) {
|
||||
if (isDnsResolvable("s3.localhost.floci.io")) {
|
||||
return "s3.localhost.floci.io";
|
||||
}
|
||||
return "s3.localhost.localstack.cloud";
|
||||
}
|
||||
|
||||
private static boolean isDnsResolvable(String hostname) {
|
||||
try {
|
||||
java.net.InetAddress.getByName(hostname);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* S3 Control client for the S3 Control API (/v20180820/...).
|
||||
* Host prefix injection (account-ID prepended to host) is disabled so requests
|
||||
|
||||
Reference in new issue
Block a user