Skip to content

Commit

Permalink
Add CODE_SNIPPET_URL to config
Browse files Browse the repository at this point in the history
Signed-off-by: ddl-rliu <[email protected]>
  • Loading branch information
ddl-rliu committed Jul 22, 2024
1 parent 7636e32 commit 4aa12ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/common/src/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface Env extends NodeJS.ProcessEnv {
* @example MAINTENANCE_MODE="We are currently down for maintenance.\n\nPlease try again later."
*/
MAINTENANCE_MODE?: string;

/**
* Controls the endpoint used in Python code snippet, leave unset to use the default window.location.host
*/
CODE_SNIPPET_URL?: string;
}

/** Represents a plain object where string keys map to values of the same type */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Grid from '@mui/material/Grid';
import Link from '@mui/material/Link';
import { RowExpander } from '../Tables/RowExpander';
import { ScrollableMonospaceText } from '../../common/ScrollableMonospaceText';
import { env } from '@clients/common/environment';

const StyledScrollableMonospaceText = styled(ScrollableMonospaceText)(({ theme }) => ({
'&>div': {
Expand All @@ -28,22 +29,23 @@ export const ExecutionNodeURL: React.FC<{
copyUrlText: string;
}> = ({ dataSourceURI, copyUrlText }) => {
const [expanded, setExpanded] = React.useState<boolean>(false);
const isHttps = /^https:/.test(window.location.href);
const codeSnippetUrl = new URL(env.CODE_SNIPPET_URL || window.location.href);
const isHttps = /^https:/.test(codeSnippetUrl.protocol);
const ref = React.useRef<HTMLDivElement>(null);

const code = isHttps
? // https snippet
`from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}"),
Config.for_endpoint("${codeSnippetUrl.host}"),
)
remote.get("${dataSourceURI}")`
: // http snippet
`from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}", True),
Config.for_endpoint("${codeSnippetUrl.host}", True),
)
remote.get("${dataSourceURI}")`;

Expand Down
7 changes: 7 additions & 0 deletions website/console/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const ASSETS_PATH = `${BASE_URL}/assets/`;
*/
const MAINTENANCE_MODE = process.env.MAINTENANCE_MODE || '';

/**
* Controls the endpoint used in Python code snippet
*/
const CODE_SNIPPET_URL = process.env.CODE_SNIPPET_URL || '';

const processEnv = {
NODE_ENV,
PORT,
Expand All @@ -86,6 +91,7 @@ const processEnv = {
BASE_HREF,
DISABLE_CONSOLE_ROUTE_PREFIX,
MAINTENANCE_MODE,
CODE_SNIPPET_URL,
};

export {
Expand All @@ -101,5 +107,6 @@ export {
ADMIN_API,
LOCAL_DEV_HOST,
MAINTENANCE_MODE,
CODE_SNIPPET_URL,
processEnv,
};

0 comments on commit 4aa12ed

Please sign in to comment.