Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions codify.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@
},
{
"type": "vscode"
},
{
"type": "aws-configure",
"profile": "codify",
"csvCredentials": "../../../Downloads/rootkey.csv"
}
]
File renamed without changes.
10 changes: 5 additions & 5 deletions src/common/orchestrator.ts
Original file line number Diff line number Diff line change
@@ -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 };
},
};
File renamed without changes.
2 changes: 1 addition & 1 deletion src/entities/project-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/entities/project.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/entities/resource-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/orchestrators/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { PlanOrchestratorResponse } from './plan.js';

export const ApplyOrchestrator = {
async run(planResult: PlanOrchestratorResponse): Promise<void> {
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);
},
};
14 changes: 7 additions & 7 deletions src/orchestrators/plan.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -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,
};
},
Expand Down
4 changes: 2 additions & 2 deletions src/orchestrators/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
2 changes: 1 addition & 1 deletion src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser/json/config-block-factory.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/parser/json/file-parser.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/parser/reader/entities/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RemoveMethods } from '../../../utils/types.js';
import { RemoveMethods } from '../../../common/types.js';

export class File {
contents!: string;
Expand Down
23 changes: 20 additions & 3 deletions src/plugins/plugin-collection.ts → src/plugins/plugin-manager.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +15,7 @@ const DEFAULT_PLUGINS = {
'default': 'latest',
}

export class PluginCollection {
export class PluginManager {

private plugins = new Map<PluginName, Plugin>()
private resourceToPluginMapping = new Map<string, string>()
Expand Down Expand Up @@ -61,18 +62,24 @@ export class PluginCollection {
return result;
}

async apply(planResponseData: PlanResponseData[]): Promise<void> {
async apply(project: Project, planResponseData: PlanResponseData[]): Promise<void> {
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);
}
Expand Down Expand Up @@ -131,4 +138,14 @@ export class PluginCollection {
return resourceMap;
}

private async validateApply(pluginName: string, desired: ResourceConfig): Promise<void> {
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}.
`)
}
}

}