@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
116 lines • 5.38 kB
JavaScript
import { isBoolean, isString } from 'es-toolkit/compat';
import { clone, isPlainObject } from '../../../../utils/value.js';
export const DEFAULT_AIRBYTE_SERVICE_CHART_VERSION = '1.8.5';
export const DEFAULT_AIRBYTE_SERVICE_CONFIG = {
accessSecret: 'puls-atlas-airbyte-config',
adminEmail: null,
airbyteVersion: null,
backendTimeoutSec: 600,
bigqueryAccess: {
enabled: false,
projectId: null
},
bootloader: {},
chartName: 'airbyte',
chartRepository: 'https://airbytehq.github.io/helm-charts',
chartVersion: DEFAULT_AIRBYTE_SERVICE_CHART_VERSION,
clusterLocation: null,
clusterName: null,
configSecretName: 'airbyte-config-secrets',
createNamespace: true,
databaseStorageSize: '8Gi',
gcpServiceAccountEmail: null,
globalAddressName: null,
host: null,
ingressAnnotations: {},
ingressClassName: 'gce',
managedCertificateName: null,
minioStorageSize: '10Gi',
moduleSource: null,
namespace: 'airbyte',
nodeSelector: {},
releaseName: 'airbyte',
rootDir: null,
serviceAccountName: 'airbyte-admin',
tolerations: []
};
const AIRBYTE_CONFIG_FILE_PATH = 'services/airbyte/config.json';
const AIRBYTE_CONFIG_PROPERTY_PREFIX = 'airbyte';
const throwServiceConfigError = message => {
throw new Error(`Invalid Atlas services config. ${message}`);
};
const assertObjectWhenProvided = (value, propertyPath) => {
if (value !== undefined && !isPlainObject(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be an object when provided.`);
}
};
const assertStringOrNullWhenProvided = (value, propertyPath) => {
if (value !== undefined && value !== null && !isString(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be a string or null when provided.`);
}
};
const assertBooleanWhenProvided = (value, propertyPath) => {
if (value !== undefined && !isBoolean(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be a boolean when provided.`);
}
};
const assertPositiveIntegerWhenProvided = (value, propertyPath) => {
if (value === undefined || value === null) {
return;
}
if (!Number.isInteger(value) || value < 1) {
throwServiceConfigError(`The "${propertyPath}" property must be a positive integer when provided.`);
}
};
const assertArrayWhenProvided = (value, propertyPath) => {
if (value !== undefined && !Array.isArray(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be an array when provided.`);
}
};
const assertResourcesWhenProvided = (value, propertyPath) => {
if (value === undefined) {
return;
}
if (!isPlainObject(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be an object when provided.`);
}
assertObjectWhenProvided(value.limits, `${propertyPath}.limits`);
assertObjectWhenProvided(value.requests, `${propertyPath}.requests`);
};
const assertBootloaderWhenProvided = (value, propertyPath) => {
if (value === undefined) {
return;
}
if (!isPlainObject(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be an object when provided.`);
}
assertObjectWhenProvided(value.nodeSelector, `${propertyPath}.nodeSelector`);
assertArrayWhenProvided(value.tolerations, `${propertyPath}.tolerations`);
assertResourcesWhenProvided(value.resources, `${propertyPath}.resources`);
};
const assertBigQueryAccessWhenProvided = (value, propertyPath) => {
if (value === undefined) {
return;
}
if (!isPlainObject(value)) {
throwServiceConfigError(`The "${propertyPath}" property must be an object when provided.`);
}
assertBooleanWhenProvided(value.enabled, `${propertyPath}.enabled`);
assertStringOrNullWhenProvided(value.projectId, `${propertyPath}.projectId`);
};
export const createDefaultAirbyteServiceConfigSection = () => clone(DEFAULT_AIRBYTE_SERVICE_CONFIG);
export const validateAirbyteServiceConfigSection = configSection => {
if (!isPlainObject(configSection)) {
throwServiceConfigError(`The "${AIRBYTE_CONFIG_FILE_PATH}" file must contain a JSON object when provided.`);
}
for (const propertyName of ['accessSecret', 'adminEmail', 'airbyteVersion', 'chartName', 'chartRepository', 'chartVersion', 'clusterLocation', 'clusterName', 'configSecretName', 'databaseStorageSize', 'gcpServiceAccountEmail', 'globalAddressName', 'host', 'ingressClassName', 'managedCertificateName', 'minioStorageSize', 'moduleSource', 'namespace', 'releaseName', 'rootDir', 'serviceAccountName']) {
assertStringOrNullWhenProvided(configSection[propertyName], `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.${propertyName}`);
}
assertBooleanWhenProvided(configSection.createNamespace, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.createNamespace`);
assertPositiveIntegerWhenProvided(configSection.backendTimeoutSec, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.backendTimeoutSec`);
assertObjectWhenProvided(configSection.ingressAnnotations, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.ingressAnnotations`);
assertBigQueryAccessWhenProvided(configSection.bigqueryAccess, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.bigqueryAccess`);
assertBootloaderWhenProvided(configSection.bootloader, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.bootloader`);
assertObjectWhenProvided(configSection.nodeSelector, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.nodeSelector`);
assertArrayWhenProvided(configSection.tolerations, `${AIRBYTE_CONFIG_PROPERTY_PREFIX}.tolerations`);
};