Skip to content

Commit 8b0d3cc

Browse files
authored
fix: Add CODE_SNIPPET_USE_AUTO_CONFIG environment variable (#883)
* Add CODE_SNIPPET_USE_AUTO_CONFIG environment variable Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com> * Fix eslint Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com> --------- Signed-off-by: ddl-rliu <richard.liu@dominodatalab.com>
1 parent 7636e32 commit 8b0d3cc

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

packages/common/src/environment/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ export interface Env extends NodeJS.ProcessEnv {
3333
* @example MAINTENANCE_MODE="We are currently down for maintenance.\n\nPlease try again later."
3434
*/
3535
MAINTENANCE_MODE?: string;
36+
37+
/**
38+
* Controls whether the config object in the inputs/outputs Python code snippet is automatically constructed
39+
* Leave unset to use the config object for endpoint window.location.host
40+
*/
41+
CODE_SNIPPET_USE_AUTO_CONFIG?: string;
3642
}
3743

3844
/** Represents a plain object where string keys map to values of the same type */

packages/oss-console/src/components/Executions/ExecutionDetails/ExecutionNodeURL.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
33
import { prism } from 'react-syntax-highlighter/dist/esm/styles/prism';
44
import FileCopyIcon from '@mui/icons-material/FileCopy';
55
import copyToClipboard from 'copy-to-clipboard';
6+
import { env } from '@clients/common/environment';
67
import { errorBackgroundColor } from '@clients/theme/CommonStyles/constants';
78
import Button from '@mui/material/Button';
89
import Typography from '@mui/material/Typography';
@@ -31,19 +32,19 @@ export const ExecutionNodeURL: React.FC<{
3132
const isHttps = /^https:/.test(window.location.href);
3233
const ref = React.useRef<HTMLDivElement>(null);
3334

34-
const code = isHttps
35-
? // https snippet
36-
`from flytekit.remote.remote import FlyteRemote
35+
const config =
36+
// eslint-disable-next-line no-nested-ternary
37+
env.CODE_SNIPPET_USE_AUTO_CONFIG === "true"
38+
? 'Config.auto()'
39+
: isHttps
40+
? // https snippet
41+
`Config.for_endpoint("${window.location.host}")`
42+
: // http snippet
43+
`Config.for_endpoint("${window.location.host}", True)`;
44+
const code = `from flytekit.remote.remote import FlyteRemote
3745
from flytekit.configuration import Config
3846
remote = FlyteRemote(
39-
Config.for_endpoint("${window.location.host}"),
40-
)
41-
remote.get("${dataSourceURI}")`
42-
: // http snippet
43-
`from flytekit.remote.remote import FlyteRemote
44-
from flytekit.configuration import Config
45-
remote = FlyteRemote(
46-
Config.for_endpoint("${window.location.host}", True),
47+
${config},
4748
)
4849
remote.get("${dataSourceURI}")`;
4950

website/console/env/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ const ASSETS_PATH = `${BASE_URL}/assets/`;
7777
*/
7878
const MAINTENANCE_MODE = process.env.MAINTENANCE_MODE || '';
7979

80+
/**
81+
* Controls whether the config object in the inputs/outputs Python code snippet is automatically constructed
82+
*/
83+
const CODE_SNIPPET_USE_AUTO_CONFIG = process.env.CODE_SNIPPET_USE_AUTO_CONFIG || '';
84+
8085
const processEnv = {
8186
NODE_ENV,
8287
PORT,
@@ -86,6 +91,7 @@ const processEnv = {
8691
BASE_HREF,
8792
DISABLE_CONSOLE_ROUTE_PREFIX,
8893
MAINTENANCE_MODE,
94+
CODE_SNIPPET_USE_AUTO_CONFIG,
8995
};
9096

9197
export {
@@ -101,5 +107,6 @@ export {
101107
ADMIN_API,
102108
LOCAL_DEV_HOST,
103109
MAINTENANCE_MODE,
110+
CODE_SNIPPET_USE_AUTO_CONFIG,
104111
processEnv,
105112
};

0 commit comments

Comments
 (0)