(taskFamilyDirectory: string, buildStepsBeforeValidation: BuildStep[])
| 3 | import { BuildStep, FileBuildStep, ShellBuildStep } from '../Driver' |
| 4 | |
| 5 | export async function validateBuildSteps(taskFamilyDirectory: string, buildStepsBeforeValidation: BuildStep[]) { |
| 6 | return await Promise.all( |
| 7 | buildStepsBeforeValidation.map(async buildStep => { |
| 8 | switch (buildStep.type) { |
| 9 | case 'shell': |
| 10 | return ShellBuildStep.parse(buildStep) |
| 11 | case 'file': { |
| 12 | const { source, destination } = FileBuildStep.parse(buildStep) |
| 13 | |
| 14 | const taskFamilyDirectoryRealPath = await realpath(taskFamilyDirectory) |
| 15 | // realpath expands symlinks, so we don't have to worry about symlinks pointing to files outside the task family directory. |
| 16 | const sourceRealPath = await realpath(join(taskFamilyDirectory, source)) |
| 17 | if (!sourceRealPath.startsWith(taskFamilyDirectoryRealPath)) { |
| 18 | throw new Error( |
| 19 | `Path to copy ${source}'s realpath is ${sourceRealPath}, which is not within the task family directory ${taskFamilyDirectory}.`, |
| 20 | ) |
| 21 | } |
| 22 | |
| 23 | return { |
| 24 | type: 'file' as const, |
| 25 | sourceWithinTaskFamilyDirectory: source, |
| 26 | destination, |
| 27 | } |
| 28 | } |
| 29 | default: |
| 30 | // This function checks that buildStep is of type never, to ensure that getPackerTemplate explicitly validates all types |
| 31 | // of build steps. |
| 32 | ;((val: never) => { |
| 33 | throw new Error(`Unexpected value for buildStep.type. buildStep: ${JSON.stringify(val)}`) |
| 34 | })(buildStep) |
| 35 | } |
| 36 | }), |
| 37 | ) |
| 38 | } |
no test coverage detected