diff --git a/codify.json b/codify.json index ae3e2d33..0972dc5f 100644 --- a/codify.json +++ b/codify.json @@ -21,10 +21,5 @@ }, { "type": "vscode" - }, - { - "type": "aws-configure", - "profile": "codify", - "csvCredentials": "../../../Downloads/rootkey.csv" } ] diff --git a/src/utils/errors.ts b/src/common/errors.ts similarity index 100% rename from src/utils/errors.ts rename to src/common/errors.ts diff --git a/src/common/orchestrator.ts b/src/common/orchestrator.ts index cd1b098b..111cfdb2 100644 --- a/src/common/orchestrator.ts +++ b/src/common/orchestrator.ts @@ -1,17 +1,17 @@ import { Project } from '../entities/project.js'; import { ctx, SubProcessName } from '../events/context.js'; -import { DependencyMap, PluginCollection } from '../plugins/plugin-collection.js'; +import { DependencyMap, PluginManager } from '../plugins/plugin-manager.js'; export const CommonOrchestrator = { async initializePlugins(project?: Project, secureMode = false): Promise<{ dependencyMap: DependencyMap - pluginCollection: PluginCollection, + pluginManager: PluginManager, }> { ctx.subprocessStarted(SubProcessName.INITIALIZE_PLUGINS) - const pluginCollection = new PluginCollection(); - const dependencyMap = await pluginCollection.initialize(project, secureMode); + const pluginManager = new PluginManager(); + const dependencyMap = await pluginManager.initialize(project, secureMode); ctx.subprocessFinished(SubProcessName.INITIALIZE_PLUGINS) - return { dependencyMap, pluginCollection }; + return { dependencyMap, pluginManager }; }, }; diff --git a/src/utils/types.ts b/src/common/types.ts similarity index 100% rename from src/utils/types.ts rename to src/common/types.ts diff --git a/src/entities/project-config.ts b/src/entities/project-config.ts index 6c3f24c0..35e7d3a5 100644 --- a/src/entities/project-config.ts +++ b/src/entities/project-config.ts @@ -2,7 +2,7 @@ import { ProjectSchema } from 'codify-schemas'; import { ConfigClass } from '../parser/language-definition.js'; import { ajv } from '../utils/ajv.js'; -import { RemoveMethods } from '../utils/types.js'; +import { RemoveMethods } from '../common/types.js'; import { ConfigBlock } from './config.js'; /** Project JSON supported format diff --git a/src/entities/project.ts b/src/entities/project.ts index d1be72c3..6d56d0dd 100644 --- a/src/entities/project.ts +++ b/src/entities/project.ts @@ -1,7 +1,7 @@ import { ValidateResponseData } from 'codify-schemas'; import { ctx } from '../events/context.js'; -import { DependencyMap } from '../plugins/plugin-collection.js'; +import { DependencyMap } from '../plugins/plugin-manager.js'; import { DependencyGraphResolver } from '../utils/dependency-graph-resolver.js'; import { ProjectConfig } from './project-config.js'; import { ResourceConfig } from './resource-config.js'; diff --git a/src/entities/resource-config.ts b/src/entities/resource-config.ts index 47939e61..d8361d95 100644 --- a/src/entities/resource-config.ts +++ b/src/entities/resource-config.ts @@ -2,7 +2,7 @@ import { ResourceSchema } from 'codify-schemas'; import { ConfigClass } from '../parser/language-definition.js'; import { ajv } from '../utils/ajv.js'; -import { RemoveMethods } from '../utils/types.js'; +import { RemoveMethods } from '../common/types.js'; import { ConfigBlock } from './config.js'; /** Resource JSON supported format diff --git a/src/orchestrators/apply.ts b/src/orchestrators/apply.ts index 8ecfdfd6..23238572 100644 --- a/src/orchestrators/apply.ts +++ b/src/orchestrators/apply.ts @@ -5,12 +5,12 @@ import { PlanOrchestratorResponse } from './plan.js'; export const ApplyOrchestrator = { async run(planResult: PlanOrchestratorResponse): Promise { - const { plan, pluginCollection } = planResult; + const { plan, pluginManager, project } = planResult; const filteredPlan = plan .filter((p) => p.operation !== ResourceOperation.NOOP) ctx.processStarted(ProcessName.APPLY); - await pluginCollection.apply(filteredPlan); + await pluginManager.apply(project, filteredPlan); ctx.processFinished(ProcessName.APPLY); }, }; diff --git a/src/orchestrators/plan.ts b/src/orchestrators/plan.ts index 430062ac..f4efeadb 100644 --- a/src/orchestrators/plan.ts +++ b/src/orchestrators/plan.ts @@ -1,15 +1,15 @@ import { PlanResponseData } from 'codify-schemas'; +import { CommonOrchestrator } from '../common/orchestrator.js'; import { Project } from '../entities/project.js'; import { ctx, ProcessName, SubProcessName } from '../events/context.js'; import { Parser } from '../parser/index.js'; -import { PluginCollection } from '../plugins/plugin-collection.js'; +import { PluginManager } from '../plugins/plugin-manager.js'; import { createStartupShellScriptsIfNotExists } from '../utils/file.js'; -import { CommonOrchestrator } from '../common/orchestrator.js'; export interface PlanOrchestratorResponse { plan: PlanResponseData[], - pluginCollection: PluginCollection; + pluginManager: PluginManager; project: Project; } @@ -24,27 +24,27 @@ export const PlanOrchestrator = { project.addXCodeToolsConfig(); ctx.subprocessFinished(SubProcessName.PARSE); - const { dependencyMap, pluginCollection } = await CommonOrchestrator.initializePlugins(project, secureMode); + const { dependencyMap, pluginManager } = await CommonOrchestrator.initializePlugins(project, secureMode); await createStartupShellScriptsIfNotExists(); ctx.subprocessStarted(SubProcessName.VALIDATE) project.validateWithResourceMap(dependencyMap); project.resolveResourceDependencies(dependencyMap); - const validationResults = await pluginCollection.validate(project); + const validationResults = await pluginManager.validate(project); project.handlePluginResourceValidationResults(validationResults); project.calculateEvaluationOrder(); ctx.subprocessFinished(SubProcessName.VALIDATE) ctx.subprocessStarted(SubProcessName.GENERATE_PLAN) - const plan = await pluginCollection.getPlan(project); + const plan = await pluginManager.getPlan(project); ctx.subprocessFinished(SubProcessName.GENERATE_PLAN) ctx.processFinished(ProcessName.PLAN) return { plan, - pluginCollection, + pluginManager, project, }; }, diff --git a/src/orchestrators/uninstall.ts b/src/orchestrators/uninstall.ts index 912a9c99..941088c1 100644 --- a/src/orchestrators/uninstall.ts +++ b/src/orchestrators/uninstall.ts @@ -18,11 +18,11 @@ export const UninstallOrchestrator = { resourceType: type, } as PlanResponseData)) - const { pluginCollection } = await CommonOrchestrator.initializePlugins(undefined, secureMode); + const { pluginManager } = await CommonOrchestrator.initializePlugins(undefined, secureMode); await createStartupShellScriptsIfNotExists(); ctx.processStarted(ProcessName.UNINSTALL); - await pluginCollection.apply(plan); + // await pluginManager.apply(plan); ctx.processFinished(ProcessName.UNINSTALL); }, }; diff --git a/src/parser/index.ts b/src/parser/index.ts index c2e3c753..33a6be7c 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -2,7 +2,7 @@ import { ConfigBlock } from '../entities/config.js'; import { Project } from '../entities/project.js'; import { ProjectConfig } from '../entities/project-config.js'; import { ResourceConfig } from '../entities/resource-config.js'; -import { InternalError } from '../utils/errors.js'; +import { InternalError } from '../common/errors.js'; import { ConfigClass } from './language-definition.js'; import { FileParser } from './parser/index.js'; import { JsonFileParser } from './parser/json/file-parser.js'; diff --git a/src/parser/parser/json/config-block-factory.ts b/src/parser/parser/json/config-block-factory.ts index f91b2d54..bd94ce23 100644 --- a/src/parser/parser/json/config-block-factory.ts +++ b/src/parser/parser/json/config-block-factory.ts @@ -1,7 +1,7 @@ +import { SyntaxError } from '../../../common/errors.js'; import { ConfigBlock } from '../../../entities/config.js'; import { ProjectConfig } from '../../../entities/project-config.js'; import { ResourceConfig } from '../../../entities/resource-config.js'; -import { SyntaxError } from '../../../utils/errors.js'; import { ConfigClass } from '../../language-definition.js'; export const JsonConfigBlockFactory = { diff --git a/src/parser/parser/json/file-parser.ts b/src/parser/parser/json/file-parser.ts index 073441d0..ec07e0e8 100644 --- a/src/parser/parser/json/file-parser.ts +++ b/src/parser/parser/json/file-parser.ts @@ -1,7 +1,7 @@ import parseJson from 'parse-json'; import { ConfigBlock } from '../../../entities/config.js'; -import { InternalError, JsonFileParseError, SyntaxError } from '../../../utils/errors.js'; +import { InternalError, JsonFileParseError, SyntaxError } from '../../../common/errors.js'; import { File } from '../../reader/entities/file.js'; import { FileParser } from '../index.js'; import { JsonConfigBlockFactory } from './config-block-factory.js'; diff --git a/src/parser/reader/entities/file.ts b/src/parser/reader/entities/file.ts index 193570b5..130d0229 100644 --- a/src/parser/reader/entities/file.ts +++ b/src/parser/reader/entities/file.ts @@ -1,4 +1,4 @@ -import { RemoveMethods } from '../../../utils/types.js'; +import { RemoveMethods } from '../../../common/types.js'; export class File { contents!: string; diff --git a/src/plugins/plugin-collection.ts b/src/plugins/plugin-manager.ts similarity index 81% rename from src/plugins/plugin-collection.ts rename to src/plugins/plugin-manager.ts index 9ecd274b..998f097a 100644 --- a/src/plugins/plugin-collection.ts +++ b/src/plugins/plugin-manager.ts @@ -1,6 +1,7 @@ -import { PlanResponseData, ValidateResponseData } from 'codify-schemas'; +import { PlanResponseData, ResourceOperation, ValidateResponseData } from 'codify-schemas'; import { Project } from '../entities/project.js'; +import { ResourceConfig } from '../entities/resource-config.js'; import { ctx, SubProcessName } from '../events/context.js'; import { groupBy } from '../utils/index.js'; import { Plugin } from './plugin.js'; @@ -14,7 +15,7 @@ const DEFAULT_PLUGINS = { 'default': 'latest', } -export class PluginCollection { +export class PluginManager { private plugins = new Map() private resourceToPluginMapping = new Map() @@ -61,18 +62,24 @@ export class PluginCollection { return result; } - async apply(planResponseData: PlanResponseData[]): Promise { + async apply(project: Project, planResponseData: PlanResponseData[]): Promise { for (const plan of planResponseData) { const { resourceType } = plan; ctx.subprocessStarted(SubProcessName.APPLYING_RESOURCE, resourceType); + const config = project.evaluationOrder.find((r) => r.type === resourceType); + if (!config) { + throw new Error(`Could not find plan ${resourceType}`) + } + const pluginName = this.resourceToPluginMapping.get(resourceType); if (!pluginName) { throw new Error(`Internal error: unable to determine plugin for apply: ${resourceType}`); } await this.plugins.get(pluginName)!.apply(plan); + await this.validateApply(pluginName, config); ctx.subprocessFinished(SubProcessName.APPLYING_RESOURCE, resourceType); } @@ -131,4 +138,14 @@ export class PluginCollection { return resourceMap; } + private async validateApply(pluginName: string, desired: ResourceConfig): Promise { + const validationPlan = await this.plugins.get(pluginName)!.plan(desired); + if (validationPlan.operation !== ResourceOperation.NOOP) { + throw new Error(`Plugin: '${pluginName}'. Resource: '${desired.type}'. Apply validation was not successful (additional changes are needed to match the desired plan). + +Validation plan returned: ${validationPlan.operation}. + `) + } + } + }