fix: align cloud web workbench bootstrap entry
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const GET_PROXY_PREFIXES = Object.freeze(["/v1/"]);
|
||||
const GET_PROXY_ROUTES = new Set(["/v1", "/auth/session", "/auth/bootstrap", "/auth/workspace-bootstrap"]);
|
||||
const GET_PROXY_ROUTES = new Set(["/v1", "/auth/session", "/auth/bootstrap"]);
|
||||
const POST_PROXY_ROUTES = new Set([
|
||||
"/auth/login",
|
||||
"/auth/register",
|
||||
@@ -17,7 +17,6 @@ const POST_PROXY_ROUTES = new Set([
|
||||
const PUBLIC_PROXY_ROUTES = new Set([
|
||||
"GET /auth/session",
|
||||
"GET /auth/bootstrap",
|
||||
"GET /auth/workspace-bootstrap",
|
||||
"POST /auth/login",
|
||||
"POST /auth/register",
|
||||
"POST /auth/logout",
|
||||
|
||||
@@ -61,12 +61,6 @@ test("cloud web exposes auth bootstrap as a public auth route", () => {
|
||||
publicRoute: true,
|
||||
routeKey: "GET /auth/bootstrap"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("GET", "/auth/workspace-bootstrap"), {
|
||||
proxy: true,
|
||||
authRequired: false,
|
||||
publicRoute: true,
|
||||
routeKey: "GET /auth/workspace-bootstrap"
|
||||
});
|
||||
assert.deepEqual(cloudWebProxyRoutePolicy("POST", "/auth/register"), {
|
||||
proxy: true,
|
||||
authRequired: false,
|
||||
|
||||
@@ -15,7 +15,6 @@ const readOnlyRpcMethods = new Set([
|
||||
]);
|
||||
const gzipAsync = promisify(gzip);
|
||||
const GZIP_MIN_BYTES = 1024;
|
||||
const DEFAULT_WORKBENCH_PROJECT_ID = "prj_hwpod_workbench";
|
||||
const CLIENT_DISCONNECT_ERROR_CODES = new Set([
|
||||
"ECONNRESET",
|
||||
"EPIPE",
|
||||
@@ -191,10 +190,6 @@ function logCloudWebRuntimeEvent(event, { serviceId, request = null, error = nul
|
||||
|
||||
export async function handleCloudWebAuth(options) {
|
||||
const { request, response, url } = options;
|
||||
if (url.pathname === "/auth/workspace-bootstrap" && request.method === "GET") {
|
||||
await handleWorkspaceBootstrap(options);
|
||||
return true;
|
||||
}
|
||||
if (url.pathname === "/auth/bootstrap" && request.method === "GET") {
|
||||
await handleAuthBootstrap(options);
|
||||
return true;
|
||||
@@ -231,47 +226,11 @@ async function handleAuthBootstrap(options) {
|
||||
sendJsonWithForwardedCookies(response, auth.statusCode || 502, auth.body ?? { authenticated: false, error: "auth_bootstrap_failed" }, auth.headers);
|
||||
}
|
||||
|
||||
async function handleWorkspaceBootstrap(options) {
|
||||
const { request, response, url, cloudApiBaseUrl, cloudApiProxyTimeoutMs, serviceId, sendJson } = options;
|
||||
if (!cloudApiBaseUrl) {
|
||||
sendJson(response, 503, { error: "cloud_api_base_url_missing", serviceId, path: "/auth/workspace-bootstrap" });
|
||||
return;
|
||||
}
|
||||
|
||||
const auth = await resolveAuthBootstrap({ request, cloudApiBaseUrl, cloudApiProxyTimeoutMs });
|
||||
if (auth.body?.authenticated !== true) {
|
||||
sendJsonWithForwardedCookies(response, auth.statusCode || 200, auth.body ?? { authenticated: false }, auth.headers);
|
||||
return;
|
||||
}
|
||||
|
||||
const projectId = authConfigValueFromSearch(url.searchParams.get("projectId"), DEFAULT_WORKBENCH_PROJECT_ID);
|
||||
const workspace = await requestCloudApiJson({
|
||||
request,
|
||||
method: "GET",
|
||||
pathname: `/v1/workbench/workspace?projectId=${encodeURIComponent(projectId)}`,
|
||||
headers: auth.cookieHeader ? { cookie: auth.cookieHeader } : {},
|
||||
cloudApiBaseUrl,
|
||||
cloudApiProxyTimeoutMs
|
||||
});
|
||||
const body = {
|
||||
...(auth.body ?? { authenticated: true }),
|
||||
projectId,
|
||||
workspace: workspace.ok ? workspace.body?.workspace ?? null : null,
|
||||
workspaceStatus: workspace.statusCode || null,
|
||||
workspaceError: workspace.ok ? null : workspace.body?.error ?? workspace.body?.message ?? null
|
||||
};
|
||||
sendJsonWithForwardedCookies(response, auth.statusCode || 200, body, auth.headers);
|
||||
}
|
||||
|
||||
async function resolveAuthBootstrap({ request, cloudApiBaseUrl, cloudApiProxyTimeoutMs }) {
|
||||
const session = await requestCloudApiJson({ request, method: "GET", pathname: "/auth/session", cloudApiBaseUrl, cloudApiProxyTimeoutMs });
|
||||
return withCookieHeader(request, session);
|
||||
}
|
||||
|
||||
function authConfigValueFromSearch(value, fallback) {
|
||||
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
||||
}
|
||||
|
||||
function requestCloudApiJson({ request, method, pathname, body = "", headers = {}, cloudApiBaseUrl, cloudApiProxyTimeoutMs }) {
|
||||
return new Promise((resolve) => {
|
||||
let settled = false;
|
||||
|
||||
Reference in New Issue
Block a user