mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ecs): use caller endpoint for exec stream URLs (#5666)
This commit is contained in:
1 parent
bb06acdeb1
commit
6e8a083d2b
7 files changed
+125
-15
No files matched your search
@@ -324,7 +324,7 @@ public class AwsJson11Controller {
|
||||
case "kms" -> kmsJsonHandler.handle(action, request, region);
|
||||
case "cognito-idp" -> cognitoJsonHandler.handle(action, request, region);
|
||||
case "acm" -> acmJsonHandler.handle(action, request, region);
|
||||
case "ecs" -> ecsJsonHandler.handle(action, request, region);
|
||||
case "ecs" -> ecsJsonHandler.handle(action, request, region, uriInfo.getBaseUri());
|
||||
case "ecr" -> ecrJsonHandler.handle(action, request, region);
|
||||
case "glue" -> glueJsonHandler.handle(action, request, region);
|
||||
case "athena" -> athenaJsonHandler.handle(action, request, region);
|
||||
|
||||
@@ -55,6 +55,7 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -87,6 +88,10 @@ public class EcsJsonHandler {
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region) {
|
||||
return handle(action, request, region, null);
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region, URI requestBaseUri) {
|
||||
return switch (action) {
|
||||
// Clusters
|
||||
case "CreateCluster" -> handleCreateCluster(request, region);
|
||||
@@ -111,7 +116,7 @@ public class EcsJsonHandler {
|
||||
case "ListTasks" -> handleListTasks(request, region);
|
||||
case "UpdateTaskProtection" -> handleUpdateTaskProtection(request, region);
|
||||
case "GetTaskProtection" -> handleGetTaskProtection(request, region);
|
||||
case "ExecuteCommand" -> handleExecuteCommand(request, region);
|
||||
case "ExecuteCommand" -> handleExecuteCommand(request, region, requestBaseUri);
|
||||
|
||||
case "CreateService" -> handleCreateService(request, region);
|
||||
case "UpdateService" -> handleUpdateService(request, region);
|
||||
@@ -515,7 +520,7 @@ public class EcsJsonHandler {
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
private Response handleExecuteCommand(JsonNode req, String region) {
|
||||
private Response handleExecuteCommand(JsonNode req, String region, URI requestBaseUri) {
|
||||
String cluster = req.has("cluster") ? req.path("cluster").asText() : null;
|
||||
String task = req.path("task").asText();
|
||||
String container = req.hasNonNull("container") ? req.path("container").asText() : null;
|
||||
@@ -535,7 +540,7 @@ public class EcsJsonHandler {
|
||||
resp.put("interactive", interactive);
|
||||
ObjectNode session = resp.putObject("session");
|
||||
session.put("sessionId", result.session().sessionId());
|
||||
session.put("streamUrl", service.execStreamUrl(result.session()));
|
||||
session.put("streamUrl", service.execStreamUrl(result.session(), requestBaseUri));
|
||||
session.put("tokenValue", result.session().tokenValue());
|
||||
return Response.ok(resp).build();
|
||||
}
|
||||
|
||||
@@ -72,8 +72,10 @@ import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@@ -2275,12 +2277,19 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
"The container " + containerName + " is not part of the task.", 400));
|
||||
}
|
||||
|
||||
/** The {@code ws://} URL a client opens for an exec session's data channel. */
|
||||
/** The data channel URL for a caller without an HTTP request endpoint. */
|
||||
public String execStreamUrl(ExecSession session) {
|
||||
String websocketBase = baseUrl.startsWith("https://")
|
||||
? "wss://" + baseUrl.substring("https://".length())
|
||||
: "ws://" + baseUrl.substring(baseUrl.indexOf("://") + 3);
|
||||
return websocketBase + EcsExecChannelHandler.CHANNEL_PATH_PREFIX + session.sessionId();
|
||||
return execStreamUrl(session, null);
|
||||
}
|
||||
|
||||
/** Uses the request's reachable endpoint, or configured base URL for non-HTTP callers. */
|
||||
public String execStreamUrl(ExecSession session, URI requestBaseUri) {
|
||||
URI endpoint = requestBaseUri != null ? requestBaseUri : URI.create(baseUrl);
|
||||
return UriBuilder.fromUri(endpoint)
|
||||
.scheme("https".equalsIgnoreCase(endpoint.getScheme()) ? "wss" : "ws")
|
||||
.path(EcsExecChannelHandler.CHANNEL_PATH_PREFIX)
|
||||
.path(session.sessionId())
|
||||
.build().toString();
|
||||
}
|
||||
|
||||
/** A container reached through the task metadata endpoint, with the task it belongs to. */
|
||||
|
||||
Reference in new issue
Block a user