From b32b2de001bb4a77c20632bec67aaf34562c5264 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Wed, 7 Feb 2024 00:07:51 -0500 Subject: [PATCH] pull SSL certs via API --- nodejs/app.js | 3 +++ nodejs/models/cert.js | 17 +++++++++++++++++ nodejs/routes/cert.js | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 nodejs/models/cert.js create mode 100644 nodejs/routes/cert.js diff --git a/nodejs/app.js b/nodejs/app.js index c27e5e8..a34480a 100755 --- a/nodejs/app.js +++ b/nodejs/app.js @@ -40,6 +40,9 @@ app.use('/api/user', middleware.auth, require('./routes/user')); // API routes for working with hosts. All endpoints need to be have valid user. app.use('/api/host', middleware.auth, require('./routes/host')); +// API routes for working with hosts. All endpoints need to be have valid user. +app.use('/api/cert', middleware.auth, require('./routes/cert')); + app.controler = { host: require('./controler/host') } diff --git a/nodejs/models/cert.js b/nodejs/models/cert.js new file mode 100644 index 0000000..1392977 --- /dev/null +++ b/nodejs/models/cert.js @@ -0,0 +1,17 @@ +'use strict'; + +const {createClient} = require('redis'); +const client = createClient({}); + +client.connect(); + +async function getCert(host){ + try{ + console.log('looking for', host); + return JSON.parse(await client.GET(`${host}:latest`)); + }catch(error){ + return {} + } +} + +module.exports = {getCert}; diff --git a/nodejs/routes/cert.js b/nodejs/routes/cert.js new file mode 100644 index 0000000..40db330 --- /dev/null +++ b/nodejs/routes/cert.js @@ -0,0 +1,15 @@ +'use strict'; + +const router = require('express').Router(); +const {getCert} = require('../models/cert'); + + +router.get('/:host', async function(req, res, next){ + try{ + return res.json(await getCert(req.params.host)); + }catch(error){ + return next(error); + } +}); + +module.exports = router;