Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(infra): keep a stored built-in Redis or MinIO without a sent flag

Yudhi Armyndharis15b46bc524bf
diff --git a/src/modules/infra/config-sections.ts b/src/modules/infra/config-sections.ts
index 51a6984c6..4c05af6fe 100644
--- a/src/modules/infra/config-sections.ts
+++ b/src/modules/infra/config-sections.ts
@@ -173,7 +173,10 @@ export function applyRedisSection(
const { updates, staleKeys, profiles } = ctx;
if (redis.enabled !== undefined) updates.REDIS_ENABLED = redis.enabled ? 'true' : 'false';
if (redis.builtIn !== undefined) updates.REDIS_BUILTIN = redis.builtIn ? 'true' : 'false';
- if (redis.builtIn === true) {
+ // An absent builtIn keeps the stored mode, as for the database: a stored built-in Redis keeps its bundled host
+ // rather than taking the fields sent (the page leaves the flag out beside a pinned host, and sends that host).
+ const redisBuiltIn = redis.builtIn ?? existing.REDIS_BUILTIN === 'true';
+ if (redisBuiltIn) {
// Built-in Redis - use container name as host. The bundled container runs without
// auth, so a password saved by an earlier external setup is stale: leaving it
// would make the client AUTH against a passwordless server on the next boot.
@@ -188,7 +191,6 @@ export function applyRedisSection(
}
}
setSecret(updates, 'REDIS_PASSWORD', redis.password);
- const redisBuiltIn = redis.builtIn ?? existing.REDIS_BUILTIN === 'true';
// What the next boot reads: a value the environment pins, else this save's, else the stored one. The queue
// section is applied first, so its switch is in `updates` already.
const saved = (key: string): string | undefined => updates[key] ?? existing[key];
@@ -231,7 +233,8 @@ export function applyStorageSection(
}
} else {
staleKeys.add('STORAGE_LOCAL_PATH');
- if (storage.builtIn === true) {
+ // An absent builtIn keeps the stored mode, as for the database and Redis.
+ if (storage.builtIn ?? existing.MINIO_BUILTIN === 'true') {
// Built-in MinIO - use container name as endpoint. The bundled keys are only the DEFAULT, as for the database
// password: keys the next boot already dials the bundled endpoint with (the flag already set, or the bundled
// endpoint pinned or stored, in any spelling) are the ones that container was created with, and are kept.
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 160290a70..4e64e3790 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -967,6 +967,37 @@ describe('InfraConfigController.saveConfig per-key merge (partial payloads)', ()
expect(env).not.toMatch(/^DATABASE_HOST=/m);
});
+ // The page also leaves the flag out of an untouched Redis or storage card beside a host pinned elsewhere, and sends
+ // the host fields seeded with the pinned value. A stored built-in mode keeps its bundled host then, as the database
+ // does: the pinned host beside a stored flag of true would start the container and switch back once it is lifted.
+ it('keeps a stored built-in Redis and MinIO when the flag is left out beside hosts pinned elsewhere', () => {
+ pin({
+ REDIS_HOST: 'cache.ext.example',
+ S3_ENDPOINT: 'https://s3.ext.example',
+ S3_ACCESS_KEY_ID: 'ak-strong',
+ S3_SECRET_ACCESS_KEY: 'sk-strong',
+ });
+
+ const env = written(
+ {
+ redis: { enabled: true, host: 'cache.ext.example', port: '6379' },
+ queue: { enabled: false },
+ storage: { type: 's3', s3Bucket: 'openwa', s3Endpoint: 'https://s3.ext.example' },
+ },
+ 'REDIS_ENABLED=true\nREDIS_BUILTIN=true\nREDIS_HOST=redis\nREDIS_PORT=6379\nSTORAGE_TYPE=s3\nMINIO_BUILTIN=true\n' +
+ 'S3_ENDPOINT=http://minio:9000\nS3_BUCKET=openwa\nS3_ACCESS_KEY_ID=minioadmin\nS3_SECRET_ACCESS_KEY=minioadmin\n',
+ );
+
+ for (const line of [
+ 'REDIS_BUILTIN=true',
+ 'REDIS_HOST=redis',
+ 'MINIO_BUILTIN=true',
+ 'S3_ENDPOINT=http://minio:9000',
+ ]) {
+ expect(env).toContain(line);
+ }
+ });
+
// The page leaves out an untouched flag beside a pinned host. The stored external flag is inherited then, so the
// credentials the pinned host may need stay as stored, where a flag of true would write the bundled ones.
it('keeps stored external credentials when the flag is left out beside a pinned bundled host', () => {