@gugananuvem/aws-local-simulator 1.0.14 → 1.0.15

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 (77) hide show
  1. package/README.md +594 -481
  2. package/bin/aws-local-simulator.js +63 -63
  3. package/package.json +11 -10
  4. package/src/config/config-loader.js +114 -114
  5. package/src/config/default-config.js +68 -68
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +146 -146
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +227 -227
  10. package/src/services/apigateway/index.js +73 -73
  11. package/src/services/apigateway/server.js +507 -507
  12. package/src/services/apigateway/simulator.js +1261 -1261
  13. package/src/services/athena/index.js +75 -75
  14. package/src/services/athena/server.js +101 -101
  15. package/src/services/athena/simulador.js +998 -998
  16. package/src/services/athena/simulator.js +346 -346
  17. package/src/services/cloudformation/index.js +106 -106
  18. package/src/services/cloudformation/server.js +417 -417
  19. package/src/services/cloudformation/simulador.js +1045 -1045
  20. package/src/services/cloudtrail/index.js +84 -84
  21. package/src/services/cloudtrail/server.js +235 -235
  22. package/src/services/cloudtrail/simulador.js +719 -719
  23. package/src/services/cloudwatch/index.js +84 -84
  24. package/src/services/cloudwatch/server.js +366 -366
  25. package/src/services/cloudwatch/simulador.js +1173 -1173
  26. package/src/services/cognito/index.js +79 -70
  27. package/src/services/cognito/server.js +301 -279
  28. package/src/services/cognito/simulator.js +1655 -1119
  29. package/src/services/config/index.js +96 -96
  30. package/src/services/config/server.js +215 -215
  31. package/src/services/config/simulador.js +1260 -1260
  32. package/src/services/dynamodb/index.js +74 -74
  33. package/src/services/dynamodb/server.js +125 -123
  34. package/src/services/dynamodb/simulator.js +630 -630
  35. package/src/services/ecs/index.js +65 -65
  36. package/src/services/ecs/server.js +235 -233
  37. package/src/services/ecs/simulator.js +844 -844
  38. package/src/services/eventbridge/index.js +89 -89
  39. package/src/services/eventbridge/server.js +209 -209
  40. package/src/services/eventbridge/simulator.js +684 -684
  41. package/src/services/index.js +45 -45
  42. package/src/services/kms/index.js +75 -75
  43. package/src/services/kms/server.js +67 -67
  44. package/src/services/kms/simulator.js +324 -324
  45. package/src/services/lambda/handler-loader.js +183 -183
  46. package/src/services/lambda/index.js +78 -78
  47. package/src/services/lambda/route-registry.js +274 -274
  48. package/src/services/lambda/server.js +145 -145
  49. package/src/services/lambda/simulator.js +199 -182
  50. package/src/services/parameter-store/index.js +80 -80
  51. package/src/services/parameter-store/server.js +50 -50
  52. package/src/services/parameter-store/simulator.js +201 -201
  53. package/src/services/s3/index.js +73 -73
  54. package/src/services/s3/server.js +329 -245
  55. package/src/services/s3/simulator.js +565 -496
  56. package/src/services/secret-manager/index.js +80 -80
  57. package/src/services/secret-manager/server.js +50 -50
  58. package/src/services/secret-manager/simulator.js +171 -171
  59. package/src/services/sns/index.js +89 -89
  60. package/src/services/sns/server.js +580 -580
  61. package/src/services/sns/simulator.js +1482 -1482
  62. package/src/services/sqs/index.js +93 -93
  63. package/src/services/sqs/server.js +349 -347
  64. package/src/services/sqs/simulator.js +441 -441
  65. package/src/services/sts/index.js +37 -37
  66. package/src/services/sts/server.js +144 -142
  67. package/src/services/sts/simulator.js +69 -69
  68. package/src/services/xray/index.js +83 -83
  69. package/src/services/xray/server.js +308 -308
  70. package/src/services/xray/simulador.js +994 -994
  71. package/src/template/aws-config-template.js +87 -87
  72. package/src/template/aws-config-template.mjs +90 -90
  73. package/src/template/config-template.json +203 -203
  74. package/src/utils/aws-config.js +91 -91
  75. package/src/utils/cloudtrail-audit.js +129 -129
  76. package/src/utils/local-store.js +83 -83
  77. package/src/utils/logger.js +59 -59
