#!/usr/bin/env node import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { parseArgs } from "node:util"; import YAML from "yaml"; const { values } = parseArgs({ options: { "ca-cert": { type: "string", default: "ca_cert.pem" }, "issuing-ca-cert": { type: "string", default: "issuing_ca_cert.pem" }, output: { type: "string", default: "trust_store.yaml" }, }, }); // IMPORTANT: Strip the trailing newline from the PEM files, // otherwise gcloud will reject the trust store with a cryptic error message. const trustStore = { trustAnchors: [{ pemCertificate: readFileSync(values["ca-cert"], "utf8").trimEnd() }], }; // The issuing CA is optional; it is included only when its file exists. if (existsSync(values["issuing-ca-cert"])) { trustStore.intermediateCas = [ { pemCertificate: readFileSync(values["issuing-ca-cert"], "utf8").trimEnd() }, ]; } writeFileSync(values.output, YAML.stringify({ trustStore }, { indentSeq: false }));