/** * Copyright (c) 2025-present, Goldman Sachs * * 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. */ import { V1_EntitlementsLakehouseEnvironmentType, V1_IngestEnvironmentClassification, V1_isIngestEnvsCompatibleWithEntitlements, } from '@finos/legend-graph'; import type { IngestDeploymentServerConfig } from '../models/IngestDeploymentServerConfig.js'; export const getIngestDeploymentServerConfigName = ( serverConf: IngestDeploymentServerConfig, ): string | undefined => { const baseUrl = new URL(serverConf.ingestServerUrl).hostname; const subdomain = baseUrl.split('.')[0]; const parts = subdomain?.split('-'); return parts?.slice(0, -1).join('-'); }; export enum LakehouseEnvironmentType { DEVELOPMENT = 'dev', PRODUCTION_PARALLEL = 'pp', } export const getEntitlementsLakehouseEnvironmentTypeCompatibleWithEnvName = ( envName: string, ): V1_EntitlementsLakehouseEnvironmentType => { if (envName.startsWith(`${LakehouseEnvironmentType.DEVELOPMENT}-`)) { return V1_EntitlementsLakehouseEnvironmentType.DEVELOPMENT; } else if ( envName.endsWith(`-${LakehouseEnvironmentType.PRODUCTION_PARALLEL}`) ) { return V1_EntitlementsLakehouseEnvironmentType.PRODUCTION_PARALLEL; } return V1_EntitlementsLakehouseEnvironmentType.PRODUCTION; }; export const buildEnvNameCompatibleWithLakehouseEnvironmentType = ( envName: string, entitlementType: string, ): string => { if (entitlementType === V1_EntitlementsLakehouseEnvironmentType.DEVELOPMENT) { return `${LakehouseEnvironmentType.DEVELOPMENT}-${envName}`; } else if ( entitlementType === V1_EntitlementsLakehouseEnvironmentType.PRODUCTION_PARALLEL ) { return `${envName}-${LakehouseEnvironmentType.PRODUCTION_PARALLEL}`; } return envName; }; export const isLakehouseEnvironmentType = (envName: string): boolean => { return ( envName.startsWith(`${LakehouseEnvironmentType.DEVELOPMENT}-`) || envName.endsWith(`-${LakehouseEnvironmentType.PRODUCTION_PARALLEL}`) || !Object.values(V1_EntitlementsLakehouseEnvironmentType).includes( envName as V1_EntitlementsLakehouseEnvironmentType, ) ); }; export type IngestDeploymentServerConfigOption = { value: IngestDeploymentServerConfig; label: string; }; export const buildIngestDeploymentServerConfigOption = ( serverConf: IngestDeploymentServerConfig, ): IngestDeploymentServerConfigOption => { const envLabel = serverConf.environmentClassification === V1_IngestEnvironmentClassification.PROD ? '' : ` [${serverConf.environmentClassification}] `; return { value: serverConf, label: `${serverConf.environmentName}${envLabel}`, }; }; export const filterEnvironmentsByEntitlementsEnv = ( entitlementsType: V1_EntitlementsLakehouseEnvironmentType, environments: IngestDeploymentServerConfig[], ): IngestDeploymentServerConfig[] => { return environments.filter((env) => V1_isIngestEnvsCompatibleWithEntitlements( env.environmentClassification, entitlementsType, ), ); }; export const decorateEnvWithRealm = ( env: string, relam: LakehouseEnvironmentType, ): string => { if (relam === LakehouseEnvironmentType.DEVELOPMENT) { if (env.startsWith(`${LakehouseEnvironmentType.DEVELOPMENT}-`)) { return env; } return `${LakehouseEnvironmentType.DEVELOPMENT}-${env}`; } else { if (env.endsWith(`-${LakehouseEnvironmentType.PRODUCTION_PARALLEL}`)) { return env; } return `${env}-${LakehouseEnvironmentType.PRODUCTION_PARALLEL}`; } };