@gugananuvem/aws-local-simulator 1.0.33 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +834 -834
  2. package/aws-config +153 -153
  3. package/bin/aws-local-simulator.js +63 -63
  4. package/package.json +3 -2
  5. package/src/config/config-loader.js +114 -114
  6. package/src/config/default-config.js +79 -79
  7. package/src/config/env-loader.js +68 -68
  8. package/src/index.js +146 -146
  9. package/src/index.mjs +123 -123
  10. package/src/server.js +463 -463
  11. package/src/services/apigateway/index.js +75 -75
  12. package/src/services/apigateway/server.js +607 -607
  13. package/src/services/apigateway/simulator.js +1405 -1405
  14. package/src/services/athena/index.js +75 -75
  15. package/src/services/athena/server.js +101 -101
  16. package/src/services/athena/simulador.js +998 -998
  17. package/src/services/athena/simulator.js +346 -346
  18. package/src/services/cloudformation/index.js +106 -106
  19. package/src/services/cloudformation/server.js +417 -417
  20. package/src/services/cloudformation/simulador.js +1020 -1020
  21. package/src/services/cloudtrail/index.js +84 -84
  22. package/src/services/cloudtrail/server.js +235 -235
  23. package/src/services/cloudtrail/simulador.js +719 -719
  24. package/src/services/cloudwatch/index.js +84 -84
  25. package/src/services/cloudwatch/server.js +366 -366
  26. package/src/services/cloudwatch/simulador.js +1173 -1173
  27. package/src/services/cognito/index.js +79 -79
  28. package/src/services/cognito/server.js +297 -297
  29. package/src/services/cognito/simulator.js +1992 -1761
  30. package/src/services/config/index.js +96 -96
  31. package/src/services/config/server.js +215 -215
  32. package/src/services/config/simulador.js +1260 -1260
  33. package/src/services/dynamodb/index.js +74 -74
  34. package/src/services/dynamodb/server.js +139 -139
  35. package/src/services/dynamodb/simulator.js +1005 -994
  36. package/src/services/dynamodb/sqlite-store.js +722 -0
  37. package/src/services/ecs/index.js +65 -65
  38. package/src/services/ecs/server.js +235 -235
  39. package/src/services/ecs/simulator.js +844 -844
  40. package/src/services/eventbridge/index.js +89 -89
  41. package/src/services/eventbridge/server.js +209 -209
  42. package/src/services/eventbridge/simulator.js +684 -684
  43. package/src/services/index.js +45 -45
  44. package/src/services/kms/index.js +75 -75
  45. package/src/services/kms/server.js +81 -81
  46. package/src/services/kms/simulator.js +344 -344
  47. package/src/services/lambda/handler-loader.js +183 -183
  48. package/src/services/lambda/index.js +81 -81
  49. package/src/services/lambda/route-registry.js +274 -274
  50. package/src/services/lambda/server.js +191 -191
  51. package/src/services/lambda/simulator.js +364 -364
  52. package/src/services/parameter-store/index.js +80 -80
  53. package/src/services/parameter-store/server.js +50 -50
  54. package/src/services/parameter-store/simulator.js +201 -201
  55. package/src/services/s3/index.js +73 -73
  56. package/src/services/s3/server.js +350 -350
  57. package/src/services/s3/simulator.js +568 -568
  58. package/src/services/secret-manager/index.js +80 -80
  59. package/src/services/secret-manager/server.js +51 -51
  60. package/src/services/secret-manager/simulator.js +182 -182
  61. package/src/services/sns/index.js +89 -89
  62. package/src/services/sns/server.js +607 -607
  63. package/src/services/sns/simulator.js +1482 -1482
  64. package/src/services/sqs/index.js +98 -98
  65. package/src/services/sqs/server.js +360 -360
  66. package/src/services/sqs/simulator.js +509 -509
  67. package/src/services/sts/index.js +37 -37
  68. package/src/services/sts/server.js +144 -144
  69. package/src/services/sts/simulator.js +69 -69
  70. package/src/services/xray/index.js +83 -83
  71. package/src/services/xray/server.js +308 -308
  72. package/src/services/xray/simulador.js +994 -994
  73. package/src/template/aws-config-template.js +87 -87
  74. package/src/template/aws-config-template.mjs +90 -90
  75. package/src/template/config-template.json +203 -203
  76. package/src/utils/aws-config.js +91 -91
  77. package/src/utils/cloudtrail-audit.js +129 -129
  78. package/src/utils/local-store.js +83 -83
  79. package/src/utils/logger.js +59 -59
