-
Notifications
You must be signed in to change notification settings - Fork 253
[cueweb/docs] Add Cuebot Facility switching (server-side gateway routing) #2433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ramonfigueiredo
wants to merge
3
commits into
AcademySoftwareFoundation:master
Choose a base branch
from
ramonfigueiredo:cueweb-facility-switching
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d71bd16
[cueweb] Add Cuebot Facility switching (server-side gateway routing)
ramonfigueiredo 6908852
[cueweb/docs] Document Cuebot Facility switching (server-side gateway…
ramonfigueiredo 7b4f332
[cueweb] Harden facility gateway resolution and cookie parsing
ramonfigueiredo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Copyright Contributors to the OpenCue Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Server-side Cuebot facility resolver (CueGUI "Cuebot Facility" parity). | ||
| * | ||
| * CueGUI maps a facility name to a list of Cuebot host:port pairs | ||
| * (`cuebot.facility` in opencue's config) and rewires the gRPC connection | ||
| * when the user switches (`Cuebot.setHostWithFacility`). CueWeb talks to the | ||
| * REST gateway rather than gRPC directly, so the CueWeb analog maps a facility | ||
| * name to a REST-gateway base URL + the JWT secret that gateway trusts. | ||
| * | ||
| * The selected facility travels from the browser to the server in a cookie | ||
| * (see `FACILITY_COOKIE`); every gateway-bound API route resolves the target | ||
| * for the current request via `getRequestFacilityTarget()`. | ||
| * | ||
| * Configuration (all server-side, optional): | ||
| * NEXT_PUBLIC_CUEBOT_FACILITIES comma-separated facility names (the menu). | ||
| * CUEBOT_<NAME>_REST_GATEWAY_URL gateway base URL for that facility. | ||
| * CUEBOT_<NAME>_JWT_SECRET JWT secret for that facility's gateway. | ||
| * | ||
| * When a facility has no explicit *_REST_GATEWAY_URL / *_JWT_SECRET, it falls | ||
| * back to the legacy single-gateway vars (NEXT_PUBLIC_OPENCUE_ENDPOINT / | ||
| * NEXT_JWT_SECRET), so the default deployment keeps working with zero new | ||
| * config and only the `local` facility wired up. | ||
| * | ||
| * NOTE: `getRequestFacilityTarget()` reads `next/headers` and only runs | ||
| * server-side. It uses a *dynamic* import so this module stays free of a | ||
| * static `next/headers` dependency — `api_utils.ts` (which imports this | ||
| * module) is also part of the client bundle, and Next.js forbids a static | ||
| * `next/headers` import anywhere in the client graph. The pure helpers below | ||
| * are safe to import from anywhere. Client components that need the cookie | ||
| * name use the literal in `use_cuebot_facility.ts`, kept in sync with | ||
| * `FACILITY_COOKIE`. | ||
| */ | ||
|
|
||
| /** Cookie carrying the selected facility name. Mirrors the localStorage value | ||
| * written by `useCuebotFacility`; must match the literal there. */ | ||
| export const FACILITY_COOKIE = "cueweb.facility"; | ||
|
|
||
| /** Default facility list — matches CueGUI's example `cuebot.facility` keys. */ | ||
| const DEFAULT_FACILITIES = ["local", "dev", "cloud", "external"] as const; | ||
|
|
||
| export interface FacilityTarget { | ||
| /** The resolved (validated) facility name. */ | ||
| name: string; | ||
| /** REST gateway base URL to send this request to. */ | ||
| gatewayUrl: string; | ||
| /** JWT secret the target gateway trusts. */ | ||
| jwtSecret: string; | ||
| } | ||
|
|
||
| /** The configured facility names (the menu). Falls back to the CueGUI defaults. */ | ||
| export function getConfiguredFacilities(): string[] { | ||
| const raw = process.env.NEXT_PUBLIC_CUEBOT_FACILITIES ?? ""; | ||
| const parsed = raw | ||
| .split(",") | ||
| .map((s) => s.trim()) | ||
| .filter((s) => s.length > 0); | ||
| return parsed.length > 0 ? parsed : [...DEFAULT_FACILITIES]; | ||
| } | ||
|
|
||
| /** "dev" -> "CUEBOT_DEV_REST_GATEWAY_URL". Non-alphanumerics become "_". */ | ||
| function envKey(facility: string, suffix: string): string { | ||
| const norm = facility.toUpperCase().replace(/[^A-Z0-9]+/g, "_"); | ||
| return `CUEBOT_${norm}_${suffix}`; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve a facility name to its gateway target. Unknown / unconfigured names | ||
| * fall back to the first configured facility (the default), mirroring CueGUI's | ||
| * `setHostWithFacility` which falls back to `cuebot.facility_default`. | ||
| */ | ||
| export function resolveFacilityTarget(name: string | undefined): FacilityTarget { | ||
| const facilities = getConfiguredFacilities(); | ||
| const fallbackName = facilities[0] ?? "local"; | ||
| const facility = name && facilities.includes(name) ? name : fallbackName; | ||
|
|
||
| const gatewayUrl = | ||
| process.env[envKey(facility, "REST_GATEWAY_URL")] ?? | ||
| process.env.NEXT_PUBLIC_OPENCUE_ENDPOINT ?? | ||
| ""; | ||
| const jwtSecret = | ||
| process.env[envKey(facility, "JWT_SECRET")] ?? | ||
| process.env.NEXT_JWT_SECRET ?? | ||
| ""; | ||
|
|
||
| return { name: facility, gatewayUrl, jwtSecret }; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the facility target for the current request, reading the selection | ||
| * from the request cookie and validating it against the configured list. | ||
| * Safe to call outside a request scope (returns the default target). | ||
| */ | ||
| export async function getRequestFacilityTarget(): Promise<FacilityTarget> { | ||
| let selected: string | undefined; | ||
| try { | ||
| // Dynamic import keeps next/headers out of the static client graph. | ||
| const { cookies } = await import("next/headers"); | ||
| const store = await cookies(); | ||
| selected = store.get(FACILITY_COOKIE)?.value; | ||
| } catch { | ||
| // Not in a request scope (e.g. build-time): use the default. | ||
| } | ||
| return resolveFacilityTarget(selected); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.