Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(storage): name the S3 credential that is actually missing
Yudhi Armyndharisc9ae0646d875
diff --git a/docs/03-system-architecture.md b/docs/03-system-architecture.mdindex c183b539c..677ccde86 100644--- a/docs/03-system-architecture.md+++ b/docs/03-system-architecture.md@@ -1321,6 +1321,9 @@ export class StorageService {...(endpoint ? { forcePathStyle: true } : {}), // path-style is a MinIO/R2 concern});// bucket auto-created if missing (HeadBucket -> CreateBucket)+ } else {+ // No client, so every putFile below lands on local disk. WARN, naming the missing+ // variables: this is the one degradation with no other signal.}}if (!fs.existsSync(this.localPath)) fs.mkdirSync(this.localPath, { recursive: true });diff --git a/src/common/storage/storage.service.s3.spec.ts b/src/common/storage/storage.service.s3.spec.tsindex c01bb1135..04603c355 100644--- a/src/common/storage/storage.service.s3.spec.ts+++ b/src/common/storage/storage.service.s3.spec.ts@@ -133,6 +133,20 @@ describe('StorageService (s3) client init', () => {expect(warn).toHaveBeenCalledWith(expect.stringContaining('S3_SECRET_ACCESS_KEY'));});+ it('names only the half of the credential pair that is missing', async () => {+ // Reaching the fallback with one of the pair set is a typo in the other. A warning that called+ // every credential absent would point the operator at the one they got right.+ process.env.S3_ACCESS_KEY_ID = 'ENVKEY';+ const warn = jest.spyOn(LoggerService.prototype, 'warn').mockImplementation(() => undefined);+ new StorageService(makeConfig({ region: 'us-east-1' }));+ await flush();++ expect(mockedS3Client).not.toHaveBeenCalled();+ const message = String(warn.mock.calls.at(-1)?.[0]);+ expect(message).toContain('S3_SECRET_ACCESS_KEY');+ expect(message).not.toContain('S3_ACCESS_KEY_ID');+ });+it('prefers canonical env names (S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY) over config', async () => {process.env.S3_ACCESS_KEY_ID = 'ENVKEY';process.env.S3_SECRET_ACCESS_KEY = 'ENVSECRET';diff --git a/src/common/storage/storage.service.ts b/src/common/storage/storage.service.tsindex e091613d7..f5d30516a 100644--- a/src/common/storage/storage.service.ts+++ b/src/common/storage/storage.service.ts@@ -97,10 +97,18 @@ export class StorageService implements OnModuleDestroy {// logging all lives past the client construction above, so an s3 deployment missing its// credentials built no client, wrote every file to local disk, and said nothing at all.// The operator's first symptom was an empty bucket with no failure to point at.+ //+ // Name the variables actually missing rather than declaring all of them absent: reaching+ // here with one of the pair set is a plain typo in the other, and "no credentials found"+ // would send that operator looking at the one they got right.+ const missing = [+ accessKeyId ? null : 'S3_ACCESS_KEY_ID',+ secretAccessKey ? null : 'S3_SECRET_ACCESS_KEY',+ ].filter((name): name is string => name !== null);this.logger.warn(- `STORAGE_TYPE=s3 but no S3 credentials were found; media is being written to the local dir ` +- `'${this.localPath}' instead of the bucket. Set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY ` +- `(the built-in MinIO uses minioadmin/minioadmin).`,+ `STORAGE_TYPE=s3 but ${missing.join(' and ')} is not set; media is being written to the ` ++ `local dir '${this.localPath}' instead of the bucket. The built-in MinIO uses ` ++ `minioadmin/minioadmin.`,);}}