fix(ui): show configured defaults on the dashboard (#8317)

The dashboard's Connect panel and its Shell and boto3 snippets showed us-east-1 and account 000000000000 whatever the emulator was configured with. They now take the region and account from the defaults /_floci/info reports, as soon as it answers rather than after every dashboard request settles, refresh the selected snippet when the region arrives, and keep the built-in values when the manifest omits them.

DashboardConnectUsesConfiguredDefaultsTest checks the page from index.html in the JUnit suite.

Closes #8282
This commit is contained in:
Rashen Anupama authored and GitHub committed 2026-11-21 16:40:41 -04:00
1 parent 1fe555fbc2
commit 22ddd72f8f
2 files changed
+111 -8

No files matched your search

+31 -8
View File
@@ -469,18 +469,37 @@
}
// ── Connect ──────────────────────────────────────────
var SNIPPETS = {
shell: "export AWS_ENDPOINT_URL=" + endpoint + "\nexport AWS_ACCESS_KEY_ID=test\nexport AWS_SECRET_ACCESS_KEY=test\nexport AWS_DEFAULT_REGION=us-east-1",
cli: "aws --endpoint-url " + endpoint + " s3 mb s3://demo\naws --endpoint-url " + endpoint + " s3 ls",
boto3: 'import boto3\n\ns3 = boto3.client(\n "s3",\n endpoint_url="' + endpoint + '",\n region_name="us-east-1",\n aws_access_key_id="test",\n aws_secret_access_key="test",\n)'
};
var activeSnippet = "shell";
var connectRegion = "us-east-1";
function renderSnippet() {
var snippets = {
shell: "export AWS_ENDPOINT_URL=" + endpoint + "\nexport AWS_ACCESS_KEY_ID=test\nexport AWS_SECRET_ACCESS_KEY=test\nexport AWS_DEFAULT_REGION=" + connectRegion,
cli: "aws --endpoint-url " + endpoint + " s3 mb s3://demo\naws --endpoint-url " + endpoint + " s3 ls",
boto3: 'import boto3\n\ns3 = boto3.client(\n "s3",\n endpoint_url="' + endpoint + '",\n region_name="' + connectRegion + '",\n aws_access_key_id="test",\n aws_secret_access_key="test",\n)'
};
$("snippet").textContent = snippets[activeSnippet];
}
function renderConnect(info) {
var defaults = info && info.defaults;
if (!defaults) { return; }
if (defaults.account_id) { $("f-account").textContent = defaults.account_id; }
if (defaults.region && defaults.region !== connectRegion) {
connectRegion = defaults.region;
$("f-region").textContent = connectRegion;
renderSnippet();
}
}
$("f-endpoint").textContent = endpoint;
$("snippet").textContent = SNIPPETS.shell;
renderSnippet();
document.querySelectorAll(".tab").forEach(function (tab) {
tab.addEventListener("click", function () {
document.querySelectorAll(".tab").forEach(function (t) { t.setAttribute("aria-selected", String(t === tab)); });
$("snippet").textContent = SNIPPETS[tab.dataset.snippet];
activeSnippet = tab.dataset.snippet;
renderSnippet();
});
});
@@ -633,7 +652,11 @@
function refresh() {
if (refreshing) { return; }
refreshing = true;
Promise.allSettled([getJson("/_floci/health"), getJson("/_floci/init"), getJson("/_floci/info"), getJson("/_floci/ui/status")])
var info = getJson("/_floci/info").then(function (manifest) {
renderConnect(manifest);
return manifest;
});
Promise.allSettled([getJson("/_floci/health"), getJson("/_floci/init"), info, getJson("/_floci/ui/status")])
.then(function (results) {
var v = results.map(function (r) { return r.status === "fulfilled" ? r.value : null; });
var health = v[0], init = v[1];
@@ -0,0 +1,80 @@
package io.floci.aws.services.floci.ui;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Guards the dashboard's Connect panel, which shows the region and account an SDK should use and
* the Shell and boto3 snippets built from them: they come from the defaults {@code /_floci/info}
* reports, as soon as it answers, and the built-in values stay when it does not report them.
*/
class DashboardConnectUsesConfiguredDefaultsTest {
private static final Path LANDING_PAGE = Path.of("src", "main", "resources", "ui", "index.html");
private static final Pattern REGION_LABEL_READ = Pattern.compile("\\(\"f-region\"\\)\\.textContent\\s*(?:[^=\\s]|==)");
private static final Pattern INFO_RENDERED_ON_ARRIVAL =
Pattern.compile("getJson\\(\"/_floci/info\"\\)\\.then\\(function \\(manifest\\) \\{\\s*renderConnect\\(manifest\\);");
// Catches: a snippet that hardcodes us-east-1, so an emulator on another region hands out
// commands and code that point the SDK at the wrong one.
@Test
void snippetsUseTheRegionTheManifestReports() {
String content = readLandingPage();
assertTrue(content.contains("AWS_DEFAULT_REGION=\" + connectRegion"),
"the Shell snippet must take its region from connectRegion");
assertTrue(content.contains("region_name=\"' + connectRegion"),
"the boto3 snippet must take its region from connectRegion");
assertFalse(content.contains("AWS_DEFAULT_REGION=us-east-1") || content.contains("region_name=\"us-east-1\""),
"no snippet may hardcode the built-in region");
}
// Catches: a snippet that reads the region back from the panel's label, so any text added to
// the label lands in the generated commands and code.
@Test
void snippetsNeverReadTheRegionBackFromThePanelLabel() {
assertFalse(REGION_LABEL_READ.matcher(readLandingPage()).find(),
"index.html must only write the region label, never read it back");
}
// Catches: the Connect panel waiting for every dashboard request to settle, so a slow
// /_floci/ui/status holds back the region and account the manifest already gave.
@Test
void theManifestIsAppliedAsSoonAsInfoAnswers() {
assertTrue(INFO_RENDERED_ON_ARRIVAL.matcher(readLandingPage()).find(),
"index.html must render the Connect defaults in /_floci/info's own callback");
}
// Catches: a manifest without defaults, or the region or account missing from them, blanking
// the built-in values shown before it arrived.
@Test
void theBuiltInValuesStayWhenTheManifestOmitsThem() {
String content = readLandingPage();
assertTrue(content.contains("<dd id=\"f-region\">us-east-1</dd>")
&& content.contains("<dd id=\"f-account\">000000000000</dd>")
&& content.contains("var connectRegion = \"us-east-1\";"),
"the panel and the snippets must start from the built-in region and account");
assertTrue(content.contains("if (!defaults) { return; }")
&& content.contains("if (defaults.account_id) {")
&& content.contains("if (defaults.region && defaults.region !== connectRegion) {"),
"the panel must change a value only when the manifest reports it");
}
private static String readLandingPage() {
try {
return Files.readString(LANDING_PAGE, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}