Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Dec 16, 2024
1 parent 2670111 commit cb39951
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
16 changes: 15 additions & 1 deletion cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"prettier": "^3.3.3",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"why-is-node-running": "^3.2.1"
},
"dependencies": {
"@opentdf/sdk": "file:../lib/opentdf-sdk-0.2.0.tgz",
Expand Down
14 changes: 12 additions & 2 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import whyIsNodeRunning from 'why-is-node-running' // should be your first import

import { createWriteStream, openAsBlob } from 'node:fs';
import { stat } from 'node:fs/promises';
import { Writable } from 'node:stream';
Expand Down Expand Up @@ -553,12 +555,19 @@ export const handleArgs = (args: string[]) => {
});
try {
log('SILLY', `Initialized client`);

log('DEBUG', `About to TDF3 decrypt [${argv.file}]`);
const ct = await client.read(await parseReadOptions(argv));
log('SILLY', `acquired read stream`);
const destination = argv.output ? createWriteStream(argv.output) : process.stdout;
await ct.pipeTo(Writable.toWeb(destination));
log('SILLY', `acquired destination stream`);
try {
await ct.pipeTo(Writable.toWeb(destination));
} catch (e) {
log('ERROR', `Failed to pipe to destination stream: ${e}`);
}
log('SILLY', `piped to destination stream`);
const lastRequest = authProvider.requestLog[authProvider.requestLog.length - 1];
log('SILLY', `last request is ${JSON.stringify(lastRequest)}`);
let accessToken = null;
let dpopToken = null;
for (const h of Object.keys(lastRequest.headers)) {
Expand All @@ -580,6 +589,7 @@ export const handleArgs = (args: string[]) => {
}
console.assert(accessToken, 'No access_token found');
console.assert(!argv.dpop || dpopToken, 'DPoP requested but absent');
setImmediate(() => whyIsNodeRunning())
} finally {
client.close();
}
Expand Down

0 comments on commit cb39951

Please sign in to comment.