@@ -1,129 +1,129 @@
1
- 'use strict';
2
-
3
- /**
4
- * CloudTrail Audit Helper
5
- *
6
- * Utilitário para registrar eventos de API nos simuladores.
7
- * Cada simulador recebe uma instância via injectDependencies.
8
- *
9
- * Uso:
10
- * this.audit = new CloudTrailAudit('s3.amazonaws.com');
11
- * // após injeção:
12
- * this.audit.setTrail(cloudtrailSimulator);
13
- * // ao executar operação:
14
- * this.audit.record({ eventName: 'PutObject', readOnly: false, ... });
15
- */
16
-
17
- class CloudTrailAudit {
18
- /**
19
- * @param {string} eventSource - ex: 's3.amazonaws.com'
20
- */
21
- constructor(eventSource) {
22
- this.eventSource = eventSource;
23
- this.trail = null;
24
- }
25
-
26
- /** @param {Object|null} cloudtrailSimulator */
27
- setTrail(cloudtrailSimulator) {
28
- this.trail = cloudtrailSimulator || null;
29
- }
30
-
31
- /**
32
- * Registra um evento se o CloudTrail estiver ativo e o tipo de evento
33
- * estiver habilitado nos event selectors do trail.
34
- *
35
- * @param {Object} params
36
- * @param {string} params.eventName
37
- * @param {boolean} [params.readOnly=false]
38
- * @param {Array} [params.resources=[]]
39
- * @param {Object} [params.requestParameters=null]
40
- * @param {Object} [params.responseElements=null]
41
- * @param {string} [params.username='local-user']
42
- * @param {string} [params.sourceIPAddress='127.0.0.1']
43
- */
44
- record(params = {}) {
45
- if (!this.trail) return;
46
-
47
- try {
48
- // Verifica se há algum trail com logging ativo
49
- const hasActiveTrail = this._hasActiveTrail();
50
- if (!hasActiveTrail) return;
51
-
52
- // Verifica se o evento deve ser gravado (management vs data event)
53
- if (!this._shouldRecord(params)) return;
54
-
55
- this.trail.recordEvent({
56
- eventSource: this.eventSource,
57
- eventName: params.eventName,
58
- readOnly: params.readOnly !== undefined ? params.readOnly : false,
59
- resources: params.resources || [],
60
- requestParameters: params.requestParameters || null,
61
- responseElements: params.responseElements || null,
62
- username: params.username || 'local-user',
63
- sourceIPAddress: params.sourceIPAddress || '127.0.0.1',
64
- });
65
- } catch (_) {
66
- // Nunca deixa o audit quebrar o fluxo principal
67
- }
68
- }
69
-
70
- _hasActiveTrail() {
71
- if (!this.trail || !this.trail.trailStatus) return false;
72
- for (const status of this.trail.trailStatus.values()) {
73
- if (status.isLogging) return true;
74
- }
75
- return false;
76
- }
77
-
78
- /**
79
- * Verifica event selectors para decidir se o evento deve ser gravado.
80
- * Management events são sempre gravados quando logging está ativo.
81
- * Data events só são gravados se houver um selector configurado para o recurso.
82
- */
83
- _shouldRecord(params) {
84
- if (!this.trail || !this.trail.eventSelectors) return true;
85
-
86
- const isDataEvent = params.isDataEvent === true;
87
-
88
- // Management events: gravados por padrão
89
- if (!isDataEvent) return true;
90
-
91
- // Data events: verifica se algum trail tem selector para este eventSource
92
- for (const [trailName, selectors] of this.trail.eventSelectors.entries()) {
93
- const status = this.trail.trailStatus.get(trailName);
94
- if (!status || !status.isLogging) continue;
95
-
96
- for (const selector of selectors) {
97
- const dataResources = selector.DataResources || [];
98
- for (const dr of dataResources) {
99
- if (this._matchesDataResource(dr)) return true;
100
- }
101
- }
102
- }
103
-
104
- return false;
105
- }
106
-
107
- _matchesDataResource(dataResource) {
108
- const typeMap = {
109
- 's3.amazonaws.com': 'AWS::S3::Object',
110
- 'dynamodb.amazonaws.com': 'AWS::DynamoDB::Table',
111
- 'kms.amazonaws.com': 'AWS::KMS::Key',
112
- 'secretsmanager.amazonaws.com': 'AWS::SecretsManager::Secret',
113
- 'ssm.amazonaws.com': 'AWS::SSM::Parameter',
114
- 'cognito-idp.amazonaws.com': 'AWS::Cognito::UserPool',
115
- 'execute-api.amazonaws.com': 'AWS::APIGateway::Stage',
116
- };
117
-
118
- const expectedType = typeMap[this.eventSource];
119
- if (!expectedType) return false;
120
-
121
- if (dataResource.Type !== expectedType) return false;
122
-
123
- // Values: wildcard ou ARN específico
124
- const values = dataResource.Values || [];
125
- return values.some((v) => v.endsWith('*') || v === expectedType);
126
- }
127
- }
128
-
129
- module.exports = { CloudTrailAudit };
1
+ 'use strict';
2
+
3
+ /**
4
+ * CloudTrail Audit Helper
5
+ *
6
+ * Utilitário para registrar eventos de API nos simuladores.
7
+ * Cada simulador recebe uma instância via injectDependencies.
8
+ *
9
+ * Uso:
10
+ * this.audit = new CloudTrailAudit('s3.amazonaws.com');
11
+ * // após injeção:
12
+ * this.audit.setTrail(cloudtrailSimulator);
13
+ * // ao executar operação:
14
+ * this.audit.record({ eventName: 'PutObject', readOnly: false, ... });
15
+ */
16
+
17
+ class CloudTrailAudit {
18
+ /**
19
+ * @param {string} eventSource - ex: 's3.amazonaws.com'
20
+ */
21
+ constructor(eventSource) {
22
+ this.eventSource = eventSource;
23
+ this.trail = null;
24
+ }
25
+
26
+ /** @param {Object|null} cloudtrailSimulator */
27
+ setTrail(cloudtrailSimulator) {
28
+ this.trail = cloudtrailSimulator || null;
29
+ }
30
+
31
+ /**
32
+ * Registra um evento se o CloudTrail estiver ativo e o tipo de evento
33
+ * estiver habilitado nos event selectors do trail.
34
+ *
35
+ * @param {Object} params
36
+ * @param {string} params.eventName
37
+ * @param {boolean} [params.readOnly=false]
38
+ * @param {Array} [params.resources=[]]
39
+ * @param {Object} [params.requestParameters=null]
40
+ * @param {Object} [params.responseElements=null]
41
+ * @param {string} [params.username='local-user']
42
+ * @param {string} [params.sourceIPAddress='127.0.0.1']
43
+ */
44
+ record(params = {}) {
45
+ if (!this.trail) return;
46
+
47
+ try {
48
+ // Verifica se há algum trail com logging ativo
49
+ const hasActiveTrail = this._hasActiveTrail();
50
+ if (!hasActiveTrail) return;
51
+
52
+ // Verifica se o evento deve ser gravado (management vs data event)
53
+ if (!this._shouldRecord(params)) return;
54
+
55
+ this.trail.recordEvent({
56
+ eventSource: this.eventSource,
57
+ eventName: params.eventName,
58
+ readOnly: params.readOnly !== undefined ? params.readOnly : false,
59
+ resources: params.resources || [],
60
+ requestParameters: params.requestParameters || null,
61
+ responseElements: params.responseElements || null,
62
+ username: params.username || 'local-user',
63
+ sourceIPAddress: params.sourceIPAddress || '127.0.0.1',
64
+ });
65
+ } catch (_) {
66
+ // Nunca deixa o audit quebrar o fluxo principal
67
+ }
68
+ }
69
+
70
+ _hasActiveTrail() {
71
+ if (!this.trail || !this.trail.trailStatus) return false;
72
+ for (const status of this.trail.trailStatus.values()) {
73
+ if (status.isLogging) return true;
74
+ }
75
+ return false;
76
+ }
77
+
78
+ /**
79
+ * Verifica event selectors para decidir se o evento deve ser gravado.
80
+ * Management events são sempre gravados quando logging está ativo.
81
+ * Data events só são gravados se houver um selector configurado para o recurso.
82
+ */
83
+ _shouldRecord(params) {
84
+ if (!this.trail || !this.trail.eventSelectors) return true;
85
+
86
+ const isDataEvent = params.isDataEvent === true;
87
+
88
+ // Management events: gravados por padrão
89
+ if (!isDataEvent) return true;
90
+
91
+ // Data events: verifica se algum trail tem selector para este eventSource
92
+ for (const [trailName, selectors] of this.trail.eventSelectors.entries()) {
93
+ const status = this.trail.trailStatus.get(trailName);
94
+ if (!status || !status.isLogging) continue;
95
+
96
+ for (const selector of selectors) {
97
+ const dataResources = selector.DataResources || [];
98
+ for (const dr of dataResources) {
99
+ if (this._matchesDataResource(dr)) return true;
100
+ }
101
+ }
102
+ }
103
+
104
+ return false;
105
+ }
106
+
107
+ _matchesDataResource(dataResource) {
108
+ const typeMap = {
109
+ 's3.amazonaws.com': 'AWS::S3::Object',
110
+ 'dynamodb.amazonaws.com': 'AWS::DynamoDB::Table',
111
+ 'kms.amazonaws.com': 'AWS::KMS::Key',
112
+ 'secretsmanager.amazonaws.com': 'AWS::SecretsManager::Secret',
113
+ 'ssm.amazonaws.com': 'AWS::SSM::Parameter',
114
+ 'cognito-idp.amazonaws.com': 'AWS::Cognito::UserPool',
115
+ 'execute-api.amazonaws.com': 'AWS::APIGateway::Stage',
116
+ };
117
+
118
+ const expectedType = typeMap[this.eventSource];
119
+ if (!expectedType) return false;
120
+
121
+ if (dataResource.Type !== expectedType) return false;
122
+
123
+ // Values: wildcard ou ARN específico
124
+ const values = dataResource.Values || [];
125
+ return values.some((v) => v.endsWith('*') || v === expectedType);
126
+ }
127
+ }
128
+
129
+ module.exports = { CloudTrailAudit };
@@ -1,84 +1,84 @@
1
- /**
2
- * Local Store - Persistência em arquivos JSON
3
- */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const mkdirp = require('mkdirp');
8
-
9
- class LocalStore {
10
- constructor(dataDir) {
11
- this.dataDir = dataDir;
12
- this.ensureDir();
13
- }
14
-
15
- ensureDir() {
16
- if (!fs.existsSync(this.dataDir)) {
17
- mkdirp.sync(this.dataDir);
18
- }
19
- }
20
-
21
- getFilePath(entity) {
22
- // Suporta subpaths como 'parameter-store/parameters'
23
- const parts = entity.split('/');
24
- const dir = parts.length > 1 ? path.join(this.dataDir, ...parts.slice(0, -1)) : this.dataDir;
25
- if (!fs.existsSync(dir)) mkdirp.sync(dir);
26
- return path.join(this.dataDir, `${entity}.json`);
27
- }
28
-
29
- read(entity) {
30
- const filePath = this.getFilePath(entity);
31
- if (!fs.existsSync(filePath)) return [];
32
-
33
- try {
34
- const content = fs.readFileSync(filePath, 'utf8');
35
- return JSON.parse(content);
36
- } catch (error) {
37
- console.error(`Erro ao ler ${entity}:`, error);
38
- return [];
39
- }
40
- }
41
-
42
- write(entity, data, _data2) {
43
- // Suporta chamada com 3 args: write(entity, null, data) usado por alguns simuladores
44
- const payload = (data === null || data === undefined) ? _data2 : data;
45
- const filePath = this.getFilePath(entity);
46
- try {
47
- fs.writeFileSync(filePath, JSON.stringify(payload, null, 2));
48
- } catch (error) {
49
- console.error(`Erro ao escrever ${entity}:`, error);
50
- throw error;
51
- }
52
- }
53
-
54
- delete(entity) {
55
- const filePath = this.getFilePath(entity);
56
- if (fs.existsSync(filePath)) {
57
- fs.unlinkSync(filePath);
58
- }
59
- }
60
-
61
- exists(entity) {
62
- const filePath = this.getFilePath(entity);
63
- return fs.existsSync(filePath);
64
- }
65
-
66
- list() {
67
- if (!fs.existsSync(this.dataDir)) return [];
68
- return fs.readdirSync(this.dataDir)
69
- .filter(f => f.endsWith('.json'))
70
- .map(f => f.replace('.json', ''));
71
- }
72
-
73
- // Aliases async para compatibilidade com simuladores que usam store.load/store.save
74
- async load(entity) {
75
- const data = this.read(entity);
76
- return Array.isArray(data) && data.length === 0 ? null : data;
77
- }
78
-
79
- async save(entity, data) {
80
- this.write(entity, data);
81
- }
82
- }
83
-
1
+ /**
2
+ * Local Store - Persistência em arquivos JSON
3
+ */
4
+
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const mkdirp = require('mkdirp');
8
+
9
+ class LocalStore {
10
+ constructor(dataDir) {
11
+ this.dataDir = dataDir;
12
+ this.ensureDir();
13
+ }
14
+
15
+ ensureDir() {
16
+ if (!fs.existsSync(this.dataDir)) {
17
+ mkdirp.sync(this.dataDir);
18
+ }
19
+ }
20
+
21
+ getFilePath(entity) {
22
+ // Suporta subpaths como 'parameter-store/parameters'
23
+ const parts = entity.split('/');
24
+ const dir = parts.length > 1 ? path.join(this.dataDir, ...parts.slice(0, -1)) : this.dataDir;
25
+ if (!fs.existsSync(dir)) mkdirp.sync(dir);
26
+ return path.join(this.dataDir, `${entity}.json`);
27
+ }
28
+
29
+ read(entity) {
30
+ const filePath = this.getFilePath(entity);
31
+ if (!fs.existsSync(filePath)) return [];
32
+
33
+ try {
34
+ const content = fs.readFileSync(filePath, 'utf8');
35
+ return JSON.parse(content);
36
+ } catch (error) {
37
+ console.error(`Erro ao ler ${entity}:`, error);
38
+ return [];
39
+ }
40
+ }
41
+
42
+ write(entity, data, _data2) {
43
+ // Suporta chamada com 3 args: write(entity, null, data) usado por alguns simuladores
44
+ const payload = (data === null || data === undefined) ? _data2 : data;
45
+ const filePath = this.getFilePath(entity);
46
+ try {
47
+ fs.writeFileSync(filePath, JSON.stringify(payload, null, 2));
48
+ } catch (error) {
49
+ console.error(`Erro ao escrever ${entity}:`, error);
50
+ throw error;
51
+ }
52
+ }
53
+
54
+ delete(entity) {
55
+ const filePath = this.getFilePath(entity);
56
+ if (fs.existsSync(filePath)) {
57
+ fs.unlinkSync(filePath);
58
+ }
59
+ }
60
+
61
+ exists(entity) {
62
+ const filePath = this.getFilePath(entity);
63
+ return fs.existsSync(filePath);
64
+ }
65
+
66
+ list() {
67
+ if (!fs.existsSync(this.dataDir)) return [];
68
+ return fs.readdirSync(this.dataDir)
69
+ .filter(f => f.endsWith('.json'))
70
+ .map(f => f.replace('.json', ''));
71
+ }
72
+
73
+ // Aliases async para compatibilidade com simuladores que usam store.load/store.save
74
+ async load(entity) {
75
+ const data = this.read(entity);
76
+ return Array.isArray(data) && data.length === 0 ? null : data;
77
+ }
78
+
79
+ async save(entity, data) {
80
+ this.write(entity, data);
81
+ }
82
+ }
83
+
84
84
  module.exports = LocalStore;
