advent-of-code-2024/cli/secrets.ts
2024-12-08 01:12:44 -07:00

31 lines
No EOL
862 B
TypeScript

export async function saveToken(token: string) {
const process = new Deno.Command("secret-tool", {
args: [
"store",
"--label",
"Advent Of Code Session Token",
"aoc-deno",
"token"
],
stdin: "piped"
}).spawn();
const stdin = process.stdin.getWriter();
await stdin.write(new TextEncoder().encode(token));
await stdin.close();
}
export async function readToken() {
const process = new Deno.Command("secret-tool", {
args: [
"lookup",
"aoc-deno",
"token"
],
stdout: "piped"
}).spawn();
const decoderStream = new TextDecoderStream();
const stdout = process.stdout.pipeTo(decoderStream.writable);
for await (const v of decoderStream.readable.values()) {
console.log(v);
}
}