mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(cfn): resolve floci virtual-hosted template urls (#690)
This commit is contained in:
1 parent
f359a94eaa
commit
7b0df82a86
2 files changed
+79
-2
No files matched your search
+18
-2
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.ChangeSet;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackEvent;
|
||||
@@ -500,7 +501,7 @@ public class CloudFormationService {
|
||||
private String fetchTemplateFromS3(String url) {
|
||||
// Parse S3 URL — three forms:
|
||||
// Virtual-hosted AWS: https://bucket.s3[.region].amazonaws.com/key
|
||||
// Virtual-hosted local: http://bucket.localhost:4566/key (or configured hostname)
|
||||
// Virtual-hosted local: http://bucket.localhost:4566/key (or configured/default hostname)
|
||||
// Path-style (both): https://s3[.region].amazonaws.com/bucket/key
|
||||
// http://host:port/bucket/key
|
||||
//
|
||||
@@ -516,7 +517,7 @@ public class CloudFormationService {
|
||||
|
||||
boolean isVirtualHosted = host != null && (
|
||||
host.contains(".s3.")
|
||||
|| (config.hostname().isPresent() && host.endsWith("." + config.hostname().get()))
|
||||
|| isConfiguredVirtualHostedS3Host(host)
|
||||
|| host.endsWith(".localhost"));
|
||||
|
||||
if (isVirtualHosted) {
|
||||
@@ -539,6 +540,21 @@ public class CloudFormationService {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConfiguredVirtualHostedS3Host(String host) {
|
||||
String suffix = config.hostname().orElse(EmbeddedDnsServer.DEFAULT_SUFFIX);
|
||||
return hasBucketPrefixForSuffix(host, suffix);
|
||||
}
|
||||
|
||||
private static boolean hasBucketPrefixForSuffix(String host, String suffix) {
|
||||
if (host == null || suffix == null || suffix.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String normalizedHost = host.toLowerCase(Locale.ROOT);
|
||||
String normalizedSuffix = suffix.toLowerCase(Locale.ROOT);
|
||||
return normalizedHost.length() > normalizedSuffix.length() + 1
|
||||
&& normalizedHost.endsWith("." + normalizedSuffix);
|
||||
}
|
||||
|
||||
private Stack newStack(String stackName, String region) {
|
||||
Stack stack = new Stack();
|
||||
stack.setStackName(stackName);
|
||||
|
||||
Reference in new issue
Block a user