Skip to content

Commit

Permalink
fix(enterprise): include workflow run config
Browse files Browse the repository at this point in the history
We now include the workflow run config when registering a workflow run
with GE.
  • Loading branch information
thsig authored and eysi09 committed Aug 13, 2020
1 parent 5a9228b commit 8dd0874
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 14 additions & 1 deletion core/src/config/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { cloneDeep, isEqual, take } from "lodash"
import { cloneDeep, isEqual, omit, take } from "lodash"
import { joi, joiUserIdentifier, joiVariableName, joiIdentifier } from "./common"
import { DEFAULT_API_VERSION } from "../constants"
import { deline, dedent } from "../util/string"
Expand Down Expand Up @@ -34,6 +34,19 @@ export interface WorkflowConfig {
triggers?: TriggerSpec[]
}

export interface WorkflowRunConfig extends Omit<WorkflowConfig, "triggers"> {
environment: string // The environment the workflow run is executed in
namespace: string // The namespace the workflow run is executed in
}

export function makeRunConfig(
workflowConfig: WorkflowConfig,
environment: string,
namespace: string
): WorkflowRunConfig {
return { ...omit(workflowConfig, ["triggers"]), environment, namespace }
}

export interface WorkflowResource extends WorkflowConfig {}

export const workflowConfigSchema = () =>
Expand Down
12 changes: 4 additions & 8 deletions core/src/enterprise/workflow-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { got, GotResponse } from "../util/http"
import { makeAuthHeader } from "./auth"
import { WorkflowConfig } from "../config/workflow"
import { WorkflowConfig, makeRunConfig } from "../config/workflow"
import { LogEntry } from "../logger/log-entry"
import { PlatformError } from "../exceptions"
import { GardenEnterpriseContext } from "./init"
Expand All @@ -25,21 +25,17 @@ export interface RegisterWorkflowRunParams {
* Registers the workflow run with the platform, and returns the UID generated for the run.
*/
export async function registerWorkflowRun({
workflowConfig,
enterpriseContext,
workflowConfig,
environment,
namespace,
log,
}: RegisterWorkflowRunParams): Promise<string> {
const { clientAuthToken, projectId, enterpriseDomain } = enterpriseContext
log.debug(`Registering workflow run for ${workflowConfig.name}...`)
const headers = makeAuthHeader(clientAuthToken)
const requestData = {
projectUid: projectId,
environment,
namespace,
workflowName: workflowConfig.name,
}
const workflowRunConfig = makeRunConfig(workflowConfig, environment, namespace)
const requestData = { projectUid: projectId, workflowRunConfig }
let res
try {
res = await got.post(`${enterpriseDomain}/workflow-runs`, { json: requestData, headers }).json<GotResponse<any>>()
Expand Down

0 comments on commit 8dd0874

Please sign in to comment.