@@ -1,96 +1,96 @@
1
- 'use strict';
2
-
3
- /**
4
- * @fileoverview AWS Config Service
5
- * Porta padrão: 4013
6
- */
7
-
8
- const http = require('http');
9
- const path = require('path');
10
- const { ConfigSimulator } = require('./simulador');
11
- const { createConfigServer } = require('./server');
12
- const LocalStore = require('../../utils/local-store');
13
-
14
- class ConfigService {
15
- constructor(config) {
16
- this.config = config;
17
- this.logger = require('../../utils/logger');
18
- this.name = 'config';
19
- this.port = config?.ports?.config || config?.services?.config?.port || 4013;
20
- this.store = null;
21
- this.simulator = null;
22
- this._server = null;
23
- this.isRunning = false;
24
- }
25
-
26
- async initialize() {
27
- this.logger.debug(`Inicializando AWS Config Service na porta ${this.port}...`);
28
- const dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA_DIR;
29
- this.store = new LocalStore(path.join(dataDir, 'config'));
30
- this.simulator = new ConfigSimulator(this.config, this.store, this.logger);
31
- await this.simulator.load();
32
- this.logger.debug('AWS Config Service inicializado');
33
- }
34
-
35
- injectDependencies(server) {
36
- if (!server) return;
37
- const s3 = server.getService('s3');
38
- if (s3?.simulator) this.simulator.s3Simulator = s3.simulator;
39
- const sns = server.getService('sns');
40
- if (sns?.simulator) this.simulator.snsSimulator = sns.simulator;
41
- const lambda = server.getService('lambda');
42
- if (lambda?.simulator) this.simulator.lambdaSimulator = lambda.simulator;
43
- const dynamo = server.getService('dynamodb');
44
- if (dynamo?.simulator) this.simulator.dynamoSimulator = dynamo.simulator;
45
- const ct = server.getService('cloudtrail');
46
- if (ct?.simulator) this.simulator.cloudtrailSimulator = ct.simulator;
47
- }
48
-
49
- async start() {
50
- if (this.isRunning) return;
51
- const { handler } = createConfigServer(this.simulator, this.logger);
52
- this._server = http.createServer((req, res) => {
53
- handler(req, res).catch(err => {
54
- this.logger.error('[Config] Unhandled error:', err);
55
- if (!res.headersSent) {
56
- res.writeHead(500, { 'Content-Type': 'application/x-amz-json-1.1' });
57
- res.end(JSON.stringify({ __type: 'InternalFailure', message: err.message }));
58
- }
59
- });
60
- });
61
- return new Promise((resolve, reject) => {
62
- this._server.listen(this.port, '0.0.0.0', (err) => {
63
- if (err) return reject(err);
64
- this.isRunning = true;
65
- this.logger.debug(`AWS Config rodando na porta ${this.port}`);
66
- resolve();
67
- });
68
- });
69
- }
70
-
71
- async stop() {
72
- if (!this.isRunning || !this._server) return;
73
- await new Promise((resolve) => this._server.close(resolve));
74
- this.simulator._stopRecording?.();
75
- this._server = null;
76
- this.isRunning = false;
77
- }
78
-
79
- async reset() {
80
- this.simulator.reset();
81
- await this.simulator.save();
82
- }
83
-
84
- getStatus() {
85
- return {
86
- running: this.isRunning,
87
- port: this.port,
88
- endpoint: `http://localhost:${this.port}`,
89
- ...this.simulator?.getStatus(),
90
- };
91
- }
92
-
93
- getSimulator() { return this.simulator; }
94
- }
95
-
96
- module.exports = { ConfigService };
1
+ 'use strict';
2
+
3
+ /**
4
+ * @fileoverview AWS Config Service
5
+ * Porta padrão: 4013
6
+ */
7
+
8
+ const http = require('http');
9
+ const path = require('path');
10
+ const { ConfigSimulator } = require('./simulador');
11
+ const { createConfigServer } = require('./server');
12
+ const LocalStore = require('../../utils/local-store');
13
+
14
+ class ConfigService {
15
+ constructor(config) {
16
+ this.config = config;
17
+ this.logger = require('../../utils/logger');
18
+ this.name = 'config';
19
+ this.port = config?.ports?.config || config?.services?.config?.port || 4013;
20
+ this.store = null;
21
+ this.simulator = null;
22
+ this._server = null;
23
+ this.isRunning = false;
24
+ }
25
+
26
+ async initialize() {
27
+ this.logger.debug(`Inicializando AWS Config Service na porta ${this.port}...`);
28
+ const dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA_DIR;
29
+ this.store = new LocalStore(path.join(dataDir, 'config'));
30
+ this.simulator = new ConfigSimulator(this.config, this.store, this.logger);
31
+ await this.simulator.load();
32
+ this.logger.debug('AWS Config Service inicializado');
33
+ }
34
+
35
+ injectDependencies(server) {
36
+ if (!server) return;
37
+ const s3 = server.getService('s3');
38
+ if (s3?.simulator) this.simulator.s3Simulator = s3.simulator;
39
+ const sns = server.getService('sns');
40
+ if (sns?.simulator) this.simulator.snsSimulator = sns.simulator;
41
+ const lambda = server.getService('lambda');
42
+ if (lambda?.simulator) this.simulator.lambdaSimulator = lambda.simulator;
43
+ const dynamo = server.getService('dynamodb');
44
+ if (dynamo?.simulator) this.simulator.dynamoSimulator = dynamo.simulator;
45
+ const ct = server.getService('cloudtrail');
46
+ if (ct?.simulator) this.simulator.cloudtrailSimulator = ct.simulator;
47
+ }
48
+
49
+ async start() {
50
+ if (this.isRunning) return;
51
+ const { handler } = createConfigServer(this.simulator, this.logger);
52
+ this._server = http.createServer((req, res) => {
53
+ handler(req, res).catch(err => {
54
+ this.logger.error('[Config] Unhandled error:', err);
55
+ if (!res.headersSent) {
56
+ res.writeHead(500, { 'Content-Type': 'application/x-amz-json-1.1' });
57
+ res.end(JSON.stringify({ __type: 'InternalFailure', message: err.message }));
58
+ }
59
+ });
60
+ });
61
+ return new Promise((resolve, reject) => {
62
+ this._server.listen(this.port, '0.0.0.0', (err) => {
63
+ if (err) return reject(err);
64
+ this.isRunning = true;
65
+ this.logger.debug(`AWS Config rodando na porta ${this.port}`);
66
+ resolve();
67
+ });
68
+ });
69
+ }
70
+
71
+ async stop() {
72
+ if (!this.isRunning || !this._server) return;
73
+ await new Promise((resolve) => this._server.close(resolve));
74
+ this.simulator._stopRecording?.();
75
+ this._server = null;
76
+ this.isRunning = false;
77
+ }
78
+
79
+ async reset() {
80
+ this.simulator.reset();
81
+ await this.simulator.save();
82
+ }
83
+
84
+ getStatus() {
85
+ return {
86
+ running: this.isRunning,
87
+ port: this.port,
88
+ endpoint: `http://localhost:${this.port}`,
89
+ ...this.simulator?.getStatus(),
90
+ };
91
+ }
92
+
93
+ getSimulator() { return this.simulator; }
94
+ }
95
+
96
+ module.exports = { ConfigService };
@@ -1,215 +1,215 @@
1
- 'use strict';
2
-
3
- /**
4
- * @fileoverview AWS Config HTTP Server
5
- *
6
- * Protocolo: JSON com header X-Amz-Target
7
- * Compatível com @aws-sdk/client-config-service (ConfigServiceClient)
8
- *
9
- * Target prefix: com.amazonaws.config.v20141112.
10
- *
11
- * Rotas admin:
12
- * GET /__admin/rules → lista config rules
13
- * GET /__admin/recorders → lista recorders
14
- * GET /__admin/resources → lista recursos descobertos
15
- * GET /__admin/health → health check
16
- * POST /__admin/reset → reset state
17
- * POST /__internal/record-resource → registra recurso (cross-service)
18
- */
19
-
20
- function createConfigServer(simulator, logger) {
21
- function parseBody(req) {
22
- return new Promise((resolve, reject) => {
23
- let data = '';
24
- req.on('data', chunk => (data += chunk));
25
- req.on('end', () => {
26
- try {
27
- resolve(data ? JSON.parse(data) : {});
28
- } catch {
29
- resolve({});
30
- }
31
- });
32
- req.on('error', reject);
33
- });
34
- }
35
-
36
- function sendJson(res, statusCode, body) {
37
- const payload = JSON.stringify(body);
38
- res.writeHead(statusCode, {
39
- 'Content-Type': 'application/x-amz-json-1.1',
40
- 'Content-Length': Buffer.byteLength(payload),
41
- 'x-amzn-RequestId': require('crypto').randomUUID(),
42
- });
43
- res.end(payload);
44
- }
45
-
46
- function sendError(res, err) {
47
- const statusCode = err.statusCode || 400;
48
- const code = err.code || 'InternalError';
49
- logger.error(`[Config] Error: ${code} — ${err.message}`);
50
- sendJson(res, statusCode, {
51
- __type: code,
52
- message: err.message,
53
- });
54
- }
55
-
56
- // Mapeamento target → método do simulador
57
- const TARGET_MAP = {
58
- // Configuration Recorders
59
- 'PutConfigurationRecorder': (body) => simulator.putConfigurationRecorder(body),
60
- 'DeleteConfigurationRecorder': (body) => simulator.deleteConfigurationRecorder(body),
61
- 'DescribeConfigurationRecorders': (body) => simulator.describeConfigurationRecorders(body),
62
- 'DescribeConfigurationRecorderStatus': (body) => simulator.describeConfigurationRecorderStatus(body),
63
- 'StartConfigurationRecorder': (body) => simulator.startConfigurationRecorder(body),
64
- 'StopConfigurationRecorder': (body) => simulator.stopConfigurationRecorder(body),
65
-
66
- // Delivery Channels
67
- 'PutDeliveryChannel': (body) => simulator.putDeliveryChannel(body),
68
- 'DeleteDeliveryChannel': (body) => simulator.deleteDeliveryChannel(body),
69
- 'DescribeDeliveryChannels': (body) => simulator.describeDeliveryChannels(body),
70
- 'DescribeDeliveryChannelStatus': (body) => simulator.describeDeliveryChannelStatus(body),
71
- 'DeliverConfigSnapshot': (body) => simulator.deliverConfigSnapshot(body),
72
-
73
- // Config Rules
74
- 'PutConfigRule': (body) => simulator.putConfigRule(body),
75
- 'DeleteConfigRule': (body) => simulator.deleteConfigRule(body),
76
- 'DescribeConfigRules': (body) => simulator.describeConfigRules(body),
77
- 'DescribeConfigRuleEvaluationStatus': (body) => simulator.describeConfigRuleEvaluationStatus(body),
78
- 'StartConfigRulesEvaluation': (body) => simulator.startConfigRulesEvaluation(body),
79
- 'GetComplianceDetailsByConfigRule': (body) => simulator.getComplianceDetailsByConfigRule(body),
80
- 'GetComplianceDetailsByResource': (body) => simulator.getComplianceDetailsByResource(body),
81
- 'GetComplianceSummaryByConfigRule': (body) => simulator.getComplianceSummaryByConfigRule(body),
82
- 'GetComplianceSummaryByResourceType': (body) => simulator.getComplianceSummaryByResourceType(body),
83
-
84
- // Resource Configuration
85
- 'GetResourceConfigHistory': (body) => simulator.getResourceConfigHistory(body),
86
- 'ListDiscoveredResources': (body) => simulator.listDiscoveredResources(body),
87
- 'GetDiscoveredResourceCounts': (body) => simulator.getDiscoveredResourceCounts(body),
88
- 'BatchGetResourceConfig': (body) => simulator.batchGetResourceConfig(body),
89
-
90
- // Conformance Packs
91
- 'PutConformancePack': (body) => simulator.putConformancePack(body),
92
- 'DeleteConformancePack': (body) => simulator.deleteConformancePack(body),
93
- 'DescribeConformancePacks': (body) => simulator.describeConformancePacks(body),
94
- 'DescribeConformancePackStatus': (body) => simulator.describeConformancePackStatus(body),
95
- 'GetConformancePackComplianceSummary': (body) => simulator.getConformancePackComplianceSummary(body),
96
-
97
- // Aggregators
98
- 'PutConfigurationAggregator': (body) => simulator.putConfigurationAggregator(body),
99
- 'DeleteConfigurationAggregator': (body) => simulator.deleteConfigurationAggregator(body),
100
- 'DescribeConfigurationAggregators': (body) => simulator.describeConfigurationAggregators(body),
101
-
102
- // Remediation
103
- 'PutRemediationConfigurations': (body) => simulator.putRemediationConfigurations(body),
104
- 'DeleteRemediationConfigurations': (body) => simulator.deleteRemediationConfigurations(body),
105
- 'DescribeRemediationConfigurations': (body) => simulator.describeRemediationConfigurations(body),
106
- 'StartRemediationExecution': (body) => simulator.startRemediationExecution(body),
107
-
108
- // Tags
109
- 'TagResource': (body) => simulator.tagResource(body),
110
- 'UntagResource': (body) => simulator.untagResource(body),
111
- 'ListTagsForResource': (body) => simulator.listTagsForResource(body),
112
- };
113
-
114
- async function handler(req, res) {
115
- const url = req.url || '/';
116
- const method = req.method || 'GET';
117
-
118
- // ── Rota interna cross-service ────────────────────────────────────────────
119
- if (url === '/__internal/record-resource' && method === 'POST') {
120
- try {
121
- const body = await parseBody(req);
122
- simulator.recordResource(body.resourceType, body.resourceId, body.configuration);
123
- return sendJson(res, 200, { ok: true });
124
- } catch (err) {
125
- return sendError(res, err);
126
- }
127
- }
128
-
129
- // ── Rotas admin ───────────────────────────────────────────────────────────
130
- if (url.startsWith('/__admin')) {
131
- try {
132
- if (url === '/__admin/health' && method === 'GET') {
133
- return sendJson(res, 200, { status: 'ok', service: 'config', ...simulator.getStatus() });
134
- }
135
-
136
- if (url === '/__admin/rules' && method === 'GET') {
137
- return sendJson(res, 200, {
138
- rules: Array.from(simulator.configRules.values()),
139
- total: simulator.configRules.size,
140
- });
141
- }
142
-
143
- if (url === '/__admin/recorders' && method === 'GET') {
144
- return sendJson(res, 200, {
145
- recorders: Array.from(simulator.recorders.values()),
146
- status: Array.from(simulator.recorderStatus.values()),
147
- });
148
- }
149
-
150
- if (url === '/__admin/resources' && method === 'GET') {
151
- return sendJson(res, 200, {
152
- resources: Array.from(simulator.discoveredResources.values()),
153
- total: simulator.discoveredResources.size,
154
- });
155
- }
156
-
157
- if (url === '/__admin/conformance-packs' && method === 'GET') {
158
- return sendJson(res, 200, {
159
- packs: Array.from(simulator.conformancePacks.values()),
160
- total: simulator.conformancePacks.size,
161
- });
162
- }
163
-
164
- if (url === '/__admin/aggregators' && method === 'GET') {
165
- return sendJson(res, 200, {
166
- aggregators: Array.from(simulator.aggregators.values()),
167
- total: simulator.aggregators.size,
168
- });
169
- }
170
-
171
- if (url === '/__admin/reset' && method === 'POST') {
172
- simulator.reset();
173
- return sendJson(res, 200, { ok: true, message: 'Config state reset' });
174
- }
175
-
176
- return sendJson(res, 404, { __type: 'ResourceNotFoundException', message: `Admin route not found: ${url}` });
177
- } catch (err) {
178
- return sendError(res, err);
179
- }
180
- }
181
-
182
- // ── Rota principal AWS Config API ─────────────────────────────────────────
183
- if (method === 'POST' && (url === '/' || url === '')) {
184
- const rawTarget = req.headers['x-amz-target'] || '';
185
- // Remove prefixo: "com.amazonaws.config.v20141112.ConfigService."
186
- const action = rawTarget.split('.').pop();
187
-
188
- if (!action || !TARGET_MAP[action]) {
189
- return sendJson(res, 400, {
190
- __type: 'InvalidAction',
191
- message: `Unknown action: ${rawTarget}`,
192
- });
193
- }
194
-
195
- try {
196
- const body = await parseBody(req);
197
- logger.debug(`[Config] Action: ${action}`);
198
- const result = await TARGET_MAP[action](body);
199
- return sendJson(res, 200, result || {});
200
- } catch (err) {
201
- return sendError(res, err);
202
- }
203
- }
204
-
205
- // 404 fallback
206
- sendJson(res, 404, {
207
- __type: 'ResourceNotFoundException',
208
- message: `Route not found: ${method} ${url}`,
209
- });
210
- }
211
-
212
- return { handler };
213
- }
214
-
215
- module.exports = { createConfigServer };
1
+ 'use strict';
2
+
3
+ /**
4
+ * @fileoverview AWS Config HTTP Server
5
+ *
6
+ * Protocolo: JSON com header X-Amz-Target
7
+ * Compatível com @aws-sdk/client-config-service (ConfigServiceClient)
8
+ *
9
+ * Target prefix: com.amazonaws.config.v20141112.
10
+ *
11
+ * Rotas admin:
12
+ * GET /__admin/rules → lista config rules
13
+ * GET /__admin/recorders → lista recorders
14
+ * GET /__admin/resources → lista recursos descobertos
15
+ * GET /__admin/health → health check
16
+ * POST /__admin/reset → reset state
17
+ * POST /__internal/record-resource → registra recurso (cross-service)
18
+ */
19
+
20
+ function createConfigServer(simulator, logger) {
21
+ function parseBody(req) {
22
+ return new Promise((resolve, reject) => {
23
+ let data = '';
24
+ req.on('data', chunk => (data += chunk));
25
+ req.on('end', () => {
26
+ try {
27
+ resolve(data ? JSON.parse(data) : {});
28
+ } catch {
29
+ resolve({});
30
+ }
31
+ });
32
+ req.on('error', reject);
33
+ });
34
+ }
35
+
36
+ function sendJson(res, statusCode, body) {
37
+ const payload = JSON.stringify(body);
38
+ res.writeHead(statusCode, {
39
+ 'Content-Type': 'application/x-amz-json-1.1',
40
+ 'Content-Length': Buffer.byteLength(payload),
41
+ 'x-amzn-RequestId': require('crypto').randomUUID(),
42
+ });
43
+ res.end(payload);
44
+ }
45
+
46
+ function sendError(res, err) {
47
+ const statusCode = err.statusCode || 400;
48
+ const code = err.code || 'InternalError';
49
+ logger.error(`[Config] Error: ${code} — ${err.message}`);
50
+ sendJson(res, statusCode, {
51
+ __type: code,
52
+ message: err.message,
53
+ });
54
+ }
55
+
56
+ // Mapeamento target → método do simulador
57
+ const TARGET_MAP = {
58
+ // Configuration Recorders
59
+ 'PutConfigurationRecorder': (body) => simulator.putConfigurationRecorder(body),
60
+ 'DeleteConfigurationRecorder': (body) => simulator.deleteConfigurationRecorder(body),
61
+ 'DescribeConfigurationRecorders': (body) => simulator.describeConfigurationRecorders(body),
62
+ 'DescribeConfigurationRecorderStatus': (body) => simulator.describeConfigurationRecorderStatus(body),
63
+ 'StartConfigurationRecorder': (body) => simulator.startConfigurationRecorder(body),
64
+ 'StopConfigurationRecorder': (body) => simulator.stopConfigurationRecorder(body),
65
+
66
+ // Delivery Channels
67
+ 'PutDeliveryChannel': (body) => simulator.putDeliveryChannel(body),
68
+ 'DeleteDeliveryChannel': (body) => simulator.deleteDeliveryChannel(body),
69
+ 'DescribeDeliveryChannels': (body) => simulator.describeDeliveryChannels(body),
70
+ 'DescribeDeliveryChannelStatus': (body) => simulator.describeDeliveryChannelStatus(body),
71
+ 'DeliverConfigSnapshot': (body) => simulator.deliverConfigSnapshot(body),
72
+
73
+ // Config Rules
74
+ 'PutConfigRule': (body) => simulator.putConfigRule(body),
75
+ 'DeleteConfigRule': (body) => simulator.deleteConfigRule(body),
76
+ 'DescribeConfigRules': (body) => simulator.describeConfigRules(body),
77
+ 'DescribeConfigRuleEvaluationStatus': (body) => simulator.describeConfigRuleEvaluationStatus(body),
78
+ 'StartConfigRulesEvaluation': (body) => simulator.startConfigRulesEvaluation(body),
79
+ 'GetComplianceDetailsByConfigRule': (body) => simulator.getComplianceDetailsByConfigRule(body),
80
+ 'GetComplianceDetailsByResource': (body) => simulator.getComplianceDetailsByResource(body),
81
+ 'GetComplianceSummaryByConfigRule': (body) => simulator.getComplianceSummaryByConfigRule(body),
82
+ 'GetComplianceSummaryByResourceType': (body) => simulator.getComplianceSummaryByResourceType(body),
83
+
84
+ // Resource Configuration
85
+ 'GetResourceConfigHistory': (body) => simulator.getResourceConfigHistory(body),
86
+ 'ListDiscoveredResources': (body) => simulator.listDiscoveredResources(body),
87
+ 'GetDiscoveredResourceCounts': (body) => simulator.getDiscoveredResourceCounts(body),
88
+ 'BatchGetResourceConfig': (body) => simulator.batchGetResourceConfig(body),
89
+
90
+ // Conformance Packs
91
+ 'PutConformancePack': (body) => simulator.putConformancePack(body),
92
+ 'DeleteConformancePack': (body) => simulator.deleteConformancePack(body),
93
+ 'DescribeConformancePacks': (body) => simulator.describeConformancePacks(body),
94
+ 'DescribeConformancePackStatus': (body) => simulator.describeConformancePackStatus(body),
95
+ 'GetConformancePackComplianceSummary': (body) => simulator.getConformancePackComplianceSummary(body),
96
+
97
+ // Aggregators
98
+ 'PutConfigurationAggregator': (body) => simulator.putConfigurationAggregator(body),
99
+ 'DeleteConfigurationAggregator': (body) => simulator.deleteConfigurationAggregator(body),
100
+ 'DescribeConfigurationAggregators': (body) => simulator.describeConfigurationAggregators(body),
101
+
102
+ // Remediation
103
+ 'PutRemediationConfigurations': (body) => simulator.putRemediationConfigurations(body),
104
+ 'DeleteRemediationConfigurations': (body) => simulator.deleteRemediationConfigurations(body),
105
+ 'DescribeRemediationConfigurations': (body) => simulator.describeRemediationConfigurations(body),
106
+ 'StartRemediationExecution': (body) => simulator.startRemediationExecution(body),
107
+
108
+ // Tags
109
+ 'TagResource': (body) => simulator.tagResource(body),
110
+ 'UntagResource': (body) => simulator.untagResource(body),
111
+ 'ListTagsForResource': (body) => simulator.listTagsForResource(body),
112
+ };
113
+
114
+ async function handler(req, res) {
115
+ const url = req.url || '/';
116
+ const method = req.method || 'GET';
117
+
118
+ // ── Rota interna cross-service ────────────────────────────────────────────
119
+ if (url === '/__internal/record-resource' && method === 'POST') {
120
+ try {
121
+ const body = await parseBody(req);
122
+ simulator.recordResource(body.resourceType, body.resourceId, body.configuration);
123
+ return sendJson(res, 200, { ok: true });
124
+ } catch (err) {
125
+ return sendError(res, err);
126
+ }
127
+ }
128
+
129
+ // ── Rotas admin ───────────────────────────────────────────────────────────
130
+ if (url.startsWith('/__admin')) {
131
+ try {
132
+ if (url === '/__admin/health' && method === 'GET') {
133
+ return sendJson(res, 200, { status: 'ok', service: 'config', ...simulator.getStatus() });
134
+ }
135
+
136
+ if (url === '/__admin/rules' && method === 'GET') {
137
+ return sendJson(res, 200, {
138
+ rules: Array.from(simulator.configRules.values()),
139
+ total: simulator.configRules.size,
140
+ });
141
+ }
142
+
143
+ if (url === '/__admin/recorders' && method === 'GET') {
144
+ return sendJson(res, 200, {
145
+ recorders: Array.from(simulator.recorders.values()),
146
+ status: Array.from(simulator.recorderStatus.values()),
147
+ });
148
+ }
149
+
150
+ if (url === '/__admin/resources' && method === 'GET') {
151
+ return sendJson(res, 200, {
152
+ resources: Array.from(simulator.discoveredResources.values()),
153
+ total: simulator.discoveredResources.size,
154
+ });
155
+ }
156
+
157
+ if (url === '/__admin/conformance-packs' && method === 'GET') {
158
+ return sendJson(res, 200, {
159
+ packs: Array.from(simulator.conformancePacks.values()),
160
+ total: simulator.conformancePacks.size,
161
+ });
162
+ }
163
+
164
+ if (url === '/__admin/aggregators' && method === 'GET') {
165
+ return sendJson(res, 200, {
166
+ aggregators: Array.from(simulator.aggregators.values()),
167
+ total: simulator.aggregators.size,
168
+ });
169
+ }
170
+
171
+ if (url === '/__admin/reset' && method === 'POST') {
172
+ simulator.reset();
173
+ return sendJson(res, 200, { ok: true, message: 'Config state reset' });
174
+ }
175
+
176
+ return sendJson(res, 404, { __type: 'ResourceNotFoundException', message: `Admin route not found: ${url}` });
177
+ } catch (err) {
178
+ return sendError(res, err);
179
+ }
180
+ }
181
+
182
+ // ── Rota principal AWS Config API ─────────────────────────────────────────
183
+ if (method === 'POST' && (url === '/' || url === '')) {
184
+ const rawTarget = req.headers['x-amz-target'] || '';
185
+ // Remove prefixo: "com.amazonaws.config.v20141112.ConfigService."
186
+ const action = rawTarget.split('.').pop();
187
+
188
+ if (!action || !TARGET_MAP[action]) {
189
+ return sendJson(res, 400, {
190
+ __type: 'InvalidAction',
191
+ message: `Unknown action: ${rawTarget}`,
192
+ });
193
+ }
194
+
195
+ try {
196
+ const body = await parseBody(req);
197
+ logger.debug(`[Config] Action: ${action}`);
198
+ const result = await TARGET_MAP[action](body);
199
+ return sendJson(res, 200, result || {});
200
+ } catch (err) {
201
+ return sendError(res, err);
202
+ }
203
+ }
204
+
205
+ // 404 fallback
206
+ sendJson(res, 404, {
207
+ __type: 'ResourceNotFoundException',
208
+ message: `Route not found: ${method} ${url}`,
209
+ });
210
+ }
211
+
212
+ return { handler };
213
+ }
214
+
215
+ module.exports = { createConfigServer };