@gugananuvem/aws-local-simulator 1.0.12 → 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 -257
  2. package/bin/aws-local-simulator.js +63 -63
  3. package/package.json +21 -10
  4. package/src/config/config-loader.js +114 -114
  5. package/src/config/default-config.js +68 -67
  6. package/src/config/env-loader.js +68 -68
  7. package/src/index.js +146 -130
  8. package/src/index.mjs +123 -123
  9. package/src/server.js +227 -223
  10. package/src/services/apigateway/index.js +73 -68
  11. package/src/services/apigateway/server.js +507 -487
  12. package/src/services/apigateway/simulator.js +1261 -1251
  13. package/src/services/athena/index.js +75 -0
  14. package/src/services/athena/server.js +101 -0
  15. package/src/services/athena/simulador.js +998 -0
  16. package/src/services/athena/simulator.js +346 -0
  17. package/src/services/cloudformation/index.js +106 -0
  18. package/src/services/cloudformation/server.js +417 -0
  19. package/src/services/cloudformation/simulador.js +1045 -0
  20. package/src/services/cloudtrail/index.js +84 -0
  21. package/src/services/cloudtrail/server.js +235 -0
  22. package/src/services/cloudtrail/simulador.js +719 -0
  23. package/src/services/cloudwatch/index.js +84 -0
  24. package/src/services/cloudwatch/server.js +366 -0
  25. package/src/services/cloudwatch/simulador.js +1173 -0
  26. package/src/services/cognito/index.js +79 -65
  27. package/src/services/cognito/server.js +301 -279
  28. package/src/services/cognito/simulator.js +1655 -1115
  29. package/src/services/config/index.js +96 -0
  30. package/src/services/config/server.js +215 -0
  31. package/src/services/config/simulador.js +1260 -0
  32. package/src/services/dynamodb/index.js +74 -70
  33. package/src/services/dynamodb/server.js +125 -121
  34. package/src/services/dynamodb/simulator.js +630 -620
  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 -85
  39. package/src/services/eventbridge/server.js +209 -0
  40. package/src/services/eventbridge/simulator.js +684 -0
  41. package/src/services/index.js +45 -19
  42. package/src/services/kms/index.js +75 -0
  43. package/src/services/kms/server.js +67 -0
  44. package/src/services/kms/simulator.js +324 -0
  45. package/src/services/lambda/handler-loader.js +183 -183
  46. package/src/services/lambda/index.js +78 -73
  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 -172
  50. package/src/services/parameter-store/index.js +80 -0
  51. package/src/services/parameter-store/server.js +50 -0
  52. package/src/services/parameter-store/simulator.js +201 -0
  53. package/src/services/s3/index.js +73 -69
  54. package/src/services/s3/server.js +329 -238
  55. package/src/services/s3/simulator.js +565 -740
  56. package/src/services/secret-manager/index.js +80 -0
  57. package/src/services/secret-manager/server.js +50 -0
  58. package/src/services/secret-manager/simulator.js +171 -0
  59. package/src/services/sns/index.js +89 -76
  60. package/src/services/sns/server.js +580 -0
  61. package/src/services/sns/simulator.js +1482 -0
  62. package/src/services/sqs/index.js +93 -95
  63. package/src/services/sqs/server.js +349 -345
  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 -0
  69. package/src/services/xray/server.js +308 -0
  70. package/src/services/xray/simulador.js +994 -0
  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 -0
  76. package/src/utils/local-store.js +83 -67
  77. package/src/utils/logger.js +59 -59
