mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(ui): serve the Console Contract v2 manifest and pass its URL to the console (#6711)
* feat(ui): serve the Console Contract v2 manifest and pass its URL to the console /_floci/info and /_localstack/info now carry manifest_version, console_contract, cloud, endpoint, health_url, tls, services, defaults and ui, keeping their existing keys. FlociUiManager injects FLOCI_INFO_URL so the console can read it. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * test(ui): drop the DisplayName from the manifest test Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
78278f4a04
commit
258994c1b9
6 files changed
+147
-4
No files matched your search
@@ -29,12 +29,15 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@Path("{prefix:(_floci|_localstack)}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class EmulatorInfoController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EmulatorInfoController.class);
|
||||
static final int MANIFEST_VERSION = 1;
|
||||
static final int CONSOLE_CONTRACT = 2;
|
||||
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
private final InitLifecycleState initLifecycleState;
|
||||
@@ -99,11 +102,48 @@ public class EmulatorInfoController {
|
||||
return Response.ok(body).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The emulator manifest of the Floci Console Contract v2: what a web console, or a script, needs to
|
||||
* know about this emulator. Additive over the original {@code version}, {@code edition},
|
||||
* {@code original_edition} and {@code dynamodb_backend} keys, which stay as they were.
|
||||
*/
|
||||
@GET
|
||||
@Path("/info")
|
||||
public Response info() {
|
||||
return Response.ok(Map.of("version", version, "edition", "community", "original_edition", "floci-always-free",
|
||||
"dynamodb_backend", dynamoDbBackendSelector.selected())).build();
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("manifest_version", MANIFEST_VERSION);
|
||||
body.put("console_contract", CONSOLE_CONTRACT);
|
||||
body.put("cloud", "aws");
|
||||
body.put("emulator", "floci");
|
||||
body.put("version", version);
|
||||
body.put("edition", "community");
|
||||
body.put("original_edition", "floci-always-free");
|
||||
body.put("dynamodb_backend", dynamoDbBackendSelector.selected());
|
||||
body.put("endpoint", config.effectiveBaseUrl());
|
||||
body.put("health_url", "/_floci/health");
|
||||
body.put("tls", Map.of("enabled", config.tls().enabled()));
|
||||
body.put("services", manifestServices(serviceRegistry.getServices()));
|
||||
|
||||
Map<String, Object> defaults = new LinkedHashMap<>();
|
||||
defaults.put("region", config.defaultRegion());
|
||||
defaults.put("account_id", config.defaultAccountId());
|
||||
body.put("defaults", defaults);
|
||||
|
||||
Map<String, Object> ui = new LinkedHashMap<>();
|
||||
ui.put("enabled", config.services().ui().enabled());
|
||||
ui.put("port", config.services().ui().port());
|
||||
body.put("ui", ui);
|
||||
return Response.ok(body).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The health map's {@code running} and {@code available}, as the manifest's {@code enabled} and
|
||||
* {@code disabled}.
|
||||
*/
|
||||
static Map<String, String> manifestServices(Map<String, String> healthServices) {
|
||||
Map<String, String> services = new TreeMap<>();
|
||||
healthServices.forEach((name, status) -> services.put(name, "running".equals(status) ? "enabled" : "disabled"));
|
||||
return services;
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -355,6 +355,7 @@ public class FlociUiManager {
|
||||
}
|
||||
env.put(PORT_ENV, String.valueOf(console.internalPort()));
|
||||
env.put("FLOCI_CLOUD", FLOCI_CLOUD);
|
||||
env.put("FLOCI_INFO_URL", infoUrl(endpoint));
|
||||
if (config.services().ui().insecureSkipTlsVerify()) {
|
||||
LOG.warn("floci.services.ui.insecure-skip-tls-verify=true: the web console sidecar will "
|
||||
+ "not verify Floci's TLS certificate. Intended for Floci's self-signed "
|
||||
@@ -370,6 +371,12 @@ public class FlociUiManager {
|
||||
return rendered;
|
||||
}
|
||||
|
||||
/** Console Contract v2's {@code FLOCI_INFO_URL}: the manifest, at the address the console reaches Floci on. */
|
||||
static String infoUrl(String endpoint) {
|
||||
String base = endpoint.endsWith("/") ? endpoint.substring(0, endpoint.length() - 1) : endpoint;
|
||||
return base + "/_floci/info";
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges operator-supplied {@code KEY=VALUE} entries over the injected defaults.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user