Skip to content

Commit c996215

Browse files
committed
fix: config registry list
1 parent e8f1230 commit c996215

File tree

9 files changed

+173
-166
lines changed

9 files changed

+173
-166
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Module } from '@nestjs/common';
2+
import { ConfigCollectorService } from './config-collector.service';
3+
4+
@Module({
5+
providers: [ConfigCollectorService],
6+
exports: [ConfigCollectorService],
7+
})
8+
export class ConfigCollectorModule {}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { ConfigRegistry } from './config-registry.service';
3+
4+
@Injectable()
5+
export class ConfigCollectorService {
6+
private extendedConfigs: Record<string, any> = {};
7+
private sensitiveKeys = ['secret', 'password', 'key', 'cert', 'ca'];
8+
9+
constructor() {}
10+
11+
/**
12+
* Register a configuration
13+
*/
14+
registerConfig(name: string, config: any): void {
15+
this.extendedConfigs[name] = config;
16+
this.collectConfig(name, config);
17+
}
18+
19+
/**
20+
* Check if a key is sensitive
21+
*/
22+
private isSensitiveKey(key: string): boolean {
23+
return this.sensitiveKeys.some((sensitiveKey) =>
24+
key.toLowerCase().includes(sensitiveKey.toLowerCase()),
25+
);
26+
}
27+
28+
/**
29+
* Mask sensitive value
30+
*/
31+
private maskValue(value: any): any {
32+
if (typeof value === 'string') {
33+
return '******';
34+
}
35+
return value;
36+
}
37+
38+
/**
39+
* Collect configuration keys from a specific config object
40+
*/
41+
private collectConfig(configName: string, config: any): void {
42+
if (!config) return;
43+
44+
const processConfig = (obj: any): any => {
45+
if (!obj) return obj;
46+
47+
if (typeof obj === 'object') {
48+
const result = Array.isArray(obj) ? [] : {};
49+
50+
Object.entries(obj).forEach(([key, value]) => {
51+
if (typeof value === 'object' && value !== null) {
52+
result[key] = processConfig(value);
53+
} else {
54+
result[key] = this.isSensitiveKey(key)
55+
? this.maskValue(value)
56+
: value;
57+
}
58+
});
59+
60+
return result;
61+
}
62+
63+
return obj;
64+
};
65+
66+
const processedConfig = processConfig(config);
67+
ConfigRegistry.addConfigKey(configName, null, processedConfig);
68+
}
69+
70+
/**
71+
* Get all collected configuration keys
72+
*/
73+
getAllConfigKeys(): Record<string, any> {
74+
return ConfigRegistry.getAllConfigKeys();
75+
}
76+
77+
/**
78+
* Get configuration keys for a specific category
79+
*/
80+
getConfigKeysForCategory(category: string): any {
81+
return ConfigRegistry.getConfigKeysForCategory(category);
82+
}
83+
84+
/**
85+
* Get a configuration by name
86+
*/
87+
getConfig(name: string): any {
88+
return this.extendedConfigs[name];
89+
}
90+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Global Configuration Registry Service
3+
*
4+
* Stores and organizes all configuration keys by category.
5+
* This provides a centralized way to access configuration metadata.
6+
*/
7+
export class ConfigRegistry {
8+
private static configKeys: Record<string, any> = {};
9+
10+
/**
11+
* Get all configuration keys organized by category
12+
*/
13+
static getAllConfigKeys(): Record<string, any> {
14+
return { ...this.configKeys };
15+
}
16+
17+
/**
18+
* Get configuration keys for a specific category
19+
*/
20+
static getConfigKeysForCategory(category: string): any {
21+
return this.configKeys[category] || {};
22+
}
23+
24+
/**
25+
* Add or update a configuration key to the registry
26+
*/
27+
static addConfigKey(
28+
category: string,
29+
subcategory: string | null,
30+
value: any,
31+
): void {
32+
if (!this.configKeys[category]) {
33+
this.configKeys[category] = subcategory ? {} : [];
34+
}
35+
36+
if (subcategory) {
37+
if (!this.configKeys[category][subcategory]) {
38+
this.configKeys[category][subcategory] = [];
39+
}
40+
41+
if (!this.configKeys[category][subcategory].includes(value)) {
42+
this.configKeys[category][subcategory].push(value);
43+
}
44+
} else {
45+
if (
46+
Array.isArray(this.configKeys[category]) &&
47+
!this.configKeys[category].includes(value)
48+
) {
49+
this.configKeys[category].push(value);
50+
}
51+
}
52+
}
53+
54+
/**
55+
* Clear all registered configuration keys
56+
*/
57+
static clear(): void {
58+
this.configKeys = {};
59+
}
60+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './config-collector.service';
2+
export * from './config-registry.service';
3+
export * from './config-collector.module';

src/frameworks/data-services/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './nats';
22
export * from './prisma';
33
export * from './method-collector';
4+
export * from './config';

src/modules/messaging/domain/usecases/handlers/system-control.handler.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ErrorResponse, log, SuccessResponse } from '@/frameworks';
1+
import {
2+
ConfigCollectorService,
3+
ErrorResponse,
4+
log,
5+
SuccessResponse,
6+
} from '@/frameworks';
27
import fs from 'fs';
38
import path from 'path';
49
import {
@@ -7,7 +12,6 @@ import {
712
} from '@/modules/messaging/domain/entities/messaging-adapter.interface';
813
import { Inject, Injectable } from '@nestjs/common';
914
import * as os from 'os';
10-
import { ConfigRegistryService } from '@/modules/messaging/domain/usecases/services/config-registry.service';
1115
import { SubjectFactory } from '../factories/subject.factory';
1216
import { SYSTEM_CONTROL_MESSAGE_TYPE } from './constant.handler';
1317
import {
@@ -22,7 +26,7 @@ export class SystemControlHandler {
2226
constructor(
2327
@Inject(MESSAGING_ADAPTER)
2428
private readonly messagingAdapter: IMessagingAdapter,
25-
private readonly configRegistry: ConfigRegistryService,
29+
private readonly configCollector: ConfigCollectorService,
2630
private readonly methodCollectorService: MethodCollectorService,
2731
) {}
2832

@@ -150,7 +154,7 @@ export class SystemControlHandler {
150154

151155
public async getConfigurationNames() {
152156
try {
153-
const configNames = this.configRegistry.getAllConfigKeys();
157+
const configNames = this.configCollector.getAllConfigKeys();
154158
const response = new SuccessResponse(
155159
'Configuration names retrieved successfully',
156160
{

src/modules/messaging/domain/usecases/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export * from './adapter/nats-messaging.adapter';
22
export * from './handlers/system-control.handler';
33
export * from './handlers/system-monitor.handler';
44
export * from './handlers/constant.handler';
5-
export * from './services/config-registry.service';
65
export * from './factories/subject.factory';

src/modules/messaging/domain/usecases/services/config-registry.service.ts

Lines changed: 0 additions & 158 deletions
This file was deleted.

0 commit comments

Comments
 (0)