@fntio/infra-client
Version:
Self-hosted AWS access portal: credential vending, target-account trust, and grant-driven private networking as CDK stacks and constructs.
72 lines (70 loc) • 2.48 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// lambdacode/monitoring/issuer-canary.ts
var issuer_canary_exports = {};
__export(issuer_canary_exports, {
handler: () => handler
});
module.exports = __toCommonJS(issuer_canary_exports);
async function getJson(url) {
let res;
try {
res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
} catch (err) {
throw new Error(`Issuer unreachable: ${url} \u2014 ${String(err)}`);
}
if (!res.ok) {
throw new Error(`Issuer unhealthy: HTTP ${res.status} from ${url}`);
}
const body = await res.json().catch(() => null);
if (!body || typeof body !== "object") {
throw new Error(`Issuer unhealthy: ${url} did not return a JSON object`);
}
return body;
}
var handler = async () => {
const url = process.env.CHECK_URL;
if (!url) throw new Error("CHECK_URL is not set");
const doc = await getJson(url);
if (!doc.issuer) {
throw new Error(
`Issuer unhealthy: discovery document from ${url} has no "issuer" field`
);
}
if (typeof doc.jwks_uri !== "string") {
throw new Error(
`Issuer unhealthy: discovery document from ${url} has no "jwks_uri"`
);
}
const jwks = await getJson(doc.jwks_uri);
const keys = Array.isArray(jwks.keys) ? jwks.keys : [];
if (keys.length === 0) {
throw new Error(`Issuer unhealthy: JWKS at ${doc.jwks_uri} lists no keys`);
}
const expectKid = process.env.EXPECT_KID;
if (expectKid && !keys.some((k) => k.kid === expectKid)) {
throw new Error(
`Issuer unhealthy: JWKS at ${doc.jwks_uri} does not list the active signing key ${expectKid}`
);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
handler
});