@gugananuvem/aws-local-simulator 1.0.15 → 1.0.16
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.
- package/README.md +789 -594
- package/bin/aws-local-simulator.js +63 -63
- package/package.json +2 -2
- package/src/config/config-loader.js +114 -114
- package/src/config/default-config.js +68 -68
- package/src/config/env-loader.js +68 -68
- package/src/index.js +146 -146
- package/src/index.mjs +123 -123
- package/src/server.js +227 -227
- package/src/services/apigateway/index.js +75 -73
- package/src/services/apigateway/server.js +570 -507
- package/src/services/apigateway/simulator.js +1261 -1261
- package/src/services/athena/index.js +75 -75
- package/src/services/athena/server.js +101 -101
- package/src/services/athena/simulador.js +998 -998
- package/src/services/athena/simulator.js +346 -346
- package/src/services/cloudformation/index.js +106 -106
- package/src/services/cloudformation/server.js +417 -417
- package/src/services/cloudformation/simulador.js +1045 -1045
- package/src/services/cloudtrail/index.js +84 -84
- package/src/services/cloudtrail/server.js +235 -235
- package/src/services/cloudtrail/simulador.js +719 -719
- package/src/services/cloudwatch/index.js +84 -84
- package/src/services/cloudwatch/server.js +366 -366
- package/src/services/cloudwatch/simulador.js +1173 -1173
- package/src/services/cognito/index.js +79 -79
- package/src/services/cognito/server.js +301 -301
- package/src/services/cognito/simulator.js +1655 -1655
- package/src/services/config/index.js +96 -96
- package/src/services/config/server.js +215 -215
- package/src/services/config/simulador.js +1260 -1260
- package/src/services/dynamodb/index.js +74 -74
- package/src/services/dynamodb/server.js +125 -125
- package/src/services/dynamodb/simulator.js +630 -630
- package/src/services/ecs/index.js +65 -65
- package/src/services/ecs/server.js +235 -235
- package/src/services/ecs/simulator.js +844 -844
- package/src/services/eventbridge/index.js +89 -89
- package/src/services/eventbridge/server.js +209 -209
- package/src/services/eventbridge/simulator.js +684 -684
- package/src/services/index.js +45 -45
- package/src/services/kms/index.js +75 -75
- package/src/services/kms/server.js +67 -67
- package/src/services/kms/simulator.js +324 -324
- package/src/services/lambda/handler-loader.js +183 -183
- package/src/services/lambda/index.js +78 -78
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +145 -145
- package/src/services/lambda/simulator.js +199 -199
- package/src/services/parameter-store/index.js +80 -80
- package/src/services/parameter-store/server.js +50 -50
- package/src/services/parameter-store/simulator.js +201 -201
- package/src/services/s3/index.js +73 -73
- package/src/services/s3/server.js +329 -329
- package/src/services/s3/simulator.js +565 -565
- package/src/services/secret-manager/index.js +80 -80
- package/src/services/secret-manager/server.js +50 -50
- package/src/services/secret-manager/simulator.js +171 -171
- package/src/services/sns/index.js +89 -89
- package/src/services/sns/server.js +580 -580
- package/src/services/sns/simulator.js +1482 -1482
- package/src/services/sqs/index.js +98 -93
- package/src/services/sqs/server.js +349 -349
- package/src/services/sqs/simulator.js +441 -441
- package/src/services/sts/index.js +37 -37
- package/src/services/sts/server.js +144 -144
- package/src/services/sts/simulator.js +69 -69
- package/src/services/xray/index.js +83 -83
- package/src/services/xray/server.js +308 -308
- package/src/services/xray/simulador.js +994 -994
- package/src/template/aws-config-template.js +87 -87
- package/src/template/aws-config-template.mjs +90 -90
- package/src/template/config-template.json +203 -203
- package/src/utils/aws-config.js +91 -91
- package/src/utils/cloudtrail-audit.js +129 -129
- package/src/utils/local-store.js +83 -83
- 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,144 +1,144 @@
|
|
|
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
|
+
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;
|
|
@@ -1,83 +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 };
|
|
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 };
|