Skip to content

Commit

Permalink
fix(manifest sign): --private-key option is required and validated
Browse files Browse the repository at this point in the history
JST-386
  • Loading branch information
pgrzy-golem committed Sep 8, 2023
1 parent 9c990f1 commit 05c17e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ export async function checkFileOverwrite(
// File does not exist, that's fine.
}
}

export async function assertFileExists(name: string, path: string): Promise<void> {
try {
await stat(path);
} catch (e) {
// File does not exist, that's fine.
console.error(`Error: ${name} "${path}" not found.`);
process.exit(1);
}
}
2 changes: 2 additions & 0 deletions src/manifest/manifest-sign.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ManifestSignOptions } from "./manifest-sign.options";
import { readManifest } from "./manifest-utils";
import { readFile, writeFile } from "fs/promises";
import { createSign } from "crypto";
import { assertFileExists } from "../lib/file";

export async function manifestSignAction(options: ManifestSignOptions): Promise<void> {
// Read and validate the manifest.
await readManifest(options.manifest);
await assertFileExists("Private key file", options.keyFile);

// Read manifest buffer.
const manifestBuffer = await readFile(options.manifest);
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/manifest-sign.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const manifestSignCommand = new Command("sign");
manifestSignCommand
.description("Sign Golem manifest file.")
.addOption(createManifestOption())
.option("-k, --key-file <file>", "Private key file.")
.requiredOption("-k, --key-file <file>", "Private key file.")
.option("-p, --passphrase <passphrase>", "Passphrase for the private key.")
.option("-s, --signature-file <file>", "Signature file.", "manifest.sig")
.action(async (options: ManifestSignOptions) => {
Expand Down

0 comments on commit 05c17e4

Please sign in to comment.