@@ -1,60 +1,60 @@
1
- /**
2
- * Logger configurável
3
- */
4
-
5
- let currentLogLevel = 'info';
6
-
7
- const LOG_LEVELS = {
8
- silent: 0,
9
- error: 1,
10
- warn: 2,
11
- info: 3,
12
- debug: 4,
13
- verboso: 5
14
- };
15
-
16
- class Logger {
17
- static setLevel(level) {
18
- if (LOG_LEVELS[level] !== undefined) {
19
- currentLogLevel = level;
20
- }
21
- }
22
-
23
- static error(...args) {
24
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.error) {
25
- console.error('\x1b[31m%s\x1b[0m', '❌', ...args);
26
- }
27
- }
28
-
29
- static warn(...args) {
30
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.warn) {
31
- console.warn('\x1b[33m%s\x1b[0m', '⚠️', ...args);
32
- }
33
- }
34
-
35
- static info(...args) {
36
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
37
- console.log('\x1b[36m%s\x1b[0m', 'ℹ️', ...args);
38
- }
39
- }
40
-
41
- static debug(...args) {
42
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.debug) {
43
- console.debug('\x1b[90m%s\x1b[0m', '🔍', ...args);
44
- }
45
- }
46
-
47
- static verboso(...args) {
48
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.verboso) {
49
- console.log('\x1b[35m%s\x1b[0m', '📝', ...args);
50
- }
51
- }
52
-
53
- static success(...args) {
54
- if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
55
- console.log('\x1b[32m%s\x1b[0m', '✅', ...args);
56
- }
57
- }
58
- }
59
-
1
+ /**
2
+ * Logger configurável
3
+ */
4
+
5
+ let currentLogLevel = 'info';
6
+
7
+ const LOG_LEVELS = {
8
+ silent: 0,
9
+ error: 1,
10
+ warn: 2,
11
+ info: 3,
12
+ debug: 4,
13
+ verboso: 5
14
+ };
15
+
16
+ class Logger {
17
+ static setLevel(level) {
18
+ if (LOG_LEVELS[level] !== undefined) {
19
+ currentLogLevel = level;
20
+ }
21
+ }
22
+
23
+ static error(...args) {
24
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.error) {
25
+ console.error('\x1b[31m%s\x1b[0m', '❌', ...args);
26
+ }
27
+ }
28
+
29
+ static warn(...args) {
30
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.warn) {
31
+ console.warn('\x1b[33m%s\x1b[0m', '⚠️', ...args);
32
+ }
33
+ }
34
+
35
+ static info(...args) {
36
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
37
+ console.log('\x1b[36m%s\x1b[0m', 'ℹ️', ...args);
38
+ }
39
+ }
40
+
41
+ static debug(...args) {
42
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.debug) {
43
+ console.debug('\x1b[90m%s\x1b[0m', '🔍', ...args);
44
+ }
45
+ }
46
+
47
+ static verboso(...args) {
48
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.verboso) {
49
+ console.log('\x1b[35m%s\x1b[0m', '📝', ...args);
50
+ }
51
+ }
52
+
53
+ static success(...args) {
54
+ if (LOG_LEVELS[currentLogLevel] >= LOG_LEVELS.info) {
55
+ console.log('\x1b[32m%s\x1b[0m', '✅', ...args);
56
+ }
57
+ }
58
+ }
59
+
60
60
  module.exports = Logger;