15814: Catch error that otherwise goes unhandled
[arvados.git] / services / workbench2 / src / models / process.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ContainerRequestResource } from "./container-request";
6 import { MountType, MountKind } from 'models/mount-types';
7 import { WorkflowResource, parseWorkflowDefinition, getWorkflow, CwlSecrets } from 'models/workflow';
8 import { WorkflowInputsData } from './workflow';
9
10 export type ProcessResource = ContainerRequestResource;
11
12 export const MOUNT_PATH_CWL_WORKFLOW = '/var/lib/cwl/workflow.json';
13 export const MOUNT_PATH_CWL_INPUT = '/var/lib/cwl/cwl.input.json';
14
15
16 export const createWorkflowMounts = (workflow: WorkflowResource, inputs: WorkflowInputsData): { [path: string]: MountType } => {
17
18     const wfdef = parseWorkflowDefinition(workflow);
19     const mounts: {[path: string]: MountType} = {
20         '/var/spool/cwl': {
21             kind: MountKind.COLLECTION,
22             writable: true,
23         },
24         'stdout': {
25             kind: MountKind.MOUNTED_FILE,
26             path: '/var/spool/cwl/cwl.output.json',
27         },
28         '/var/lib/cwl/workflow.json': {
29             kind: MountKind.JSON,
30             content: wfdef,
31         },
32         '/var/lib/cwl/cwl.input.json': {
33             kind: MountKind.JSON,
34             content: inputs,
35         }
36     };
37
38     return mounts;
39 };
40
41 export const createWorkflowSecretMounts = (workflow: WorkflowResource, inputs: WorkflowInputsData): { [path: string]: MountType } => {
42
43     const wfdef = parseWorkflowDefinition(workflow);
44     const secret_mounts: {[path: string]: MountType} = {};
45
46     const wf = getWorkflow(wfdef);
47     if (wf && wf.hints) {
48         const secrets = wf.hints.find(item => item.class === 'http://commonwl.org/cwltool#Secrets') as CwlSecrets | undefined;
49         if (secrets && secrets.secrets) {
50             let secretCount = 0;
51             secrets.secrets.forEach((paramId) => {
52                 const param = paramId.split("/").pop();
53                 if (!param || !inputs[param]) {
54                     return;
55                 }
56                 const value: string = inputs[param] as string;
57                 const mnt = "/secrets/s"+secretCount;
58                 secret_mounts[mnt] = {
59                     "kind": MountKind.TEXT,
60                     "content": value
61                 }
62                 inputs[param] = {"$include": mnt}
63                 secretCount++;
64             });
65         }
66     }
67     return secret_mounts;
68 };