UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

30 lines 1.25 kB
import { ServiceLifecycle } from './ServiceLifecycle.js'; const REQUIRED_METHOD_NAMES = ['createDefaultConfigSection', 'validateConfigSection', 'createTerraformPayload', 'createSecretPayload']; const CAPABILITY_METHOD_NAMES = { failureDiagnostics: ['logTerraformApplyFailureDetails'], runtimeInputs: ['resolveRuntimeInputs'], terraformImports: ['getTerraformImportTargets', 'doesTerraformImportTargetExist'] }; const assertMethodOverride = (service, methodName) => { if (service[methodName] === ServiceLifecycle.prototype[methodName]) { throw new Error(`Atlas service ${service.id} must implement ${methodName}().`); } }; export const validateServiceLifecycle = service => { if (!(service instanceof ServiceLifecycle)) { throw new Error('Atlas services must extend ServiceLifecycle.'); } for (const methodName of REQUIRED_METHOD_NAMES) { assertMethodOverride(service, methodName); } for (const [capabilityName, methodNames] of Object.entries(CAPABILITY_METHOD_NAMES)) { if (service.capabilities[capabilityName] !== true) { continue; } for (const methodName of methodNames) { assertMethodOverride(service, methodName); } } return service; }; export default validateServiceLifecycle;