Skip to content

Commit

Permalink
refactor: rename validate module action to configure
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jan 25, 2019
1 parent 4363fc5 commit 7b02fdd
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export class ActionHelper implements TypeGuard {
return (<Function>handler)(handlerParams)
}

private async callModuleHandler<T extends keyof Omit<ModuleActions, "describeType" | "validate">>(
private async callModuleHandler<T extends keyof Omit<ModuleActions, "describeType" | "configure">>(
{ params, actionType, defaultHandler }:
{ params: ModuleActionHelperParams<ModuleActionParams[T]>, actionType: T, defaultHandler?: ModuleActions[T] },
): Promise<ModuleActionOutputs[T]> {
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ export class Garden {
@param force - add the module again, even if it's already registered
*/
async addModule(config: ModuleConfig, force = false) {
const validateHandler = await this.getModuleActionHandler({ actionType: "validate", moduleType: config.type })
const validateHandler = await this.getModuleActionHandler({ actionType: "configure", moduleType: config.type })
const ctx = this.getPluginContext(validateHandler["pluginName"])

config = await validateHandler({ ctx, moduleConfig: config })
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/plugins/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { GardenPlugin } from "../../types/plugin/plugin"
import {
BuildModuleParams,
GetBuildStatusParams,
ValidateModuleParams,
ConfigureModuleParams,
HotReloadServiceParams,
PublishModuleParams,
} from "../../types/plugin/params"
import { keyBy } from "lodash"
import { containerHelpers } from "./helpers"
import { ContainerModule, containerModuleSpecSchema } from "./config"

export async function validateContainerModule({ ctx, moduleConfig }: ValidateModuleParams<ContainerModule>) {
export async function configureContainerModule({ ctx, moduleConfig }: ConfigureModuleParams<ContainerModule>) {
moduleConfig.spec = validateWithPath({
config: moduleConfig.spec,
schema: containerModuleSpecSchema,
Expand Down Expand Up @@ -148,7 +148,7 @@ export async function validateContainerModule({ ctx, moduleConfig }: ValidateMod
export const gardenPlugin = (): GardenPlugin => ({
moduleActions: {
container: {
validate: validateContainerModule,
configure: configureContainerModule,

async getBuildStatus({ module, log }: GetBuildStatusParams<ContainerModule>) {
const identifier = await containerHelpers.imageExistsLocally(module)
Expand Down
15 changes: 8 additions & 7 deletions garden-service/src/plugins/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import { Module } from "../types/module"
import {
BuildResult,
BuildStatus,
ValidateModuleResult,
TestResult,
RunTaskResult,
ConfigureModuleResult,
} from "../types/plugin/outputs"
import {
BuildModuleParams,
GetBuildStatusParams,
ValidateModuleParams,
TestModuleParams, RunTaskParams,
TestModuleParams,
RunTaskParams,
ConfigureModuleParams,
} from "../types/plugin/params"
import { CommonServiceSpec } from "../config/service"
import { BaseTestSpec, baseTestSpecSchema } from "../config/test"
Expand Down Expand Up @@ -84,9 +85,9 @@ export const execModuleSpecSchema = Joi.object()

export interface ExecModule extends Module<ExecModuleSpec, CommonServiceSpec, ExecTestSpec> { }

export async function parseExecModule(
{ ctx, moduleConfig }: ValidateModuleParams<ExecModule>,
): Promise<ValidateModuleResult> {
export async function configureExecModule(
{ ctx, moduleConfig }: ConfigureModuleParams<ExecModule>,
): Promise<ConfigureModuleResult> {

moduleConfig.spec = validateWithPath({
config: moduleConfig.spec,
Expand Down Expand Up @@ -225,7 +226,7 @@ export async function runExecTask(params: RunTaskParams): Promise<RunTaskResult>
export const execPlugin: GardenPlugin = {
moduleActions: {
exec: {
validate: parseExecModule,
configure: configureExecModule,
getBuildStatus: getExecModuleBuildStatus,
build: buildExecModule,
runTask: runExecTask,
Expand Down
12 changes: 6 additions & 6 deletions garden-service/src/plugins/google/google-cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
validateWithPath,
} from "../../config/common"
import { Module } from "../../types/module"
import { ValidateModuleResult } from "../../types/plugin/outputs"
import { ConfigureModuleResult } from "../../types/plugin/outputs"
import {
DeployServiceParams,
GetServiceOutputsParams,
GetServiceStatusParams,
ValidateModuleParams,
ConfigureModuleParams,
} from "../../types/plugin/params"
import { ServiceState, ServiceStatus, ingressHostnameSchema, Service } from "../../types/service"
import {
Expand Down Expand Up @@ -79,9 +79,9 @@ function getGcfProject<T extends GcfModule>(service: Service<T>, provider: Provi
return service.spec.project || provider.config["default-project"] || null
}

export async function parseGcfModule(
{ ctx, moduleConfig }: ValidateModuleParams<GcfModule>,
): Promise<ValidateModuleResult<GcfModule>> {
export async function configureGcfModule(
{ ctx, moduleConfig }: ConfigureModuleParams<GcfModule>,
): Promise<ConfigureModuleResult<GcfModule>> {

// TODO: check that each function exists at the specified path
moduleConfig.spec = validateWithPath({
Expand Down Expand Up @@ -116,7 +116,7 @@ export const gardenPlugin = (): GardenPlugin => ({
},
moduleActions: {
"google-cloud-function": {
validate: parseGcfModule,
configure: configureGcfModule,

async deployService(params: DeployServiceParams<GcfModule>) {
const { ctx, service } = params
Expand Down
10 changes: 5 additions & 5 deletions garden-service/src/plugins/kubernetes/container/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import { getServiceLogs } from "./logs"
import { execInService, runContainerModule, runContainerService, runContainerTask } from "./run"
import { testContainerModule } from "./test"
import { ConfigurationError } from "../../../exceptions"
import { validateContainerModule } from "../../container/container"
import { configureContainerModule } from "../../container/container"
import { KubernetesProvider } from "../kubernetes"
import { ValidateModuleParams } from "../../../types/plugin/params"
import { ConfigureModuleParams } from "../../../types/plugin/params"
import { getContainerServiceStatus, getServiceOutputs } from "./status"
import { getTestResult } from "../test"
import { ContainerModule } from "../../container/config"

async function validate(params: ValidateModuleParams<ContainerModule>) {
const config = await validateContainerModule(params)
async function configure(params: ConfigureModuleParams<ContainerModule>) {
const config = await configureContainerModule(params)

// validate ingress specs
const provider: KubernetesProvider = params.ctx.provider
Expand Down Expand Up @@ -49,6 +49,7 @@ async function validate(params: ValidateModuleParams<ContainerModule>) {
}

export const containerHandlers = {
configure,
deployService: deployContainerService,
deleteService,
execInService,
Expand All @@ -62,5 +63,4 @@ export const containerHandlers = {
runService: runContainerService,
runTask: runContainerTask,
testModule: testContainerModule,
validate,
}
8 changes: 4 additions & 4 deletions garden-service/src/plugins/kubernetes/helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
joiUserIdentifier,
} from "../../../config/common"
import { Module, FileCopySpec } from "../../../types/module"
import { ValidateModuleParams } from "../../../types/plugin/params"
import { ValidateModuleResult } from "../../../types/plugin/outputs"
import { ConfigureModuleParams } from "../../../types/plugin/params"
import { ConfigureModuleResult } from "../../../types/plugin/outputs"
import { containsSource } from "./common"
import { ConfigurationError } from "../../../exceptions"
import { deline } from "../../../util/string"
Expand Down Expand Up @@ -205,8 +205,8 @@ export const helmModuleSpecSchema = Joi.object().keys({
),
})

export async function validateHelmModule({ ctx, moduleConfig }: ValidateModuleParams<HelmModule>)
: Promise<ValidateModuleResult<HelmModule>> {
export async function validateHelmModule({ ctx, moduleConfig }: ConfigureModuleParams<HelmModule>)
: Promise<ConfigureModuleResult<HelmModule>> {
moduleConfig.spec = validateWithPath({
config: moduleConfig.spec,
schema: helmModuleSpecSchema,
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/plugins/kubernetes/helm/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { ModuleAndRuntimeActions } from "../../../types/plugin/plugin"
import { getExecModuleBuildStatus } from "../../exec"
import { HelmModule, validateHelmModule } from "./config"
import { HelmModule, validateHelmModule as configureHelmModule } from "./config"
import { buildHelmModule } from "./build"
import { getServiceStatus, getServiceOutputs } from "./status"
import { deployService, deleteService } from "./deployment"
Expand All @@ -20,6 +20,7 @@ import { testHelmModule } from "./test"

export const helmHandlers: Partial<ModuleAndRuntimeActions<HelmModule>> = {
build: buildHelmModule,
configure: configureHelmModule,
// TODO: add execInService handler
deleteService,
deployService,
Expand All @@ -33,5 +34,4 @@ export const helmHandlers: Partial<ModuleAndRuntimeActions<HelmModule>> = {
runModule: runHelmModule,
runTask: runHelmTask,
testModule: testHelmModule,
validate: validateHelmModule,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { ValidateModuleParams } from "../../types/plugin/params"
import { ConfigureModuleParams } from "../../types/plugin/params"
import { join } from "path"
import {
GcfModule,
parseGcfModule,
configureGcfModule,
} from "../google/google-cloud-functions"
import {
GardenPlugin,
Expand All @@ -33,8 +33,8 @@ export const gardenPlugin = (): GardenPlugin => ({

moduleActions: {
"google-cloud-function": {
async validate(params: ValidateModuleParams<GcfModule>) {
const parsed = await parseGcfModule(params)
async configure(params: ConfigureModuleParams<GcfModule>) {
const parsed = await configureGcfModule(params)

// convert the module and services to containers to run locally
const serviceConfigs: ServiceConfig<ContainerServiceSpec>[] = parsed.serviceConfigs.map((s) => {
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/plugins/openfaas/openfaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { Garden } from "../../garden"
import { PluginContext } from "../../plugin-context"
import { joiArray, validate, PrimitiveMap } from "../../config/common"
import { Module } from "../../types/module"
import { ValidateModuleResult } from "../../types/plugin/outputs"
import { ConfigureModuleResult } from "../../types/plugin/outputs"
import {
PrepareEnvironmentParams,
GetEnvironmentStatusParams,
ValidateModuleParams,
ConfigureModuleParams,
DeleteServiceParams,
GetServiceLogsParams,
} from "../../types/plugin/params"
Expand Down Expand Up @@ -162,7 +162,7 @@ export function gardenPlugin({ config }: { config: OpenFaasConfig }): GardenPlug
},
moduleActions: {
openfaas: {
async validate({ moduleConfig }: ValidateModuleParams<OpenFaasModule>): Promise<ValidateModuleResult> {
async configure({ moduleConfig }: ConfigureModuleParams<OpenFaasModule>): Promise<ConfigureModuleResult> {
moduleConfig.spec = validate(
moduleConfig.spec,
openfaasModuleSpecSchame,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/types/plugin/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ export const moduleTypeDescriptionSchema = Joi.object()
),
})

export type ValidateModuleResult<T extends Module = Module> =
export type ConfigureModuleResult<T extends Module = Module> =
ModuleConfig<
T["spec"],
T["serviceConfigs"][0]["spec"],
T["testConfigs"][0]["spec"],
T["taskConfigs"][0]["spec"]
>

export const validateModuleResultSchema = moduleConfigSchema
export const configureModuleResultSchema = moduleConfigSchema

export interface BuildResult {
buildLog?: string
Expand Down Expand Up @@ -335,7 +335,7 @@ export interface TaskActionOutputs {

export interface ModuleActionOutputs extends ServiceActionOutputs {
describeType: Promise<ModuleTypeDescription>
validate: Promise<ValidateModuleResult>
configure: Promise<ConfigureModuleResult>
getBuildStatus: Promise<BuildStatus>
build: Promise<BuildResult>
pushModule: Promise<PushResult>
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/types/plugin/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export interface DescribeModuleTypeParams { }
export const describeModuleTypeParamsSchema = Joi.object()
.keys({})

export interface ValidateModuleParams<T extends Module = Module> {
export interface ConfigureModuleParams<T extends Module = Module> {
ctx: PluginContext
log?: LogEntry
moduleConfig: T["_ConfigType"]
}
export const validateModuleParamsSchema = Joi.object()
export const configureModuleParamsSchema = Joi.object()
.keys({
ctx: pluginContextSchema
.required(),
Expand Down Expand Up @@ -336,7 +336,7 @@ export interface TaskActionParams<T extends Module = Module> {

export interface ModuleActionParams<T extends Module = Module> {
describeType: DescribeModuleTypeParams,
validate: ValidateModuleParams<T>
configure: ConfigureModuleParams<T>
getBuildStatus: GetBuildStatusParams<T>
build: BuildModuleParams<T>
pushModule: PushModuleParams<T>
Expand Down
12 changes: 6 additions & 6 deletions garden-service/src/types/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
getServiceLogsParamsSchema,
runServiceParamsSchema,
describeModuleTypeParamsSchema,
validateModuleParamsSchema,
configureModuleParamsSchema,
getBuildStatusParamsSchema,
buildModuleParamsSchema,
pushModuleParamsSchema,
Expand Down Expand Up @@ -71,7 +71,7 @@ import {
TaskActionOutputs,
setSecretResultSchema,
testResultSchema,
validateModuleResultSchema,
configureModuleResultSchema,
publishModuleResultSchema,
taskStatusSchema,
runTaskResultSchema,
Expand Down Expand Up @@ -291,9 +291,9 @@ export const moduleActionDescriptions:
paramsSchema: describeModuleTypeParamsSchema,
resultSchema: moduleTypeDescriptionSchema,
},
validate: {
configure: {
description: dedent`
Validate and optionally transform the given module configuration.
Validate and transform the given module configuration.
Note that this does not need to perform structural schema validation (the framework does that
automatically), but should in turn perform semantic validation to make sure the configuration is sane.
Expand All @@ -303,8 +303,8 @@ export const moduleActionDescriptions:
framework configuration fields, this action needs to specify those via the \`serviceConfigs\` and
\`testConfigs\` output keys.
`,
paramsSchema: validateModuleParamsSchema,
resultSchema: validateModuleResultSchema,
paramsSchema: configureModuleParamsSchema,
resultSchema: configureModuleResultSchema,
},

getBuildStatus: {
Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { mapValues, fromPairs } from "lodash"
import {
DeleteSecretParams,
GetSecretParams,
ValidateModuleParams,
ConfigureModuleParams,
RunModuleParams,
RunServiceParams,
RunTaskParams,
Expand Down Expand Up @@ -92,7 +92,7 @@ export const testModuleSpecSchema = containerModuleSpecSchema
tasks: joiArray(testModuleTaskSchema),
})

export async function validateTestModule({ moduleConfig }: ValidateModuleParams) {
export async function configureTestModule({ moduleConfig }: ConfigureModuleParams) {
moduleConfig.spec = validate(
moduleConfig.spec,
testModuleSpecSchema,
Expand Down Expand Up @@ -155,7 +155,7 @@ export const testPlugin: PluginFactory = (): GardenPlugin => {
moduleActions: {
test: {
testModule: testExecModule,
validate: validateTestModule,
configure: configureTestModule,
build: buildExecModule,
runModule,

Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ServiceLogEntry } from "../../src/types/plugin/outputs"
import { LogEntry } from "../../src/logger/log-entry"
import {
describeModuleTypeParamsSchema,
validateModuleParamsSchema,
configureModuleParamsSchema,
getBuildStatusParamsSchema,
buildModuleParamsSchema,
pushModuleParamsSchema,
Expand Down Expand Up @@ -389,8 +389,8 @@ const testPlugin: PluginFactory = async () => ({
}
},

validate: async (params) => {
validate(params, validateModuleParamsSchema)
configure: async (params) => {
validate(params, configureModuleParamsSchema)

const serviceConfigs = params.moduleConfig.spec.services.map(spec => ({
name: spec.name,
Expand Down
Loading

0 comments on commit 7b02fdd

Please sign in to comment.