Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(infra): report whether each built-in flag is stored

Yudhi Armyndharised3313164cdc
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.ts
index 85a05ca35..62fc90c12 100644
--- a/dashboard/src/hooks/useInfraConfigForm.test.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts
@@ -46,6 +46,7 @@ const SAVED: SavedConfig = {
database: {
type: 'postgres',
builtIn: false,
+ builtInSet: true,
host: 'pg.internal',
port: '5433',
username: 'openwa',
@@ -56,11 +57,12 @@ const SAVED: SavedConfig = {
sslRejectUnauthorized: false,
passwordSet: true,
},
- redis: { enabled: true, builtIn: false, host: 'redis.internal', port: '6380', passwordSet: true },
+ redis: { enabled: true, builtIn: false, builtInSet: true, host: 'redis.internal', port: '6380', passwordSet: true },
queue: { enabled: true },
storage: {
type: 's3',
builtIn: false,
+ builtInSet: true,
localPath: '',
s3Bucket: 'media',
s3Region: 'eu-west-1',
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 3f1661ace..fb4728932 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -34,6 +34,7 @@ const SAVED_CONFIG: SavedConfig = {
database: {
type: 'postgres',
builtIn: false,
+ builtInSet: true,
host: 'shared-db-host',
port: '6543',
username: 'openwa_admin',
@@ -44,11 +45,12 @@ const SAVED_CONFIG: SavedConfig = {
sslRejectUnauthorized: true,
passwordSet: true,
},
- redis: { enabled: false, builtIn: false, host: 'localhost', port: '6379', passwordSet: false },
+ redis: { enabled: false, builtIn: false, builtInSet: true, host: 'localhost', port: '6379', passwordSet: false },
queue: { enabled: false },
storage: {
type: 'local',
builtIn: false,
+ builtInSet: true,
localPath: './data/media',
s3Bucket: '',
s3Region: 'ap-southeast-1',
@@ -620,7 +622,7 @@ const RUNNING_SQLITE: InfraStatus = {
};
const SAVED_SWITCH: SavedConfig = {
...SAVED_CONFIG,
- redis: { enabled: true, builtIn: false, host: 'redis.internal', port: '6380', passwordSet: true },
+ redis: { enabled: true, builtIn: false, builtInSet: true, host: 'redis.internal', port: '6380', passwordSet: true },
queue: { enabled: true },
storage: { ...SAVED_CONFIG.storage, type: 's3', s3Bucket: 'media', s3CredentialsSet: true },
};
@@ -734,7 +736,7 @@ const RUNNING_BUNDLED: InfraStatus = {
};
const SAVED_EXTERNAL: SavedConfig = {
...SAVED_CONFIG,
- redis: { enabled: true, builtIn: false, host: 'redis.internal', port: '6379', passwordSet: false },
+ redis: { enabled: true, builtIn: false, builtInSet: true, host: 'redis.internal', port: '6379', passwordSet: false },
storage: { ...SAVED_CONFIG.storage, type: 's3', builtIn: false },
};
@@ -815,7 +817,7 @@ test('a switch to a bundled container waiting for a restart says what runs now,
},
saved: {
...SAVED_BUNDLED,
- redis: { enabled: true, builtIn: true, host: 'redis', port: '6379', passwordSet: false },
+ redis: { enabled: true, builtIn: true, builtInSet: true, host: 'redis', port: '6379', passwordSet: false },
},
};
const { container } = renderInfrastructure();
@@ -1065,7 +1067,14 @@ test('the database, Redis and S3 secret fields are not offered saved passwords',
},
saved: {
...SAVED_CONFIG,
- redis: { enabled: true, builtIn: false, host: 'redis.example', port: '6379', passwordSet: true },
+ redis: {
+ enabled: true,
+ builtIn: false,
+ builtInSet: true,
+ host: 'redis.example',
+ port: '6379',
+ passwordSet: true,
+ },
storage: { ...SAVED_CONFIG.storage, type: 's3' },
},
};
@@ -1089,7 +1098,7 @@ test('turning a running built-in Redis off asks the restart to stop its containe
status: { ...INFRA_STATUS, redis: { enabled: true, connected: true, host: 'redis', port: 6379, builtIn: true } },
saved: {
...SAVED_CONFIG,
- redis: { enabled: true, builtIn: true, host: 'redis', port: '6379', passwordSet: false },
+ redis: { enabled: true, builtIn: true, builtInSet: true, host: 'redis', port: '6379', passwordSet: false },
},
};
const { container } = renderInfrastructure();
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 50583e826..057dc747c 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -655,6 +655,9 @@ export interface SavedConfig {
database: {
type: 'sqlite' | 'postgres';
builtIn: boolean;
+ // Whether the flag is stored (saved file or environment). A deployment that pins the bundled host never
+ // writes it, and `builtIn` is then false only because nothing says otherwise: /infra/status has what runs.
+ builtInSet: boolean;
host: string;
port: string;
username: string;
@@ -665,11 +668,12 @@ export interface SavedConfig {
sslRejectUnauthorized: boolean;
passwordSet: boolean;
};
- redis: { enabled: boolean; builtIn: boolean; host: string; port: string; passwordSet: boolean };
+ redis: { enabled: boolean; builtIn: boolean; builtInSet: boolean; host: string; port: string; passwordSet: boolean };
queue: { enabled: boolean };
storage: {
type: 'local' | 's3';
builtIn: boolean;
+ builtInSet: boolean;
localPath: string;
s3Bucket: string;
s3Region: string;
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index deb148ae5..21c661564 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -5619,6 +5619,7 @@ Read the effective infrastructure config used to hydrate the dashboard form. Eac
"database": {
"type": "sqlite",
"builtIn": false,
+ "builtInSet": false,
"host": "",
"port": "",
"username": "",
@@ -5629,11 +5630,12 @@ Read the effective infrastructure config used to hydrate the dashboard form. Eac
"sslRejectUnauthorized": true,
"passwordSet": false
},
- "redis": { "enabled": false, "builtIn": false, "host": "", "port": "", "passwordSet": false },
+ "redis": { "enabled": false, "builtIn": false, "builtInSet": false, "host": "", "port": "", "passwordSet": false },
"queue": { "enabled": false },
"storage": {
"type": "local",
"builtIn": false,
+ "builtInSet": false,
"localPath": "./data/media",
"s3Bucket": "",
"s3Region": "",
@@ -5649,6 +5651,8 @@ Read the effective infrastructure config used to hydrate the dashboard form. Eac
}
```
+`builtInSet` says whether each `builtIn` flag is stored (in the saved file or pinned by the environment). A Compose deployment that pins `DATABASE_HOST=postgres`, `REDIS_HOST=redis` or `S3_ENDPOINT` in `.env` never writes the flag, so there `builtIn` is `false` only because nothing says otherwise: read what runs from `GET /api/infra/status`.
+
When nothing supplies a key — no pinned environment value and the file absent or silent about it — empty-string/default values are returned (`schema='public'`, `poolSize=10`, `sslRejectUnauthorized=true`, `engine.type='whatsapp-web.js'`, `headless=true`).
**Errors:** `401` · `403`
diff --git a/openapi.json b/openapi.json
index 16a739009..7500e60a5 100644
--- a/openapi.json
+++ b/openapi.json
@@ -22233,6 +22233,11 @@
"type": "boolean",
"example": true
},
+ "builtInSet": {
+ "type": "boolean",
+ "description": "Whether the built-in flag is stored, in the saved file or pinned by the environment. When false, builtIn is false only because nothing says otherwise (a Compose deployment that pins the bundled host never writes it): read what runs from /infra/status.",
+ "example": true
+ },
"host": {
"type": "string",
"example": "openwa-postgres"
@@ -22276,6 +22281,7 @@
"required": [
"type",
"builtIn",
+ "builtInSet",
"host",
"port",
"username",
@@ -22298,6 +22304,11 @@
"type": "boolean",
"example": true
},
+ "builtInSet": {
+ "type": "boolean",
+ "description": "Whether the built-in flag is stored, in the saved file or pinned by the environment. When false, builtIn is false only because nothing says otherwise (a Compose deployment that pins the bundled host never writes it): read what runs from /infra/status.",
+ "example": true
+ },
"host": {
"type": "string",
"example": "openwa-redis"
@@ -22316,6 +22327,7 @@
"required": [
"enabled",
"builtIn",
+ "builtInSet",
"host",
"port",
"passwordSet"
@@ -22348,6 +22360,11 @@
"type": "boolean",
"example": false
},
+ "builtInSet": {
+ "type": "boolean",
+ "description": "Whether the built-in flag is stored, in the saved file or pinned by the environment. When false, builtIn is false only because nothing says otherwise (a Compose deployment that pins the bundled host never writes it): read what runs from /infra/status.",
+ "example": true
+ },
"localPath": {
"type": "string",
"example": "./data/media"
@@ -22373,6 +22390,7 @@
"required": [
"type",
"builtIn",
+ "builtInSet",
"localPath",
"s3Bucket",
"s3Region",
diff --git a/src/modules/infra/dto/infra-response.dto.ts b/src/modules/infra/dto/infra-response.dto.ts
index 324b24183..8fe1150cd 100644
--- a/src/modules/infra/dto/infra-response.dto.ts
+++ b/src/modules/infra/dto/infra-response.dto.ts
@@ -235,6 +235,11 @@ export class InfraUpdateCheckResponseDto {
// ---------- GET /infra/config ----------
+const BUILT_IN_SET_DESCRIPTION =
+ 'Whether the built-in flag is stored, in the saved file or pinned by the environment. When false, builtIn is ' +
+ 'false only because nothing says otherwise (a Compose deployment that pins the bundled host never writes it): ' +
+ 'read what runs from /infra/status.';
+
export class InfraConfigDatabaseDto {
@ApiProperty({ enum: ['sqlite', 'postgres'], example: 'postgres' })
type!: string;
@@ -242,6 +247,9 @@ export class InfraConfigDatabaseDto {
@ApiProperty({ example: true })
builtIn!: boolean;
+ @ApiProperty({ description: BUILT_IN_SET_DESCRIPTION, example: true })
+ builtInSet!: boolean;
+
@ApiProperty({ example: 'openwa-postgres' })
host!: string;
@@ -277,6 +285,9 @@ export class InfraConfigRedisDto {
@ApiProperty({ example: true })
builtIn!: boolean;
+ @ApiProperty({ description: BUILT_IN_SET_DESCRIPTION, example: true })
+ builtInSet!: boolean;
+
@ApiProperty({ example: 'openwa-redis' })
host!: string;
@@ -299,6 +310,9 @@ export class InfraConfigStorageDto {
@ApiProperty({ example: false })
builtIn!: boolean;
+ @ApiProperty({ description: BUILT_IN_SET_DESCRIPTION, example: true })
+ builtInSet!: boolean;
+
@ApiProperty({ example: './data/media' })
localPath!: string;
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 7c0030fb2..59ae8c4d7 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -1401,6 +1401,57 @@ describe('InfraConfigController.getConfig reflects environment-pinned values (#1
});
});
+// A Compose deployment that pins DATABASE_HOST=postgres, REDIS_HOST=redis or S3_ENDPOINT in .env never writes the
+// *_BUILTIN keys, so a false flag there only means nothing says otherwise: the form must tell it from a flag
+// that was saved as false.
+describe('InfraConfigController.getConfig reports whether each built-in flag is stored', () => {
+ const newController = () => new InfraConfigController({} as never, {} as never, {} as never);
+ const withFile = (contents: string) => {
+ (fs.existsSync as jest.Mock).mockReturnValue(true);
+ (fs.readFileSync as jest.Mock).mockReturnValue(contents);
+ };
+ const flags = (cfg: ReturnType<InfraConfigController['getConfig']>) => ({
+ database: [cfg.database.builtIn, cfg.database.builtInSet],
+ redis: [cfg.redis.builtIn, cfg.redis.builtInSet],
+ storage: [cfg.storage.builtIn, cfg.storage.builtInSet],
+ });
+
+ afterEach(() => {
+ (fs.existsSync as jest.Mock).mockReturnValue(false);
+ (fs.readFileSync as jest.Mock).mockReturnValue('');
+ delete process.env.POSTGRES_BUILTIN;
+ recordPinnedEnvKeys({});
+ });
+
+ it('a file that holds no flag reports every flag as not stored', () => {
+ withFile('DATABASE_TYPE=postgres\nDATABASE_HOST=postgres\nREDIS_HOST=redis\nS3_ENDPOINT=http://minio:9000\n');
+
+ expect(flags(newController().getConfig())).toEqual({
+ database: [false, false],
+ redis: [false, false],
+ storage: [false, false],
+ });
+ });
+
+ it('a flag saved as false is stored, as is one saved as true', () => {
+ withFile('POSTGRES_BUILTIN=false\nREDIS_BUILTIN=true\n');
+
+ expect(flags(newController().getConfig())).toEqual({
+ database: [false, true],
+ redis: [true, true],
+ storage: [false, false],
+ });
+ });
+
+ it('a flag only the environment pins is stored', () => {
+ recordPinnedEnvKeys({ POSTGRES_BUILTIN: 'true' });
+ process.env.POSTGRES_BUILTIN = 'true';
+ withFile('');
+
+ expect(flags(newController().getConfig()).database).toEqual([true, true]);
+ });
+});
+
describe('InfraConfigController.requestRestart constrains teardown to managed profiles', () => {
const buildController = (dockerService: Record<string, unknown>) =>
new InfraConfigController(
diff --git a/src/modules/infra/infra-config.controller.ts b/src/modules/infra/infra-config.controller.ts
index c5cdcc935..bc175dcd9 100644
--- a/src/modules/infra/infra-config.controller.ts
+++ b/src/modules/infra/infra-config.controller.ts
@@ -70,6 +70,7 @@ interface SavedConfigResponse {
database: {
type: 'sqlite' | 'postgres';
builtIn: boolean;
+ builtInSet: boolean;
host: string;
port: string;
username: string;
@@ -80,11 +81,12 @@ interface SavedConfigResponse {
sslRejectUnauthorized: boolean;
passwordSet: boolean;
};
- redis: { enabled: boolean; builtIn: boolean; host: string; port: string; passwordSet: boolean };
+ redis: { enabled: boolean; builtIn: boolean; builtInSet: boolean; host: string; port: string; passwordSet: boolean };
queue: { enabled: boolean };
storage: {
type: 'local' | 's3';
builtIn: boolean;
+ builtInSet: boolean;
localPath: string;
s3Bucket: string;
s3Region: string;
@@ -142,6 +144,7 @@ export class InfraConfigController {
database: {
type: effective('DATABASE_TYPE') === 'postgres' ? 'postgres' : 'sqlite',
builtIn: effective('POSTGRES_BUILTIN') === 'true',
+ builtInSet: Boolean(effective('POSTGRES_BUILTIN')),
host: effective('DATABASE_HOST') || '',
port: effective('DATABASE_PORT') || '',
username: effective('DATABASE_USERNAME') || '',
@@ -155,6 +158,7 @@ export class InfraConfigController {
redis: {
enabled: effective('REDIS_ENABLED') === 'true',
builtIn: effective('REDIS_BUILTIN') === 'true',
+ builtInSet: Boolean(effective('REDIS_BUILTIN')),
host: effective('REDIS_HOST') || '',
port: effective('REDIS_PORT') || '',
passwordSet: Boolean(effective('REDIS_PASSWORD')),
@@ -163,6 +167,7 @@ export class InfraConfigController {
storage: {
type: effective('STORAGE_TYPE') === 's3' ? 's3' : 'local',
builtIn: effective('MINIO_BUILTIN') === 'true',
+ builtInSet: Boolean(effective('MINIO_BUILTIN')),
localPath: effective('STORAGE_LOCAL_PATH') || '',
s3Bucket: effective('S3_BUCKET') || '',
s3Region: effective('S3_REGION') || '',