Skip to content

Commit

Permalink
chore: k1ch / ensure seedKeysIfDbIsEmpty does not cause Unhandled Pro…
Browse files Browse the repository at this point in the history
…mise Rejection
  • Loading branch information
k1ch committed Oct 8, 2024
1 parent ca9d6e7 commit fb04a39
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions database/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dmgt-tech/the-usher-server-database",
"version": "2.3.0-rc.2",
"version": "2.3.0-rc.3",
"description": "Database layer for TheUsher",
"scripts": {
"test": "mocha --exit",
Expand Down
6 changes: 3 additions & 3 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dmgt-tech/the-usher-server",
"version": "2.3.0-rc.2",
"version": "2.3.0-rc.3",
"description": "The Usher Authorization Server",
"engines": {
"node": ">=18"
Expand Down
14 changes: 10 additions & 4 deletions server/the-usher.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { verifyTokenForAdmin, verifyTokenForSelf, verifyTokenForClientAdmin } = r
const winstonLogger = require('./src/logging/winston-logger')

// Normalizes a port into a number, string, or false
function normalizePort (val) {
function normalizePort(val) {
var port = parseInt(val, 10)
if (isNaN(port)) {
return val // named pipe
Expand All @@ -27,7 +27,7 @@ function normalizePort (val) {
return false
}

async function seedKeysIfDbIsEmpty () {
async function seedKeysIfDbIsEmpty() {
if ((await keystore.selectAllKeys()).length === 0) {
console.log('Note: There were no keys in the database generating and inserting a new key.')
keygen.generateAndInsertNewKeys()
Expand All @@ -54,7 +54,7 @@ const optionsObject = {
customErrorHandling: true
}

function preInitCheck () {
function preInitCheck() {
let missingKeyEnvVars = false
if (!env.ISSUER_WHITELIST) {
missingKeyEnvVars = true
Expand Down Expand Up @@ -115,7 +115,13 @@ expressApp.use(function (req, res, next) {
res.status(405).send(notFoundResponse)
})

seedKeysIfDbIsEmpty()
try {
if (process.env.SKIP_KEYS_CHECK === 'true') {
seedKeysIfDbIsEmpty()
}
} catch (err) {
console.log(`Failed to seedKeysIfDbIsEmpty: ${JSON.stringify(err)}`)
}

module.exports = { 'the-usher': expressApp } // For deploying to GCP
// For deploying to AWS Lambda
Expand Down

0 comments on commit fb04a39

Please sign in to comment.