-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.ts
74 lines (65 loc) · 2.3 KB
/
verify.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { executeShellCommand } from '@backstage/plugin-scaffolder-node';
import { createTemplateAction }from '@backstage/plugin-scaffolder-node';
import commandExists from 'command-exists';
import {Writable} from 'stream';
class ConsoleLogStream extends Writable {
data: string;
constructor(options: any) {
super(options);
this.data = '';
}
_write(chunk: any, _: any, callback: any) {
this.data += chunk.toString(); // Convert the chunk to a string and append it to this.data
console.log(this.data)
callback();
}
}
export const createVerifyDependency = () => {
return createTemplateAction<{
verifiers: string[];
}>({
id: 'cnoe:verify:dependency',
schema: {
input: {
type: 'object',
required: ['verifiers'],
properties: {
verifiers: {
type: 'array',
items: {
type: 'string',
},
title: 'verifiers',
description: 'The list of verifiers',
},
},
},
},
async handler(ctx) {
const verifiers = ctx.input.verifiers
if (verifiers == null || verifiers.length == 0) {
ctx.logger.error('no verifier was supplied for the object')
return
}
const baseCommand = 'cnoe-embed'
const baseArguments = ['k8s', 'verify']
const commandExistsToRun = await commandExists(baseCommand)
verifiers.forEach((verifier: string) => baseArguments.push("--config", verifier))
console.log(baseArguments)
if (!commandExistsToRun) {
throw new Error("cnoe command is missing")
}
var logStream = new ConsoleLogStream({});
await executeShellCommand({
command: baseCommand,
args: baseArguments,
logStream: logStream,
}).then(() =>
ctx.logger.info("verification succeeded")
).catch((error) => {
ctx.logger.error(error)
throw new Error(logStream.data)
});
},
});
};