Skip to content
Snippets Groups Projects
Commit f245fd91 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

make configration better and more readable

parent 2c7592ac
No related branches found
No related tags found
1 merge request!20New GUI V2 structure
import process from 'process';
import { Environment, OrchestratorConfig } from '@orchestrator-ui/orchestrator-ui-components';
import {
Environment,
OrchestratorConfig,
} from '@orchestrator-ui/orchestrator-ui-components';
export const DEFAULT_GRAPHQL_CORE_ENDPOINT =
'http://localhost:8080/api/graphql';
// Default configurations
export const DEFAULT_GRAPHQL_CORE_ENDPOINT = 'http://localhost:8080/api/graphql';
export const DEFAULT_ORCHESTRATOR_API_BASE_URL = 'http://localhost:8080/api';
export const DEFAULT_ORCHESTRATOR_WEBSOCKET_URL = 'ws://localhost:8080';
export const ENGINE_STATUS_ENDPOINT = '/settings/status';
export const PROCESSES_ENDPOINT = '/processes';
export const SUBSCRIPTION_ACTIONS_ENDPOINT = '/subscriptions/workflows';
export const SUBSCRIPTION_PROCESSES_ENDPOINT =
'/processes/process-subscriptions-by-subscription-id';
export const SUBSCRIPTION_PROCESSES_ENDPOINT = '/processes/process-subscriptions-by-subscription-id';
export const DEFAULT_WORKFLOW_INFORMATION_LINK_URL = 'http://localhost:8080';
interface EnvConfig {
ORCHESTRATOR_GRAPHQL_HOST?: string;
ORCHESTRATOR_GRAPHQL_PATH?: string;
ORCHESTRATOR_API_HOST?: string;
ORCHESTRATOR_API_PATH?: string;
ORCHESTRATOR_WEBSOCKET_URL?: string;
ENVIRONMENT_NAME?: string;
AUTH_ACTIVE?: string;
USE_WEB_SOCKETS?: string;
USE_THEME_TOGGLE?: string;
WORKFLOW_INFORMATION_LINK_URL?: string;
SHOW_WORKFLOW_INFORMATION_LINK?: string;
}
const getEnvValue = (envVar: string | undefined, defaultValue: string): string =>
envVar || defaultValue;
const getBooleanEnvValue = (envVar: string | undefined, defaultValue: boolean): boolean =>
envVar ? envVar.toLowerCase() === 'true' : defaultValue;
// Assemble the Orchestrator configuration from environment variables
export const getInitialOrchestratorConfig = (): OrchestratorConfig => {
const orchestratorGraphqlBaseUrl =
process.env.ORCHESTRATOR_GRAPHQL_HOST &&
process.env.ORCHESTRATOR_GRAPHQL_PATH
? `${process.env.ORCHESTRATOR_GRAPHQL_HOST}${process.env.ORCHESTRATOR_GRAPHQL_PATH}`
: DEFAULT_GRAPHQL_CORE_ENDPOINT;
const env = process.env as unknown as EnvConfig;
// Construct URLs based on environment or defaults
const orchestratorGraphqlBaseUrl = env.ORCHESTRATOR_GRAPHQL_HOST && env.ORCHESTRATOR_GRAPHQL_PATH
? `${env.ORCHESTRATOR_GRAPHQL_HOST}${env.ORCHESTRATOR_GRAPHQL_PATH}`
: DEFAULT_GRAPHQL_CORE_ENDPOINT;
const orchestratorApiBaseUrl =
process.env.ORCHESTRATOR_API_HOST && process.env.ORCHESTRATOR_API_PATH
? `${process.env.ORCHESTRATOR_API_HOST}${process.env.ORCHESTRATOR_API_PATH}`
: DEFAULT_ORCHESTRATOR_API_BASE_URL;
const orchestratorApiBaseUrl = env.ORCHESTRATOR_API_HOST && env.ORCHESTRATOR_API_PATH
? `${env.ORCHESTRATOR_API_HOST}${env.ORCHESTRATOR_API_PATH}`
: DEFAULT_ORCHESTRATOR_API_BASE_URL;
return {
orchestratorApiBaseUrl,
engineStatusEndpoint: orchestratorApiBaseUrl + ENGINE_STATUS_ENDPOINT,
graphqlEndpointCore: orchestratorGraphqlBaseUrl,
processesEndpoint: orchestratorApiBaseUrl + PROCESSES_ENDPOINT,
environmentName:
process.env.ENVIRONMENT_NAME ?? Environment.DEVELOPMENT,
subscriptionActionsEndpoint:
orchestratorApiBaseUrl + SUBSCRIPTION_ACTIONS_ENDPOINT,
subscriptionProcessesEndpoint:
orchestratorApiBaseUrl + SUBSCRIPTION_PROCESSES_ENDPOINT,
orchestratorWebsocketUrl:
process.env.ORCHESTRATOR_WEBSOCKET_URL ||
DEFAULT_ORCHESTRATOR_WEBSOCKET_URL,
authActive: process.env.AUTH_ACTIVE?.toLowerCase() != 'false',
useWebSockets: process.env.USE_WEB_SOCKETS?.toLowerCase() === 'true',
useThemeToggle: process.env.USE_THEME_TOGGLE?.toLowerCase() === 'true',
workflowInformationLinkUrl:
process.env.WORKFLOW_INFORMATION_LINK_URL ??
DEFAULT_WORKFLOW_INFORMATION_LINK_URL,
showWorkflowInformationLink:
process.env.SHOW_WORKFLOW_INFORMATION_LINK?.toLowerCase() ===
'true',
environmentName: getEnvValue(env.ENVIRONMENT_NAME, Environment.DEVELOPMENT),
subscriptionActionsEndpoint: orchestratorApiBaseUrl + SUBSCRIPTION_ACTIONS_ENDPOINT,
subscriptionProcessesEndpoint: orchestratorApiBaseUrl + SUBSCRIPTION_PROCESSES_ENDPOINT,
orchestratorWebsocketUrl: getEnvValue(env.ORCHESTRATOR_WEBSOCKET_URL, DEFAULT_ORCHESTRATOR_WEBSOCKET_URL),
authActive: getBooleanEnvValue(env.AUTH_ACTIVE, true),
useWebSockets: getBooleanEnvValue(env.USE_WEB_SOCKETS, false),
useThemeToggle: getBooleanEnvValue(env.USE_THEME_TOGGLE, false),
workflowInformationLinkUrl: getEnvValue(env.WORKFLOW_INFORMATION_LINK_URL, DEFAULT_WORKFLOW_INFORMATION_LINK_URL),
showWorkflowInformationLink: getBooleanEnvValue(env.SHOW_WORKFLOW_INFORMATION_LINK, false),
};
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment