diff --git a/provider/index.ts b/provider/index.ts index d9fc43f..3c67741 100644 --- a/provider/index.ts +++ b/provider/index.ts @@ -120,7 +120,7 @@ const bytesToString = (byteArray: Uint8Array): string => { }; const execPromise = async (args: Array, input: string): Promise => { - return new Promise((res: (result: string) => void, rej: (error: childProcess.ExecException) => void): void => { + return new Promise((res: (result: string) => void, rej: (error: Error) => void): void => { const proc = childProcess.spawn('sh', ['-c', 'cat', '-', '|', ...args], { stdio: 'pipe', shell: true }); (proc.stdin as Writable).end(input); @@ -137,11 +137,19 @@ const execPromise = async (args: Array, input: string): Promise proc.on('close', (code: number) => { if (code > 0) { - rej({ - name: `Exited with code ${code}`, - message: stderr, + log(`Exec exited with code ${code}`, { + stdout, + stderr, }); + rej(new Error(`Exec exited with code ${code}`)); } else { + if (stderr) { + log(`Exec exited cleanly, but stderr was not empty`, { + stderr, + }); + } else { + log('Exec exited cleanly'); + } res(stdout); } }); @@ -149,9 +157,13 @@ const execPromise = async (args: Array, input: string): Promise }; const sopsDecode = async (fileContent: string, dataType: string, kmsKeyArn: string | undefined): Promise => { + log('Running sops command'); const sopsArgs = ['-d', '--input-type', dataType, '--output-type', 'json', ...(kmsKeyArn ? ['--kms', kmsKeyArn] : []), '/dev/stdin']; + log('Sops command args', { sopsArgs }); const result = await execPromise([path.join(__dirname, 'sops'), ...sopsArgs], fileContent); + log('Sops command result', { result }); const parsed = JSON.parse(result); + log('Sops command result', { parsed }); return Promise.resolve(parsed); }; diff --git a/provider/jest.config.js b/provider/jest.config.js index 28cb3e4..2b0aac5 100644 --- a/provider/jest.config.js +++ b/provider/jest.config.js @@ -10,7 +10,7 @@ module.exports = { statements: 86, branches: 65, functions: 90, - lines: 86, + lines: 85, }, }, };