30 lines
884 B
JavaScript
Executable File
30 lines
884 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { parseArgs } from "node:util";
|
|
|
|
const { values } = parseArgs({
|
|
options: {
|
|
"private-key-file": { type: "string" },
|
|
"client-email": { type: "string" },
|
|
output: { type: "string", default: "cred.json" },
|
|
},
|
|
});
|
|
|
|
if (!values["private-key-file"] || !values["client-email"]) {
|
|
console.error("Usage: make_cred.mjs --private-key-file FILE --client-email EMAIL [--output FILE]");
|
|
process.exit(1);
|
|
}
|
|
|
|
const privateKey = readFileSync(values["private-key-file"], "utf8");
|
|
const clientEmail = values["client-email"];
|
|
|
|
const cred = {
|
|
type: "service_account",
|
|
project_id: clientEmail.split("@")[1].split(".")[0],
|
|
private_key: privateKey,
|
|
client_email: clientEmail,
|
|
token_uri: "https://oauth2.googleapis.com/token",
|
|
};
|
|
|
|
writeFileSync(values.output, JSON.stringify(cred, null, 2) + "\n");
|