@gugananuvem/aws-local-simulator 1.0.8 → 1.0.10
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 +2 -1
- package/bin/aws-local-simulator.js +62 -1
- package/package.json +10 -7
- package/src/config/config-loader.js +113 -0
- package/src/config/default-config.js +65 -0
- package/src/config/env-loader.js +69 -0
- package/src/index.js +131 -1
- package/src/index.mjs +124 -0
- package/src/server.js +222 -0
- package/src/services/apigateway/index.js +67 -0
- package/src/services/apigateway/server.js +435 -0
- package/src/services/apigateway/simulator.js +1252 -0
- package/src/services/cognito/index.js +66 -0
- package/src/services/cognito/server.js +229 -0
- package/src/services/cognito/simulator.js +848 -0
- package/src/services/dynamodb/index.js +71 -0
- package/src/services/dynamodb/server.js +122 -0
- package/src/services/dynamodb/simulator.js +614 -0
- package/src/services/ecs/index.js +66 -0
- package/src/services/ecs/server.js +234 -0
- package/src/services/ecs/simulator.js +845 -0
- package/src/services/eventbridge/index.js +85 -0
- package/src/services/index.js +19 -0
- package/src/services/lambda/handler-loader.js +173 -0
- package/src/services/lambda/index.js +73 -0
- package/src/services/lambda/route-registry.js +275 -0
- package/src/services/lambda/server.js +153 -0
- package/src/services/lambda/simulator.js +285 -0
- package/src/services/s3/index.js +70 -0
- package/src/services/s3/server.js +239 -0
- package/src/services/s3/simulator.js +740 -0
- package/src/services/sns/index.js +76 -0
- package/src/services/sqs/index.js +96 -0
- package/src/services/sqs/server.js +274 -0
- package/src/services/sqs/simulator.js +660 -0
- package/src/template/aws-config-template.js +88 -0
- package/src/template/aws-config-template.mjs +91 -0
- package/src/template/config-template.json +203 -0
- package/src/utils/aws-config.js +92 -0
- package/src/utils/local-store.js +68 -0
- package/src/utils/logger.js +60 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lambda Server - Servidor HTTP para Lambda (API Gateway style)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const express = require('express');
|
|
6
|
+
const cors = require('cors');
|
|
7
|
+
const LambdaSimulator = require('./simulator');
|
|
8
|
+
const logger = require('../../utils/logger');
|
|
9
|
+
|
|
10
|
+
class LambdaServer {
|
|
11
|
+
constructor(port, config) {
|
|
12
|
+
this.port = port;
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.app = express();
|
|
15
|
+
this.simulator = null;
|
|
16
|
+
this.server = null;
|
|
17
|
+
this.setupMiddlewares();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setupMiddlewares() {
|
|
21
|
+
this.app.use(express.json({ limit: '10mb' }));
|
|
22
|
+
this.app.use(express.urlencoded({ extended: true }));
|
|
23
|
+
this.app.use(cors());
|
|
24
|
+
|
|
25
|
+
// Logging de requisições
|
|
26
|
+
if (logger.currentLogLevel === 'verboso') {
|
|
27
|
+
this.app.use((req, res, next) => {
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
res.on('finish', () => {
|
|
30
|
+
const duration = Date.now() - start;
|
|
31
|
+
logger.verboso(`Lambda: ${req.method} ${req.path} - ${duration}ms`);
|
|
32
|
+
});
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async initialize() {
|
|
39
|
+
this.simulator = new LambdaSimulator(this.config);
|
|
40
|
+
await this.simulator.initialize();
|
|
41
|
+
this.setupRoutes();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setupRoutes() {
|
|
45
|
+
// Health check
|
|
46
|
+
this.app.get('/health', (req, res) => {
|
|
47
|
+
res.json({
|
|
48
|
+
status: 'healthy',
|
|
49
|
+
version: require('../../../package.json').version,
|
|
50
|
+
lambdas: this.simulator.getLambdasCount(),
|
|
51
|
+
routes: this.simulator.listRoutes()
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Rota catch-all para todas as Lambdas
|
|
56
|
+
this.app.all('*', async (req, res) => {
|
|
57
|
+
const result = await this.simulator.handleRequest(req, res);
|
|
58
|
+
|
|
59
|
+
if (result && result.error) {
|
|
60
|
+
res.status(result.status).json(result.error);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Admin endpoints
|
|
65
|
+
this.setupAdminRoutes();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setupAdminRoutes() {
|
|
69
|
+
// Listar todas as Lambdas
|
|
70
|
+
this.app.get('/__admin/lambdas', (req, res) => {
|
|
71
|
+
res.json(this.simulator.listLambdas());
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Detalhes de uma Lambda
|
|
75
|
+
this.app.get('/__admin/lambdas/:path', (req, res) => {
|
|
76
|
+
const lambda = this.simulator.getLambda(req.params.path);
|
|
77
|
+
if (lambda) {
|
|
78
|
+
res.json(lambda);
|
|
79
|
+
} else {
|
|
80
|
+
res.status(404).json({ error: 'Lambda not found' });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Recarregar Lambdas
|
|
85
|
+
this.app.post('/__admin/reload', async (req, res) => {
|
|
86
|
+
await this.simulator.reloadLambdas();
|
|
87
|
+
res.json({
|
|
88
|
+
message: 'Lambdas recarregadas',
|
|
89
|
+
count: this.simulator.getLambdasCount()
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Injetar variável de ambiente
|
|
94
|
+
this.app.post('/__admin/env', (req, res) => {
|
|
95
|
+
const { key, value } = req.body;
|
|
96
|
+
if (key && value !== undefined) {
|
|
97
|
+
this.simulator.setEnvironmentVariable(key, value);
|
|
98
|
+
res.json({ message: `Environment variable ${key} set` });
|
|
99
|
+
} else {
|
|
100
|
+
res.status(400).json({ error: 'Missing key or value' });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Listar variáveis de ambiente
|
|
105
|
+
this.app.get('/__admin/env', (req, res) => {
|
|
106
|
+
res.json(this.simulator.getEnvironmentVariables());
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Estatísticas
|
|
110
|
+
this.app.get('/__admin/stats', (req, res) => {
|
|
111
|
+
res.json(this.simulator.getStats());
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
start() {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
this.server = this.app.listen(this.port, () => {
|
|
118
|
+
logger.info(`🚀 Lambda API rodando em http://localhost:${this.port}`);
|
|
119
|
+
this.printRoutes();
|
|
120
|
+
resolve();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
printRoutes() {
|
|
126
|
+
logger.info('\n📚 Lambdas registradas:');
|
|
127
|
+
const lambdas = this.simulator.listLambdas();
|
|
128
|
+
for (const lambda of lambdas) {
|
|
129
|
+
logger.info(` ${lambda.path.padEnd(30)} -> ${lambda.handlerName || 'anonymous'}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
stop() {
|
|
134
|
+
return new Promise((resolve) => {
|
|
135
|
+
if (this.server) {
|
|
136
|
+
this.server.close(() => resolve());
|
|
137
|
+
} else {
|
|
138
|
+
resolve();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getStatus() {
|
|
144
|
+
return {
|
|
145
|
+
running: !!this.server,
|
|
146
|
+
port: this.port,
|
|
147
|
+
endpoint: `http://localhost:${this.port}`,
|
|
148
|
+
lambdasCount: this.simulator?.getLambdasCount() || 0
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = LambdaServer;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lambda Simulator - Simula execução de funções Lambda
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const HandlerLoader = require('./handler-loader');
|
|
6
|
+
const RouteRegistry = require('./route-registry');
|
|
7
|
+
const logger = require('../../utils/logger');
|
|
8
|
+
|
|
9
|
+
class LambdaSimulator {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.routeRegistry = new RouteRegistry();
|
|
13
|
+
this.lambdas = new Map();
|
|
14
|
+
this.environment = { ...process.env };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async initialize() {
|
|
18
|
+
logger.debug('Inicializando Lambda Simulator...');
|
|
19
|
+
|
|
20
|
+
if (this.config.lambdas && this.config.lambdas.length > 0) {
|
|
21
|
+
for (const lambdaConfig of this.config.lambdas) {
|
|
22
|
+
await this.registerLambda(lambdaConfig);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
logger.debug(`✅ ${this.lambdas.size} Lambdas registradas`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async registerLambda(lambdaConfig) {
|
|
30
|
+
try {
|
|
31
|
+
const { path, handler: handlerPath, env = {}, type = 'auto' } = lambdaConfig;
|
|
32
|
+
|
|
33
|
+
// Carrega o handler
|
|
34
|
+
const handler = await HandlerLoader.load(handlerPath, type);
|
|
35
|
+
|
|
36
|
+
// Registra no route registry
|
|
37
|
+
this.routeRegistry.register(path, handler, env);
|
|
38
|
+
|
|
39
|
+
// Armazena metadata
|
|
40
|
+
this.lambdas.set(path, {
|
|
41
|
+
path,
|
|
42
|
+
handler,
|
|
43
|
+
handlerPath,
|
|
44
|
+
handlerName: handler.name || 'anonymous',
|
|
45
|
+
env,
|
|
46
|
+
type,
|
|
47
|
+
registeredAt: new Date().toISOString()
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
logger.debug(`✅ Lambda registrada: ${path} -> ${handler.name || 'anonymous'}`);
|
|
51
|
+
|
|
52
|
+
} catch (error) {
|
|
53
|
+
logger.error(`❌ Erro ao registrar Lambda ${lambdaConfig.path}:`, error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async handleRequest(req, res) {
|
|
59
|
+
const matchedRoute = this.routeRegistry.find(req.path);
|
|
60
|
+
|
|
61
|
+
if (!matchedRoute) {
|
|
62
|
+
return {
|
|
63
|
+
error: {
|
|
64
|
+
statusCode: 404,
|
|
65
|
+
message: `Route not found: ${req.path}`,
|
|
66
|
+
availableRoutes: this.listRoutes()
|
|
67
|
+
},
|
|
68
|
+
status: 404
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Aplica variáveis de ambiente específicas da rota
|
|
73
|
+
this.applyEnvironment(matchedRoute.env);
|
|
74
|
+
|
|
75
|
+
// Prepara evento Lambda
|
|
76
|
+
const event = this.toLambdaEvent(req, matchedRoute.params);
|
|
77
|
+
|
|
78
|
+
logger.debug(`🎯 Executando: ${matchedRoute.path} -> ${matchedRoute.handler.name || 'anonymous'}`);
|
|
79
|
+
|
|
80
|
+
// Executa middlewares
|
|
81
|
+
const middlewares = this.routeRegistry.getMiddlewares(matchedRoute);
|
|
82
|
+
let handled = false;
|
|
83
|
+
let result = null;
|
|
84
|
+
|
|
85
|
+
const runMiddlewares = async (index) => {
|
|
86
|
+
if (index >= middlewares.length) {
|
|
87
|
+
// Executa handler
|
|
88
|
+
|
|
89
|
+
result = await this.executeHandler(matchedRoute.handler, event);
|
|
90
|
+
handled = true;
|
|
91
|
+
|
|
92
|
+
console.log(`✅ Resposta: ${result.statusCode}`);
|
|
93
|
+
res
|
|
94
|
+
.status(result.statusCode || 200)
|
|
95
|
+
.set(result.headers || {})
|
|
96
|
+
.send(result.body ? JSON.parse(result.body) : null);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const middleware = middlewares[index];
|
|
101
|
+
await new Promise((resolve, reject) => {
|
|
102
|
+
middleware(event, {
|
|
103
|
+
status: (code) => ({ json: (data) => {
|
|
104
|
+
result = { statusCode: code, body: data };
|
|
105
|
+
handled = true;
|
|
106
|
+
resolve();
|
|
107
|
+
}}),
|
|
108
|
+
send: (data) => {
|
|
109
|
+
result = { statusCode: 200, body: data };
|
|
110
|
+
handled = true;
|
|
111
|
+
resolve();
|
|
112
|
+
},
|
|
113
|
+
next: () => {
|
|
114
|
+
runMiddlewares(index + 1).then(resolve).catch(reject);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
await runMiddlewares(0);
|
|
121
|
+
|
|
122
|
+
if (!handled && result) {
|
|
123
|
+
return this.formatResponse(result);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async executeHandler(handler, event) {
|
|
130
|
+
try {
|
|
131
|
+
const context = this.createContext();
|
|
132
|
+
const result = await handler(event, context);
|
|
133
|
+
return result;
|
|
134
|
+
} catch (error) {
|
|
135
|
+
logger.error('❌ Erro no handler:', error);
|
|
136
|
+
return {
|
|
137
|
+
statusCode: 500,
|
|
138
|
+
body: {
|
|
139
|
+
error: 'Internal Server Error',
|
|
140
|
+
message: error.message,
|
|
141
|
+
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
toLambdaEvent(req, params = {}) {
|
|
148
|
+
return {
|
|
149
|
+
httpMethod: req.method,
|
|
150
|
+
path: req.path,
|
|
151
|
+
headers: req.headers,
|
|
152
|
+
queryStringParameters: req.query,
|
|
153
|
+
pathParameters: params,
|
|
154
|
+
body: req.body ? (typeof req.body === 'string' ? req.body : JSON.stringify(req.body)) : null,
|
|
155
|
+
isBase64Encoded: false,
|
|
156
|
+
requestContext: {
|
|
157
|
+
path: req.path,
|
|
158
|
+
stage: process.env.STAGE_NAME || 'dev',
|
|
159
|
+
requestId: Math.random().toString(36).substring(7),
|
|
160
|
+
identity: {
|
|
161
|
+
sourceIp: req.ip,
|
|
162
|
+
userAgent: req.headers['user-agent']
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
stageVariables: {},
|
|
166
|
+
resource: req.path
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
formatResponse(result) {
|
|
171
|
+
const statusCode = result.statusCode || 200;
|
|
172
|
+
const body = result.body;
|
|
173
|
+
const headers = result.headers || { 'Content-Type': 'application/json' };
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
statusCode,
|
|
177
|
+
headers,
|
|
178
|
+
body: typeof body === 'string' ? body : JSON.stringify(body),
|
|
179
|
+
isBase64Encoded: false
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
createContext() {
|
|
184
|
+
return {
|
|
185
|
+
awsRequestId: Math.random().toString(36).substring(7),
|
|
186
|
+
functionName: 'local-lambda',
|
|
187
|
+
functionVersion: '$LATEST',
|
|
188
|
+
invokedFunctionArn: 'arn:aws:lambda:local:function',
|
|
189
|
+
memoryLimitInMB: '1024',
|
|
190
|
+
logGroupName: '/aws/lambda/local-lambda',
|
|
191
|
+
logStreamName: 'local-stream',
|
|
192
|
+
getRemainingTimeInMillis: () => 30000,
|
|
193
|
+
callbackWaitsForEmptyEventLoop: true,
|
|
194
|
+
identity: null,
|
|
195
|
+
clientContext: null
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
applyEnvironment(env) {
|
|
200
|
+
for (const [key, value] of Object.entries(env)) {
|
|
201
|
+
process.env[key] = value;
|
|
202
|
+
this.environment[key] = value;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setEnvironmentVariable(key, value) {
|
|
207
|
+
process.env[key] = value;
|
|
208
|
+
this.environment[key] = value;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getEnvironmentVariables() {
|
|
212
|
+
return { ...this.environment };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
listLambdas() {
|
|
216
|
+
return Array.from(this.lambdas.values()).map(l => ({
|
|
217
|
+
path: l.path,
|
|
218
|
+
handlerName: l.handlerName,
|
|
219
|
+
handlerPath: l.handlerPath,
|
|
220
|
+
type: l.type,
|
|
221
|
+
env: l.env,
|
|
222
|
+
registeredAt: l.registeredAt
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
getLambda(path) {
|
|
227
|
+
return this.lambdas.get(path);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
listRoutes() {
|
|
231
|
+
return this.routeRegistry.list();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
getLambdasCount() {
|
|
235
|
+
return this.lambdas.size;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async reloadLambdas() {
|
|
239
|
+
logger.info('🔄 Recarregando Lambdas...');
|
|
240
|
+
|
|
241
|
+
for (const [path, lambda] of this.lambdas.entries()) {
|
|
242
|
+
try {
|
|
243
|
+
const newHandler = await HandlerLoader.reload(lambda.handlerPath, lambda.type);
|
|
244
|
+
this.routeRegistry.register(path, newHandler, lambda.env);
|
|
245
|
+
lambda.handler = newHandler;
|
|
246
|
+
lambda.handlerName = newHandler.name || 'anonymous';
|
|
247
|
+
logger.debug(`✅ Lambda recarregada: ${path}`);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
logger.error(`❌ Erro ao recarregar Lambda ${path}:`, error);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
logger.info(`✅ ${this.lambdas.size} Lambdas recarregadas`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
getStats() {
|
|
257
|
+
const lambdas = this.listLambdas();
|
|
258
|
+
return {
|
|
259
|
+
totalLambdas: lambdas.length,
|
|
260
|
+
lambdas: lambdas.map(l => ({
|
|
261
|
+
path: l.path,
|
|
262
|
+
handler: l.handlerName
|
|
263
|
+
})),
|
|
264
|
+
routes: this.routeRegistry.getStats(),
|
|
265
|
+
environment: Object.keys(this.environment).length
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async reset() {
|
|
270
|
+
// Recarrega Lambdas
|
|
271
|
+
await this.reloadLambdas();
|
|
272
|
+
|
|
273
|
+
// Limpa variáveis de ambiente customizadas
|
|
274
|
+
for (const key of Object.keys(this.environment)) {
|
|
275
|
+
if (!process.env.hasOwnProperty(key) || key.startsWith('AWS_LOCAL_SIMULATOR_')) {
|
|
276
|
+
delete process.env[key];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.environment = { ...process.env };
|
|
281
|
+
logger.debug('Lambda: Estado resetado');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
module.exports = LambdaSimulator;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S3 Service - Ponto de entrada
|
|
3
|
+
* Exporta o serviço principal e seus componentes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const S3Server = require('./server');
|
|
7
|
+
const S3Simulator = require('./simulator');
|
|
8
|
+
|
|
9
|
+
class S3Service {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.name = 's3';
|
|
13
|
+
this.port = config.ports.s3;
|
|
14
|
+
this.server = null;
|
|
15
|
+
this.simulator = null;
|
|
16
|
+
this.isRunning = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async initialize() {
|
|
20
|
+
const logger = require('../../utils/logger');
|
|
21
|
+
logger.debug(`Inicializando S3 Service na porta ${this.port}...`);
|
|
22
|
+
|
|
23
|
+
// Cria o simulador
|
|
24
|
+
this.simulator = new S3Simulator(this.config);
|
|
25
|
+
|
|
26
|
+
// Cria o servidor HTTP
|
|
27
|
+
this.server = new S3Server(this.port, this.config);
|
|
28
|
+
this.server.simulator = this.simulator;
|
|
29
|
+
|
|
30
|
+
await this.server.initialize();
|
|
31
|
+
|
|
32
|
+
logger.debug('S3 Service inicializado');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async start() {
|
|
36
|
+
if (this.isRunning) return;
|
|
37
|
+
await this.server.start();
|
|
38
|
+
this.isRunning = true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async stop() {
|
|
42
|
+
if (!this.isRunning) return;
|
|
43
|
+
await this.server.stop();
|
|
44
|
+
this.isRunning = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async reset() {
|
|
48
|
+
await this.simulator.reset();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getStatus() {
|
|
52
|
+
return {
|
|
53
|
+
running: this.isRunning,
|
|
54
|
+
port: this.port,
|
|
55
|
+
endpoint: `http://localhost:${this.port}`,
|
|
56
|
+
bucketsCount: this.simulator?.getBucketsCount() || 0,
|
|
57
|
+
objectsCount: this.simulator?.getTotalObjectsCount() || 0
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
getSimulator() {
|
|
62
|
+
return this.simulator;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getServer() {
|
|
66
|
+
return this.server;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = S3Service;
|