diff --git a/packages/api/src/config.js b/packages/api/src/config.js index 50603f5259..e16b62278d 100644 --- a/packages/api/src/config.js +++ b/packages/api/src/config.js @@ -1,6 +1,9 @@ import { modes as MaintenanceModes, DEFAULT_MODE, + NO_READ_OR_WRITE, + READ_ONLY, + READ_WRITE_ONLY, } from './middleware/maintenance.js' /** @@ -178,6 +181,13 @@ function parseRuntimeEnv(s) { } } +/** @type {Record} */ +const legacyModeMappings = { + '--': NO_READ_OR_WRITE, + 'r-': READ_ONLY, + rw: READ_WRITE_ONLY, +} + /** * If `s` is undefined, return the default maintenance mode. Otherwise, make sure it's a valid mode and return. * @@ -193,6 +203,11 @@ function maintenanceModeFromString(s) { return m } } + for (const [key, value] of Object.entries(legacyModeMappings)) { + if (s === key) { + return value + } + } throw new Error( `invalid maintenance mode value "${s}". valid choices: ${MaintenanceModes}` ) diff --git a/packages/api/test/config.spec.js b/packages/api/test/config.spec.js index 7bd7919eca..034990534f 100644 --- a/packages/api/test/config.spec.js +++ b/packages/api/test/config.spec.js @@ -26,7 +26,7 @@ const BASE_CONFIG = { DATABASE_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoyNTUwNjUzNjM0LCJyb2xlIjoic2VydmljZV9yb2xlIn0.necIJaiP7X2T2QjGeV-FhpkizcNTX8HjDDBAxpgQTEI', DATABASE_CONNECTION: 'postgresql://postgres:postgres@localhost:5432/postgres', - MAINTENANCE_MODE: 'rw', + MAINTENANCE_MODE: 'rwc', S3_REGION: 'us-east-1', S3_ACCESS_KEY_ID: 'minioadmin', S3_SECRET_ACCESS_KEY: 'minioadmin', @@ -144,6 +144,23 @@ test.serial( test.serial( 'serviceConfigFromVariables sets MAINTENANCE_MODE if it contains a valid mode string', + (t) => { + const modes = ['---', 'r--', 'rw-', 'rwc'] + for (const m of modes) { + t.is( + serviceConfigFromVariables( + override({ + MAINTENANCE_MODE: m, + }) + ).MAINTENANCE_MODE.toString(), + m + ) + } + } +) + +test.serial( + 'serviceConfigFromVariables sets MAINTENANCE_MODE if it contains a valid legacy mode string', (t) => { const modes = ['--', 'r-', 'rw'] for (const m of modes) { diff --git a/packages/api/test/scripts/globals.js b/packages/api/test/scripts/globals.js index e670fe1099..d2ca6eed6e 100644 --- a/packages/api/test/scripts/globals.js +++ b/packages/api/test/scripts/globals.js @@ -17,7 +17,7 @@ globalThis.PICKUP_API_URL = 'http://127.0.0.1:9094' // will be used with we can active auth in cluster base64 of test:test globalThis.PICKUP_BASIC_AUTH_TOKEN = 'dGVzdDp0ZXN0' -globalThis.MAINTENANCE_MODE = 'rw' +globalThis.MAINTENANCE_MODE = 'rwc' globalThis.S3_ENDPOINT = 'http://127.0.0.1:9000' globalThis.S3_REGION = 'us-east-1'