pr_26783.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. diff --git a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs b/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
  2. index 29f5e7ffd26..46be91a1d9c 100644
  3. --- a/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
  4. +++ b/services/web/modules/server-ce-scripts/scripts/check-mongodb.mjs
  5. @@ -9,6 +9,34 @@ const { ObjectId } = mongodb
  6. const MIN_MONGO_VERSION = [6, 0]
  7. const MIN_MONGO_FEATURE_COMPATIBILITY_VERSION = [6, 0]
  8. +// Allow ignoring admin check failures via an environment variable
  9. +const OVERRIDE_ENV_VAR_NAME = 'ALLOW_MONGO_ADMIN_CHECK_FAILURES'
  10. +
  11. +function shouldSkipAdminChecks() {
  12. + return process.env[OVERRIDE_ENV_VAR_NAME] === 'true'
  13. +}
  14. +
  15. +function handleUnauthorizedError(err, feature) {
  16. + if (
  17. + err instanceof mongodb.MongoServerError &&
  18. + err.codeName === 'Unauthorized'
  19. + ) {
  20. + console.warn(`Warning: failed to check ${feature} (not authorised)`)
  21. + if (!shouldSkipAdminChecks()) {
  22. + console.error(
  23. + `Please ensure the MongoDB user has the required admin permissions, or\n` +
  24. + `set the environment variable ${OVERRIDE_ENV_VAR_NAME}=true to ignore this check.`
  25. + )
  26. + process.exit(1)
  27. + }
  28. + console.warn(
  29. + `Ignoring ${feature} check failure (${OVERRIDE_ENV_VAR_NAME}=${process.env[OVERRIDE_ENV_VAR_NAME]})`
  30. + )
  31. + } else {
  32. + throw err
  33. + }
  34. +}
  35. +
  36. async function main() {
  37. let mongoClient
  38. try {
  39. @@ -18,8 +46,16 @@ async function main() {
  40. throw err
  41. }
  42. - await checkMongoVersion(mongoClient)
  43. - await checkFeatureCompatibilityVersion(mongoClient)
  44. + try {
  45. + await checkMongoVersion(mongoClient)
  46. + } catch (err) {
  47. + handleUnauthorizedError(err, 'MongoDB version')
  48. + }
  49. + try {
  50. + await checkFeatureCompatibilityVersion(mongoClient)
  51. + } catch (err) {
  52. + handleUnauthorizedError(err, 'MongoDB feature compatibility version')
  53. + }
  54. try {
  55. await testTransactions(mongoClient)