From 00c35aed11d46059c5729004ea2fbee70e4d9f4f Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 9 Dec 2024 16:33:20 -0600 Subject: [PATCH] Webiste: Update custom hook to validate githubRepoDRIByPath config variable (#24497) Closes: #24399 Changes: - Updated the website's custom hook to validate values in the sails.config.custom.githubRepoDRIByPath config variable when the website starts. --- website/api/hooks/custom/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/website/api/hooks/custom/index.js b/website/api/hooks/custom/index.js index 1e6d150087..5a46166252 100644 --- a/website/api/hooks/custom/index.js +++ b/website/api/hooks/custom/index.js @@ -88,6 +88,19 @@ will be disabled and/or hidden in the UI. from: sails.config.custom.fromEmailAddress, fromName: sails.config.custom.fromName, }); + + // Validate all values in the githubRepoDRIByPath config variable. + if(sails.config.custom.githubRepoDRIByPath) { + if(!_.isObject(sails.config.custom.githubRepoDRIByPath)) { + throw new Error(`Invalid configuration! An invalid "sails.config.custom.githubRepoDRIByPath" value was provided. If set, this value should be a dictionary, where each key is a path in the GitHub repo, and each value is a GitHub username. Please change this value to be a dictionary and try running this script again.`); + } + for(let path in sails.config.custom.githubRepoDRIByPath) { + if(typeof sails.config.custom.githubRepoDRIByPath[path] !== 'string') { + throw new Error(`Invalid configuration! A path (${path}) in the "sails.config.custom.githubRepoDRIByPath" config value contains a DRI value that is not a string (type: ${typeof sails.config.custom.githubRepoDRIByPath[path]}). Please change the DRI for this path to be a string containing a single GitHub username and try running this script again.`); + } + } + } + // Send a request to our Algolia crawler to reindex the website. // FUTURE: If this breaks again, use the Platform model to store when the website was last crawled // (platform.algoliaLastCrawledWebsiteAt), and then only send a request if it was <30m ago, then remove dyno check.