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.
This commit is contained in:
Eric 2024-12-09 16:33:20 -06:00 committed by GitHub
parent cae70d2921
commit 00c35aed11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.