From 333d803f76a6a8b08d8dc4444d981e554da2b805 Mon Sep 17 00:00:00 2001 From: ingalls Date: Mon, 30 Sep 2024 09:32:43 -0600 Subject: [PATCH] Cleaner cert expiration addition --- api/routes/server.ts | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/api/routes/server.ts b/api/routes/server.ts index 39e7888b7..ede5e7af2 100644 --- a/api/routes/server.ts +++ b/api/routes/server.ts @@ -1,4 +1,4 @@ -import { Type } from '@sinclair/typebox' +import { Static, Type } from '@sinclair/typebox' import { X509Certificate } from 'crypto'; import Schema from '@openaddresses/batch-schema'; import Err from '@openaddresses/batch-error'; @@ -33,22 +33,18 @@ export default async function router(schema: Schema, config: Config) { if (config.server.auth.cert && config.server.auth.key) auth = true; if (user.access === AuthUserAccess.ADMIN) { - if (auth) { - const { validFrom, validTo, subject } = new X509Certificate(config.server.auth.cert); - - return res.json({ - status: 'configured', - ...config.server, - certificate: { validFrom, validTo, subject }, - auth - }); - } else { - return res.json({ + const response: Static = { status: 'configured', ...config.server, auth - }); + }; + + if (config.server.auth.cert && config.server.auth.key) { + const { validFrom, validTo, subject } = new X509Certificate(config.server.auth.cert); + response.certificate = { validFrom, validTo, subject }; } + + return res.json(response) } else { return res.json({ id: config.server.id, @@ -100,11 +96,18 @@ export default async function router(schema: Schema, config: Config) { let auth = false if (config.server.auth.cert && config.server.auth.key) auth = true; - return res.json({ - status: 'configured', - ...config.server, - auth - }); + const response: Static = { + status: 'configured', + ...config.server, + auth + }; + + if (config.server.auth.cert && config.server.auth.key) { + const { validFrom, validTo, subject } = new X509Certificate(config.server.auth.cert); + response.certificate = { validFrom, validTo, subject }; + } + + return res.json(response); } catch (err) { return Err.respond(err, res); }