@@ -1,37 +1,37 @@
1
- const STSServer = require('./server');
2
- const logger = require('../../utils/logger');
3
-
4
- class STSService {
5
- constructor(config) {
6
- this.config = config;
7
- this.name = 'sts';
8
- this.port = config.ports.sts || 9326;
9
- this.server = null;
10
- this.isRunning = false;
11
- }
12
-
13
- async initialize() {
14
- this.server = new STSServer(this.port, this.config);
15
- await this.server.initialize();
16
- }
17
-
18
- async start() {
19
- if (this.isRunning) return;
20
- await this.server.start();
21
- this.isRunning = true;
22
- }
23
-
24
- async stop() {
25
- if (!this.isRunning) return;
26
- await this.server.stop();
27
- this.isRunning = false;
28
- }
29
-
30
- async reset() {}
31
-
32
- getStatus() {
33
- return { running: this.isRunning, port: this.port, endpoint: `http://localhost:${this.port}` };
34
- }
35
- }
36
-
37
- module.exports = STSService;
1
+ const STSServer = require('./server');
2
+ const logger = require('../../utils/logger');
3
+
4
+ class STSService {
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.name = 'sts';
8
+ this.port = config.ports.sts || 9326;
9
+ this.server = null;
10
+ this.isRunning = false;
11
+ }
12
+
13
+ async initialize() {
14
+ this.server = new STSServer(this.port, this.config);
15
+ await this.server.initialize();
16
+ }
17
+
18
+ async start() {
19
+ if (this.isRunning) return;
20
+ await this.server.start();
21
+ this.isRunning = true;
22
+ }
23
+
24
+ async stop() {
25
+ if (!this.isRunning) return;
26
+ await this.server.stop();
27
+ this.isRunning = false;
28
+ }
29
+
30
+ async reset() {}
31
+
32
+ getStatus() {
33
+ return { running: this.isRunning, port: this.port, endpoint: `http://localhost:${this.port}` };
34
+ }
35
+ }
36
+
37
+ module.exports = STSService;
@@ -1,142 +1,144 @@
1
- const express = require('express');
2
- const crypto = require('crypto');
3
- const STSSimulator = require('./simulator');
4
- const logger = require('../../utils/logger');
5
-
6
- class STSServer {
7
- constructor(port, config) {
8
- this.port = port;
9
- this.config = config;
10
- this.app = express();
11
- this.simulator = new STSSimulator(config);
12
- this.server = null;
13
- this.setupMiddlewares();
14
- }
15
-
16
- setupMiddlewares() {
17
- this.app.use(express.raw({ type: '*/*', limit: '10mb' }));
18
- this.app.use((req, res, next) => {
19
- if (req.body && Buffer.isBuffer(req.body)) {
20
- const str = req.body.toString('utf8');
21
- const ct = req.headers['content-type'] || '';
22
- if (ct.includes('application/x-www-form-urlencoded')) {
23
- req.body = Object.fromEntries(new URLSearchParams(str));
24
- } else {
25
- try { req.body = JSON.parse(str); } catch (e) { req.body = {}; }
26
- }
27
- } else { req.body = req.body || {}; }
28
- next();
29
- });
30
- }
31
-
32
- async initialize() {
33
- await this.simulator.initialize();
34
- this.setupRoutes();
35
- logger.debug('STS Server inicializado');
36
- }
37
-
38
- setupRoutes() {
39
- this.app.post('/', (req, res) => {
40
- // STS uses query protocol: Action in body or query string
41
- const action = req.query.Action || req.body.Action ||
42
- (req.headers['x-amz-target'] && req.headers['x-amz-target'].split('.')[1]);
43
-
44
- logger.debug(`STS action: ${action}`);
45
-
46
- try {
47
- const result = this.handleAction(action, req.body);
48
- const xml = this.generateXmlResponse(action, result);
49
- res.set('Content-Type', 'text/xml');
50
- res.send(xml);
51
- } catch (err) {
52
- logger.error('STS Error:', err.message);
53
- res.status(400).send(this.simulator.generateErrorResponse('InvalidAction', err.message));
54
- }
55
- });
56
- }
57
-
58
- handleAction(action, params) {
59
- switch (action) {
60
- case 'AssumeRole': return this.simulator.assumeRole(params);
61
- case 'GetCallerIdentity': return this.simulator.getCallerIdentity(params);
62
- case 'GetSessionToken': return this.simulator.getSessionToken(params);
63
- case 'AssumeRoleWithWebIdentity': return this.simulator.assumeRoleWithWebIdentity(params);
64
- case 'AssumeRoleWithSAML': return this.simulator.assumeRoleWithSAML(params);
65
- default: throw new Error(`Unsupported STS action: ${action}`);
66
- }
67
- }
68
-
69
- generateXmlResponse(action, result) {
70
- const requestId = crypto.randomUUID();
71
- switch (action) {
72
- case 'AssumeRole':
73
- case 'AssumeRoleWithWebIdentity':
74
- case 'AssumeRoleWithSAML':
75
- return `<?xml version="1.0" encoding="UTF-8"?>
76
- <${action}Response xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
77
- <${action}Result>
78
- <Credentials>
79
- <AccessKeyId>${result.Credentials.AccessKeyId}</AccessKeyId>
80
- <SecretAccessKey>${result.Credentials.SecretAccessKey}</SecretAccessKey>
81
- <SessionToken>${result.Credentials.SessionToken}</SessionToken>
82
- <Expiration>${result.Credentials.Expiration}</Expiration>
83
- </Credentials>
84
- <AssumedRoleUser>
85
- <AssumedRoleId>${result.AssumedRoleUser.AssumedRoleId}</AssumedRoleId>
86
- <Arn>${result.AssumedRoleUser.Arn}</Arn>
87
- </AssumedRoleUser>
88
- </${action}Result>
89
- <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
90
- </${action}Response>`;
91
-
92
- case 'GetCallerIdentity':
93
- return `<?xml version="1.0" encoding="UTF-8"?>
94
- <GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
95
- <GetCallerIdentityResult>
96
- <UserId>${result.UserId}</UserId>
97
- <Account>${result.Account}</Account>
98
- <Arn>${result.Arn}</Arn>
99
- </GetCallerIdentityResult>
100
- <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
101
- </GetCallerIdentityResponse>`;
102
-
103
- case 'GetSessionToken':
104
- return `<?xml version="1.0" encoding="UTF-8"?>
105
- <GetSessionTokenResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
106
- <GetSessionTokenResult>
107
- <Credentials>
108
- <AccessKeyId>${result.Credentials.AccessKeyId}</AccessKeyId>
109
- <SecretAccessKey>${result.Credentials.SecretAccessKey}</SecretAccessKey>
110
- <SessionToken>${result.Credentials.SessionToken}</SessionToken>
111
- <Expiration>${result.Credentials.Expiration}</Expiration>
112
- </Credentials>
113
- </GetSessionTokenResult>
114
- <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
115
- </GetSessionTokenResponse>`;
116
-
117
- default: return '';
118
- }
119
- }
120
-
121
- start() {
122
- return new Promise((resolve) => {
123
- this.server = this.app.listen(this.port, () => {
124
- logger.info(`🔑 STS rodando em http://localhost:${this.port}`);
125
- resolve();
126
- });
127
- });
128
- }
129
-
130
- stop() {
131
- return new Promise((resolve) => {
132
- if (this.server) this.server.close(() => resolve());
133
- else resolve();
134
- });
135
- }
136
-
137
- getStatus() {
138
- return { running: !!this.server, port: this.port, endpoint: `http://localhost:${this.port}` };
139
- }
140
- }
141
-
142
- module.exports = STSServer;
1
+ const express = require('express');
2
+ const cors = require('cors');
3
+ const crypto = require('crypto');
4
+ const STSSimulator = require('./simulator');
5
+ const logger = require('../../utils/logger');
6
+
7
+ class STSServer {
8
+ constructor(port, config) {
9
+ this.port = port;
10
+ this.config = config;
11
+ this.app = express();
12
+ this.simulator = new STSSimulator(config);
13
+ this.server = null;
14
+ this.setupMiddlewares();
15
+ }
16
+
17
+ setupMiddlewares() {
18
+ this.app.use(cors());
19
+ this.app.use(express.raw({ type: '*/*', limit: '10mb' }));
20
+ this.app.use((req, res, next) => {
21
+ if (req.body && Buffer.isBuffer(req.body)) {
22
+ const str = req.body.toString('utf8');
23
+ const ct = req.headers['content-type'] || '';
24
+ if (ct.includes('application/x-www-form-urlencoded')) {
25
+ req.body = Object.fromEntries(new URLSearchParams(str));
26
+ } else {
27
+ try { req.body = JSON.parse(str); } catch (e) { req.body = {}; }
28
+ }
29
+ } else { req.body = req.body || {}; }
30
+ next();
31
+ });
32
+ }
33
+
34
+ async initialize() {
35
+ await this.simulator.initialize();
36
+ this.setupRoutes();
37
+ logger.debug('STS Server inicializado');
38
+ }
39
+
40
+ setupRoutes() {
41
+ this.app.post('/', (req, res) => {
42
+ // STS uses query protocol: Action in body or query string
43
+ const action = req.query.Action || req.body.Action ||
44
+ (req.headers['x-amz-target'] && req.headers['x-amz-target'].split('.')[1]);
45
+
46
+ logger.debug(`STS action: ${action}`);
47
+
48
+ try {
49
+ const result = this.handleAction(action, req.body);
50
+ const xml = this.generateXmlResponse(action, result);
51
+ res.set('Content-Type', 'text/xml');
52
+ res.send(xml);
53
+ } catch (err) {
54
+ logger.error('STS Error:', err.message);
55
+ res.status(400).send(this.simulator.generateErrorResponse('InvalidAction', err.message));
56
+ }
57
+ });
58
+ }
59
+
60
+ handleAction(action, params) {
61
+ switch (action) {
62
+ case 'AssumeRole': return this.simulator.assumeRole(params);
63
+ case 'GetCallerIdentity': return this.simulator.getCallerIdentity(params);
64
+ case 'GetSessionToken': return this.simulator.getSessionToken(params);
65
+ case 'AssumeRoleWithWebIdentity': return this.simulator.assumeRoleWithWebIdentity(params);
66
+ case 'AssumeRoleWithSAML': return this.simulator.assumeRoleWithSAML(params);
67
+ default: throw new Error(`Unsupported STS action: ${action}`);
68
+ }
69
+ }
70
+
71
+ generateXmlResponse(action, result) {
72
+ const requestId = crypto.randomUUID();
73
+ switch (action) {
74
+ case 'AssumeRole':
75
+ case 'AssumeRoleWithWebIdentity':
76
+ case 'AssumeRoleWithSAML':
77
+ return `<?xml version="1.0" encoding="UTF-8"?>
78
+ <${action}Response xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
79
+ <${action}Result>
80
+ <Credentials>
81
+ <AccessKeyId>${result.Credentials.AccessKeyId}</AccessKeyId>
82
+ <SecretAccessKey>${result.Credentials.SecretAccessKey}</SecretAccessKey>
83
+ <SessionToken>${result.Credentials.SessionToken}</SessionToken>
84
+ <Expiration>${result.Credentials.Expiration}</Expiration>
85
+ </Credentials>
86
+ <AssumedRoleUser>
87
+ <AssumedRoleId>${result.AssumedRoleUser.AssumedRoleId}</AssumedRoleId>
88
+ <Arn>${result.AssumedRoleUser.Arn}</Arn>
89
+ </AssumedRoleUser>
90
+ </${action}Result>
91
+ <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
92
+ </${action}Response>`;
93
+
94
+ case 'GetCallerIdentity':
95
+ return `<?xml version="1.0" encoding="UTF-8"?>
96
+ <GetCallerIdentityResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
97
+ <GetCallerIdentityResult>
98
+ <UserId>${result.UserId}</UserId>
99
+ <Account>${result.Account}</Account>
100
+ <Arn>${result.Arn}</Arn>
101
+ </GetCallerIdentityResult>
102
+ <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
103
+ </GetCallerIdentityResponse>`;
104
+
105
+ case 'GetSessionToken':
106
+ return `<?xml version="1.0" encoding="UTF-8"?>
107
+ <GetSessionTokenResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
108
+ <GetSessionTokenResult>
109
+ <Credentials>
110
+ <AccessKeyId>${result.Credentials.AccessKeyId}</AccessKeyId>
111
+ <SecretAccessKey>${result.Credentials.SecretAccessKey}</SecretAccessKey>
112
+ <SessionToken>${result.Credentials.SessionToken}</SessionToken>
113
+ <Expiration>${result.Credentials.Expiration}</Expiration>
114
+ </Credentials>
115
+ </GetSessionTokenResult>
116
+ <ResponseMetadata><RequestId>${requestId}</RequestId></ResponseMetadata>
117
+ </GetSessionTokenResponse>`;
118
+
119
+ default: return '';
120
+ }
121
+ }
122
+
123
+ start() {
124
+ return new Promise((resolve) => {
125
+ this.server = this.app.listen(this.port, () => {
126
+ logger.info(`🔑 STS rodando em http://localhost:${this.port}`);
127
+ resolve();
128
+ });
129
+ });
130
+ }
131
+
132
+ stop() {
133
+ return new Promise((resolve) => {
134
+ if (this.server) this.server.close(() => resolve());
135
+ else resolve();
136
+ });
137
+ }
138
+
139
+ getStatus() {
140
+ return { running: !!this.server, port: this.port, endpoint: `http://localhost:${this.port}` };
141
+ }
142
+ }
143
+
144
+ module.exports = STSServer;
@@ -1,69 +1,69 @@
1
- const crypto = require('crypto');
2
- const logger = require('../../utils/logger');
3
-
4
- class STSSimulator {
5
- constructor(config) {
6
- this.config = config;
7
- this.assumedRoles = new Map();
8
- }
9
-
10
- async initialize() {
11
- logger.debug('Inicializando STS Simulator...');
12
- }
13
-
14
- assumeRole(params = {}) {
15
- const { RoleArn, RoleSessionName, DurationSeconds = 3600 } = params;
16
- if (!RoleArn) throw new Error('RoleArn is required');
17
- if (!RoleSessionName) throw new Error('RoleSessionName is required');
18
-
19
- const accessKeyId = `ASIA${crypto.randomBytes(8).toString('hex').toUpperCase()}`;
20
- const secretKey = crypto.randomBytes(20).toString('hex');
21
- const sessionToken = crypto.randomBytes(64).toString('base64');
22
- const expiration = new Date(Date.now() + DurationSeconds * 1000).toISOString();
23
- const assumedRoleId = `AROA${crypto.randomBytes(8).toString('hex').toUpperCase()}:${RoleSessionName}`;
24
-
25
- return {
26
- Credentials: { AccessKeyId: accessKeyId, SecretAccessKey: secretKey, SessionToken: sessionToken, Expiration: expiration },
27
- AssumedRoleUser: { AssumedRoleId: assumedRoleId, Arn: `${RoleArn}/${RoleSessionName}` },
28
- PackedPolicySize: null
29
- };
30
- }
31
-
32
- getCallerIdentity(params = {}) {
33
- return {
34
- UserId: 'AKIAIOSFODNN7EXAMPLE',
35
- Account: '123456789012',
36
- Arn: 'arn:aws:iam::123456789012:user/local-simulator'
37
- };
38
- }
39
-
40
- getSessionToken(params = {}) {
41
- const { DurationSeconds = 3600 } = params;
42
- return {
43
- Credentials: {
44
- AccessKeyId: `ASIA${crypto.randomBytes(8).toString('hex').toUpperCase()}`,
45
- SecretAccessKey: crypto.randomBytes(20).toString('hex'),
46
- SessionToken: crypto.randomBytes(64).toString('base64'),
47
- Expiration: new Date(Date.now() + DurationSeconds * 1000).toISOString()
48
- }
49
- };
50
- }
51
-
52
- assumeRoleWithWebIdentity(params = {}) {
53
- return this.assumeRole({ ...params, RoleSessionName: params.RoleSessionName || 'web-identity-session' });
54
- }
55
-
56
- assumeRoleWithSAML(params = {}) {
57
- return this.assumeRole({ ...params, RoleSessionName: params.RoleSessionName || 'saml-session' });
58
- }
59
-
60
- generateErrorResponse(code, message) {
61
- return `<?xml version="1.0" encoding="UTF-8"?>
62
- <ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
63
- <Error><Code>${code}</Code><Message>${message}</Message></Error>
64
- <RequestId>${crypto.randomUUID()}</RequestId>
65
- </ErrorResponse>`;
66
- }
67
- }
68
-
69
- module.exports = STSSimulator;
1
+ const crypto = require('crypto');
2
+ const logger = require('../../utils/logger');
3
+
4
+ class STSSimulator {
5
+ constructor(config) {
6
+ this.config = config;
7
+ this.assumedRoles = new Map();
8
+ }
9
+
10
+ async initialize() {
11
+ logger.debug('Inicializando STS Simulator...');
12
+ }
13
+
14
+ assumeRole(params = {}) {
15
+ const { RoleArn, RoleSessionName, DurationSeconds = 3600 } = params;
16
+ if (!RoleArn) throw new Error('RoleArn is required');
17
+ if (!RoleSessionName) throw new Error('RoleSessionName is required');
18
+
19
+ const accessKeyId = `ASIA${crypto.randomBytes(8).toString('hex').toUpperCase()}`;
20
+ const secretKey = crypto.randomBytes(20).toString('hex');
21
+ const sessionToken = crypto.randomBytes(64).toString('base64');
22
+ const expiration = new Date(Date.now() + DurationSeconds * 1000).toISOString();
23
+ const assumedRoleId = `AROA${crypto.randomBytes(8).toString('hex').toUpperCase()}:${RoleSessionName}`;
24
+
25
+ return {
26
+ Credentials: { AccessKeyId: accessKeyId, SecretAccessKey: secretKey, SessionToken: sessionToken, Expiration: expiration },
27
+ AssumedRoleUser: { AssumedRoleId: assumedRoleId, Arn: `${RoleArn}/${RoleSessionName}` },
28
+ PackedPolicySize: null
29
+ };
30
+ }
31
+
32
+ getCallerIdentity(params = {}) {
33
+ return {
34
+ UserId: 'AKIAIOSFODNN7EXAMPLE',
35
+ Account: '123456789012',
36
+ Arn: 'arn:aws:iam::123456789012:user/local-simulator'
37
+ };
38
+ }
39
+
40
+ getSessionToken(params = {}) {
41
+ const { DurationSeconds = 3600 } = params;
42
+ return {
43
+ Credentials: {
44
+ AccessKeyId: `ASIA${crypto.randomBytes(8).toString('hex').toUpperCase()}`,
45
+ SecretAccessKey: crypto.randomBytes(20).toString('hex'),
46
+ SessionToken: crypto.randomBytes(64).toString('base64'),
47
+ Expiration: new Date(Date.now() + DurationSeconds * 1000).toISOString()
48
+ }
49
+ };
50
+ }
51
+
52
+ assumeRoleWithWebIdentity(params = {}) {
53
+ return this.assumeRole({ ...params, RoleSessionName: params.RoleSessionName || 'web-identity-session' });
54
+ }
55
+
56
+ assumeRoleWithSAML(params = {}) {
57
+ return this.assumeRole({ ...params, RoleSessionName: params.RoleSessionName || 'saml-session' });
58
+ }
59
+
60
+ generateErrorResponse(code, message) {
61
+ return `<?xml version="1.0" encoding="UTF-8"?>
62
+ <ErrorResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
63
+ <Error><Code>${code}</Code><Message>${message}</Message></Error>
64
+ <RequestId>${crypto.randomUUID()}</RequestId>
65
+ </ErrorResponse>`;
66
+ }
67
+ }
68
+
69
+ module.exports = STSSimulator;
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @fileoverview X-Ray Service
5
+ * Porta padrão: 4015
6
+ */
7
+
8
+ const path = require('path');
9
+ const { XRaySimulator } = require('./simulador');
10
+ const { createXRayServer } = require('./server');
11
+ const LocalStore = require('../../utils/local-store');
12
+
13
+ class XRayService {
14
+ constructor(config) {
15
+ this.config = config;
16
+ this.logger = require('../../utils/logger');
17
+ this.name = 'xray';
18
+ this.port = config?.ports?.xray || config?.services?.xray?.port || 4015;
19
+ this.store = null;
20
+ this.simulator = null;
21
+ this._server = null;
22
+ this.isRunning = false;
23
+ }
24
+
25
+ async initialize() {
26
+ this.logger.debug(`Inicializando X-Ray Service na porta ${this.port}...`);
27
+ const dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA_DIR;
28
+ this.store = new LocalStore(path.join(dataDir, 'xray'));
29
+ this.simulator = new XRaySimulator(this.config, this.store, this.logger);
30
+ await this.simulator.load();
31
+ this.logger.debug('X-Ray Service inicializado');
32
+ }
33
+
34
+ injectDependencies(server) {
35
+ if (!server) return;
36
+ const cw = server.getService('cloudwatch');
37
+ if (cw?.simulator) this.simulator.cloudwatchSimulator = cw.simulator;
38
+ const ct = server.getService('cloudtrail');
39
+ if (ct?.simulator) this.simulator.cloudtrailSimulator = ct.simulator;
40
+ }
41
+
42
+ async start() {
43
+ if (this.isRunning) return;
44
+ const httpServer = createXRayServer(this.simulator);
45
+ return new Promise((resolve, reject) => {
46
+ httpServer.listen(this.port, () => {
47
+ this._server = httpServer;
48
+ this.isRunning = true;
49
+ this.logger.debug(`X-Ray rodando na porta ${this.port}`);
50
+ resolve();
51
+ });
52
+ httpServer.on('error', reject);
53
+ });
54
+ }
55
+
56
+ async stop() {
57
+ if (!this.isRunning || !this._server) return;
58
+ return new Promise((resolve, reject) => {
59
+ this._server.close((err) => {
60
+ if (err) return reject(err);
61
+ this.isRunning = false;
62
+ resolve();
63
+ });
64
+ });
65
+ }
66
+
67
+ async reset() {
68
+ await this.simulator.reset();
69
+ }
70
+
71
+ getStatus() {
72
+ return {
73
+ running: this.isRunning,
74
+ port: this.port,
75
+ endpoint: `http://localhost:${this.port}`,
76
+ ...this.simulator?.getStatus(),
77
+ };
78
+ }
79
+
80
+ getSimulator() { return this.simulator; }
81
+ }
82
+
83
+ module.exports = { XRayService };