Example
Node.js で SSL 期限を取得
Infra Ops Hub の /api/v1/ssl を Node.js fetch で呼び出して、 SSL 証明書の残日数を取得する最小サンプル。API キーをINFRA_OPS_HUB_API_KEYに設定して実行します。
ESM JavaScript
// package.json: {"type": "module"}
const host = "example.com";
const apiKey = process.env.INFRA_OPS_HUB_API_KEY;
if (!apiKey) throw new Error("INFRA_OPS_HUB_API_KEY is required");
const res = await fetch(
`https://infra.yuzlrin.jp/api/v1/ssl?host=${encodeURIComponent(host)}`,
{ headers: { authorization: `Bearer ${apiKey}` } },
);
const data = await res.json();
if (!data.ok) {
console.error("SSL check failed:", data.error);
process.exit(1);
}
console.log(`${host} は残 ${data.daysRemaining} 日(発行元: ${data.issuer})`);
if (data.daysRemaining < 14) {
console.error("[warn] 期限 14 日以内。更新とセーフティ監視の登録を推奨。");
process.exit(2);
}TypeScript + API Key
import assert from "node:assert/strict";
interface SslResponse {
ok: boolean;
host: string;
daysRemaining?: number;
validFrom?: string;
validTo?: string;
issuer?: string;
error?: string;
}
export async function checkSsl(host: string, apiKey: string): Promise<SslResponse> {
const res = await fetch(
`https://infra.yuzlrin.jp/api/v1/ssl?host=${encodeURIComponent(host)}`,
{ headers: { authorization: `Bearer ${apiKey}` } },
);
const data = (await res.json()) as SslResponse;
assert.equal(typeof data.ok, "boolean");
return data;
}Authorization: Bearer <key> ヘッダで認証します。API キーの発行 →