simple-fs-server/keyout.ts

27 lines
852 B
TypeScript
Raw Normal View History

2023-01-05 18:18:07 +09:00
import { Command } from "https://deno.land/x/cliffy@v0.25.6/mod.ts";
import { fromFileUrl, join } from "path/mod.ts";
import { prepareSecretKey } from "./util/secret.ts";
export const key_out_cmd = new Command();
key_out_cmd.name("keyout")
.description("Output the secret key.")
2023-01-06 17:48:51 +09:00
.option("-f, --file <file:string>", "The file to output the key to. (default: stdout)")
.option("--dotenv", "Output the key in dotenv format.")
.action(async ({file, dotenv}) => {
2023-01-05 18:18:07 +09:00
const key = await prepareSecretKey();
2023-01-06 17:48:51 +09:00
const keyout = await crypto.subtle.exportKey("jwk", key);
let out = JSON.stringify(keyout);
if (dotenv){
out = [`SECRET_KEY='${out}'`].join("\n");
}
if (file){
await Deno.writeTextFile(file, out);
} else {
console.log(out);
}
2023-01-05 18:18:07 +09:00
});
if ( import.meta.main ){
await key_out_cmd.parse(Deno.args);
}