@gugananuvem/aws-local-simulator 1.0.10 → 1.0.11
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 +204 -193
- package/bin/aws-local-simulator.js +62 -62
- package/package.json +2 -2
- package/src/config/config-loader.js +112 -112
- package/src/config/default-config.js +65 -65
- package/src/config/env-loader.js +68 -68
- package/src/index.js +130 -130
- package/src/index.mjs +123 -123
- package/src/server.js +221 -222
- package/src/services/apigateway/index.js +66 -66
- package/src/services/apigateway/server.js +434 -434
- package/src/services/apigateway/simulator.js +1251 -1251
- package/src/services/cognito/index.js +65 -65
- package/src/services/cognito/server.js +228 -228
- package/src/services/cognito/simulator.js +847 -847
- package/src/services/dynamodb/index.js +70 -70
- package/src/services/dynamodb/server.js +121 -121
- package/src/services/dynamodb/simulator.js +620 -614
- package/src/services/ecs/index.js +65 -65
- package/src/services/ecs/server.js +233 -233
- package/src/services/ecs/simulator.js +844 -844
- package/src/services/eventbridge/index.js +84 -84
- package/src/services/index.js +18 -18
- package/src/services/lambda/handler-loader.js +172 -172
- package/src/services/lambda/index.js +72 -72
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +152 -152
- package/src/services/lambda/simulator.js +284 -284
- package/src/services/s3/index.js +69 -69
- package/src/services/s3/server.js +238 -238
- package/src/services/s3/simulator.js +740 -740
- package/src/services/sns/index.js +75 -75
- package/src/services/sqs/index.js +95 -95
- package/src/services/sqs/server.js +273 -273
- package/src/services/sqs/simulator.js +659 -659
- 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/local-store.js +67 -67
- package/src/utils/logger.js +59 -59
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Carrega configurações do usuário
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const defaultConfig = require('./default-config');
|
|
8
|
-
const EnvLoader = require('./env-loader');
|
|
9
|
-
const logger = require('../utils/logger');
|
|
10
|
-
|
|
11
|
-
class ConfigLoader {
|
|
12
|
-
static async load(configPath) {
|
|
13
|
-
logger.info('📝 Carregando configurações...');
|
|
14
|
-
|
|
15
|
-
// 1. Carrega configurações padrão
|
|
16
|
-
let config = { ...defaultConfig };
|
|
17
|
-
|
|
18
|
-
// 2. Sobrescreve com variáveis de ambiente
|
|
19
|
-
const envConfig = EnvLoader.load();
|
|
20
|
-
config = this.mergeDeep(config, envConfig);
|
|
21
|
-
|
|
22
|
-
// 3. Sobrescreve com arquivo de configuração do usuário se existir
|
|
23
|
-
if (configPath) {
|
|
24
|
-
const userConfig = await this.loadUserConfig(configPath);
|
|
25
|
-
config = this.mergeDeep(config, userConfig);
|
|
26
|
-
} else {
|
|
27
|
-
// Tenta encontrar arquivo de configuração padrão
|
|
28
|
-
const possiblePaths = [
|
|
29
|
-
path.join(process.cwd(), 'aws-local-simulator.json'),
|
|
30
|
-
path.join(process.cwd(), 'aws-local-simulator.config.json'),
|
|
31
|
-
path.join(process.cwd(), '.aws-local-simulator.json')
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
for (const possiblePath of possiblePaths) {
|
|
35
|
-
if (fs.existsSync(possiblePath)) {
|
|
36
|
-
const userConfig = await this.loadUserConfig(possiblePath);
|
|
37
|
-
config = this.mergeDeep(config, userConfig);
|
|
38
|
-
logger.info(`✅ Configuração carregada de: ${possiblePath}`);
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 4. Valida configurações
|
|
45
|
-
this.validate(config);
|
|
46
|
-
|
|
47
|
-
logger.info(`✅ Configurações carregadas (logLevel: ${config.logLevel})`);
|
|
48
|
-
|
|
49
|
-
return config;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static async loadUserConfig(filePath) {
|
|
53
|
-
try {
|
|
54
|
-
const fullPath = path.resolve(process.cwd(), filePath);
|
|
55
|
-
|
|
56
|
-
if (!fs.existsSync(fullPath)) {
|
|
57
|
-
logger.warn(`Arquivo de configuração não encontrado: ${fullPath}`);
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const content = fs.readFileSync(fullPath, 'utf8');
|
|
62
|
-
const config = JSON.parse(content);
|
|
63
|
-
|
|
64
|
-
return config;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
logger.error(`Erro ao carregar configuração de ${filePath}:`, error);
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
static validate(config) {
|
|
72
|
-
// Valida serviços
|
|
73
|
-
const enabledServices = Object.entries(config.services)
|
|
74
|
-
.filter(([_, enabled]) => enabled)
|
|
75
|
-
.map(([name]) => name);
|
|
76
|
-
|
|
77
|
-
if (enabledServices.length === 0) {
|
|
78
|
-
logger.warn('⚠️ Nenhum serviço está habilitado!');
|
|
79
|
-
} else {
|
|
80
|
-
logger.info(`📦 Serviços habilitados: ${enabledServices.join(', ')}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Valida diretório de dados
|
|
84
|
-
if (!config.dataDir) {
|
|
85
|
-
throw new Error('dataDir não configurado');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Valida portas
|
|
89
|
-
for (const [service, port] of Object.entries(config.ports)) {
|
|
90
|
-
if (config.services[service] && (port < 1 || port > 65535)) {
|
|
91
|
-
throw new Error(`Porta inválida para ${service}: ${port}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
static mergeDeep(target, source) {
|
|
97
|
-
const output = { ...target };
|
|
98
|
-
|
|
99
|
-
for (const key in source) {
|
|
100
|
-
if (source.hasOwnProperty(key)) {
|
|
101
|
-
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
102
|
-
output[key] = this.mergeDeep(target[key] || {}, source[key]);
|
|
103
|
-
} else {
|
|
104
|
-
output[key] = source[key];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return output;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Carrega configurações do usuário
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const defaultConfig = require('./default-config');
|
|
8
|
+
const EnvLoader = require('./env-loader');
|
|
9
|
+
const logger = require('../utils/logger');
|
|
10
|
+
|
|
11
|
+
class ConfigLoader {
|
|
12
|
+
static async load(configPath) {
|
|
13
|
+
logger.info('📝 Carregando configurações...');
|
|
14
|
+
|
|
15
|
+
// 1. Carrega configurações padrão
|
|
16
|
+
let config = { ...defaultConfig };
|
|
17
|
+
|
|
18
|
+
// 2. Sobrescreve com variáveis de ambiente
|
|
19
|
+
const envConfig = EnvLoader.load();
|
|
20
|
+
config = this.mergeDeep(config, envConfig);
|
|
21
|
+
|
|
22
|
+
// 3. Sobrescreve com arquivo de configuração do usuário se existir
|
|
23
|
+
if (configPath) {
|
|
24
|
+
const userConfig = await this.loadUserConfig(configPath);
|
|
25
|
+
config = this.mergeDeep(config, userConfig);
|
|
26
|
+
} else {
|
|
27
|
+
// Tenta encontrar arquivo de configuração padrão
|
|
28
|
+
const possiblePaths = [
|
|
29
|
+
path.join(process.cwd(), 'aws-local-simulator.json'),
|
|
30
|
+
path.join(process.cwd(), 'aws-local-simulator.config.json'),
|
|
31
|
+
path.join(process.cwd(), '.aws-local-simulator.json')
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
for (const possiblePath of possiblePaths) {
|
|
35
|
+
if (fs.existsSync(possiblePath)) {
|
|
36
|
+
const userConfig = await this.loadUserConfig(possiblePath);
|
|
37
|
+
config = this.mergeDeep(config, userConfig);
|
|
38
|
+
logger.info(`✅ Configuração carregada de: ${possiblePath}`);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 4. Valida configurações
|
|
45
|
+
this.validate(config);
|
|
46
|
+
|
|
47
|
+
logger.info(`✅ Configurações carregadas (logLevel: ${config.logLevel})`);
|
|
48
|
+
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static async loadUserConfig(filePath) {
|
|
53
|
+
try {
|
|
54
|
+
const fullPath = path.resolve(process.cwd(), filePath);
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(fullPath)) {
|
|
57
|
+
logger.warn(`Arquivo de configuração não encontrado: ${fullPath}`);
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const content = fs.readFileSync(fullPath, 'utf8');
|
|
62
|
+
const config = JSON.parse(content);
|
|
63
|
+
|
|
64
|
+
return config;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
logger.error(`Erro ao carregar configuração de ${filePath}:`, error);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static validate(config) {
|
|
72
|
+
// Valida serviços
|
|
73
|
+
const enabledServices = Object.entries(config.services)
|
|
74
|
+
.filter(([_, enabled]) => enabled)
|
|
75
|
+
.map(([name]) => name);
|
|
76
|
+
|
|
77
|
+
if (enabledServices.length === 0) {
|
|
78
|
+
logger.warn('⚠️ Nenhum serviço está habilitado!');
|
|
79
|
+
} else {
|
|
80
|
+
logger.info(`📦 Serviços habilitados: ${enabledServices.join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Valida diretório de dados
|
|
84
|
+
if (!config.dataDir) {
|
|
85
|
+
throw new Error('dataDir não configurado');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Valida portas
|
|
89
|
+
for (const [service, port] of Object.entries(config.ports)) {
|
|
90
|
+
if (config.services[service] && (port < 1 || port > 65535)) {
|
|
91
|
+
throw new Error(`Porta inválida para ${service}: ${port}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static mergeDeep(target, source) {
|
|
97
|
+
const output = { ...target };
|
|
98
|
+
|
|
99
|
+
for (const key in source) {
|
|
100
|
+
if (source.hasOwnProperty(key)) {
|
|
101
|
+
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
102
|
+
output[key] = this.mergeDeep(target[key] || {}, source[key]);
|
|
103
|
+
} else {
|
|
104
|
+
output[key] = source[key];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return output;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
113
|
module.exports = { loadConfig: ConfigLoader.load.bind(ConfigLoader) };
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configurações padrão do simulador
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
// Serviços habilitados por padrão
|
|
7
|
-
services: {
|
|
8
|
-
dynamodb: true,
|
|
9
|
-
s3: true,
|
|
10
|
-
sqs: true,
|
|
11
|
-
lambda: true,
|
|
12
|
-
sns: false,
|
|
13
|
-
eventbridge: false,
|
|
14
|
-
ecs: false,
|
|
15
|
-
cognito: false,
|
|
16
|
-
apigateway: false,
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
// Portas padrão
|
|
20
|
-
ports: {
|
|
21
|
-
dynamodb: 8000,
|
|
22
|
-
s3: 4566,
|
|
23
|
-
sqs: 9324,
|
|
24
|
-
lambda: 3001,
|
|
25
|
-
sns: 9911,
|
|
26
|
-
eventbridge: 4010,
|
|
27
|
-
ecs: 8080,
|
|
28
|
-
cognito: 9229,
|
|
29
|
-
apigateway: 4567,
|
|
30
|
-
},
|
|
31
|
-
apigateway: {
|
|
32
|
-
defaultCors: {
|
|
33
|
-
allowOrigins: ["*"],
|
|
34
|
-
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
35
|
-
allowHeaders: ["*"],
|
|
36
|
-
maxAge: 300,
|
|
37
|
-
},
|
|
38
|
-
defaultThrottling: {
|
|
39
|
-
burstLimit: 100,
|
|
40
|
-
rateLimit: 10,
|
|
41
|
-
},
|
|
42
|
-
enableAccessLogging: true,
|
|
43
|
-
autoDeploy: true,
|
|
44
|
-
},
|
|
45
|
-
// Configurações de persistência
|
|
46
|
-
dataDir: "./.aws-local-simulator-data",
|
|
47
|
-
|
|
48
|
-
// Configurações de logging
|
|
49
|
-
logLevel: "info", // silent, info, debug, verboso
|
|
50
|
-
|
|
51
|
-
// Configurações das Lambdas
|
|
52
|
-
lambdas: [], // Será preenchido pelo usuário
|
|
53
|
-
|
|
54
|
-
// Configurações de CORS
|
|
55
|
-
cors: true,
|
|
56
|
-
|
|
57
|
-
// Auto-criação de tabelas DynamoDB
|
|
58
|
-
autoCreateTables: true,
|
|
59
|
-
|
|
60
|
-
// Auto-criação de buckets S3
|
|
61
|
-
autoCreateBuckets: true,
|
|
62
|
-
|
|
63
|
-
// Configurações adicionais
|
|
64
|
-
additional: {},
|
|
65
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Configurações padrão do simulador
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
// Serviços habilitados por padrão
|
|
7
|
+
services: {
|
|
8
|
+
dynamodb: true,
|
|
9
|
+
s3: true,
|
|
10
|
+
sqs: true,
|
|
11
|
+
lambda: true,
|
|
12
|
+
sns: false,
|
|
13
|
+
eventbridge: false,
|
|
14
|
+
ecs: false,
|
|
15
|
+
cognito: false,
|
|
16
|
+
apigateway: false,
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Portas padrão
|
|
20
|
+
ports: {
|
|
21
|
+
dynamodb: 8000,
|
|
22
|
+
s3: 4566,
|
|
23
|
+
sqs: 9324,
|
|
24
|
+
lambda: 3001,
|
|
25
|
+
sns: 9911,
|
|
26
|
+
eventbridge: 4010,
|
|
27
|
+
ecs: 8080,
|
|
28
|
+
cognito: 9229,
|
|
29
|
+
apigateway: 4567,
|
|
30
|
+
},
|
|
31
|
+
apigateway: {
|
|
32
|
+
defaultCors: {
|
|
33
|
+
allowOrigins: ["*"],
|
|
34
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
35
|
+
allowHeaders: ["*"],
|
|
36
|
+
maxAge: 300,
|
|
37
|
+
},
|
|
38
|
+
defaultThrottling: {
|
|
39
|
+
burstLimit: 100,
|
|
40
|
+
rateLimit: 10,
|
|
41
|
+
},
|
|
42
|
+
enableAccessLogging: true,
|
|
43
|
+
autoDeploy: true,
|
|
44
|
+
},
|
|
45
|
+
// Configurações de persistência
|
|
46
|
+
dataDir: "./.aws-local-simulator-data",
|
|
47
|
+
|
|
48
|
+
// Configurações de logging
|
|
49
|
+
logLevel: "info", // silent, info, debug, verboso
|
|
50
|
+
|
|
51
|
+
// Configurações das Lambdas
|
|
52
|
+
lambdas: [], // Será preenchido pelo usuário
|
|
53
|
+
|
|
54
|
+
// Configurações de CORS
|
|
55
|
+
cors: true,
|
|
56
|
+
|
|
57
|
+
// Auto-criação de tabelas DynamoDB
|
|
58
|
+
autoCreateTables: true,
|
|
59
|
+
|
|
60
|
+
// Auto-criação de buckets S3
|
|
61
|
+
autoCreateBuckets: true,
|
|
62
|
+
|
|
63
|
+
// Configurações adicionais
|
|
64
|
+
additional: {},
|
|
65
|
+
};
|
package/src/config/env-loader.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Carrega configurações de variáveis de ambiente
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const logger = require('../utils/logger');
|
|
6
|
-
|
|
7
|
-
class EnvLoader {
|
|
8
|
-
static load() {
|
|
9
|
-
const config = {};
|
|
10
|
-
|
|
11
|
-
// Carrega configuração de serviços
|
|
12
|
-
config.services = {
|
|
13
|
-
dynamodb: this.getEnvBool('AWS_LOCAL_SIMULATOR_DYNAMODB', true),
|
|
14
|
-
s3: this.getEnvBool('AWS_LOCAL_SIMULATOR_S3', true),
|
|
15
|
-
sqs: this.getEnvBool('AWS_LOCAL_SIMULATOR_SQS', true),
|
|
16
|
-
sns: this.getEnvBool('AWS_LOCAL_SIMULATOR_SNS', false),
|
|
17
|
-
lambda: this.getEnvBool('AWS_LOCAL_SIMULATOR_LAMBDA', true),
|
|
18
|
-
apigateway: this.getEnvBool('AWS_LOCAL_SIMULATOR_APIGATEWAY', false),
|
|
19
|
-
eventbridge: this.getEnvBool('AWS_LOCAL_SIMULATOR_EVENTBRIDGE', false)
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Carrega portas
|
|
23
|
-
config.ports = {
|
|
24
|
-
dynamodb: this.getEnvInt('AWS_LOCAL_SIMULATOR_DYNAMODB_PORT', 8000),
|
|
25
|
-
s3: this.getEnvInt('AWS_LOCAL_SIMULATOR_S3_PORT', 4566),
|
|
26
|
-
sqs: this.getEnvInt('AWS_LOCAL_SIMULATOR_SQS_PORT', 9324),
|
|
27
|
-
lambda: this.getEnvInt('AWS_LOCAL_SIMULATOR_LAMBDA_PORT', 3001),
|
|
28
|
-
sns: this.getEnvInt('AWS_LOCAL_SIMULATOR_SNS_PORT', 9911),
|
|
29
|
-
apigateway: this.getEnvInt('AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT', 4567),
|
|
30
|
-
eventbridge: this.getEnvInt('AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT', 4010)
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Carrega diretório de dados
|
|
34
|
-
config.dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA || './.aws-local-simulator-data';
|
|
35
|
-
|
|
36
|
-
// Carrega nível de log
|
|
37
|
-
config.logLevel = process.env.AWS_LOCAL_SIMULATOR_LOG || 'info';
|
|
38
|
-
|
|
39
|
-
// Carrega CORS
|
|
40
|
-
config.cors = this.getEnvBool('AWS_LOCAL_SIMULATOR_CORS', true);
|
|
41
|
-
|
|
42
|
-
// Carrega auto-create
|
|
43
|
-
config.autoCreateTables = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_TABLES', true);
|
|
44
|
-
config.autoCreateBuckets = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_BUCKETS', true);
|
|
45
|
-
|
|
46
|
-
logger.debug('Variáveis de ambiente carregadas:', config);
|
|
47
|
-
|
|
48
|
-
return config;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static getEnvBool(key, defaultValue) {
|
|
52
|
-
const value = process.env[key];
|
|
53
|
-
if (value === undefined) return defaultValue;
|
|
54
|
-
return value === 'true' || value === '1' || value === 'yes';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static getEnvInt(key, defaultValue) {
|
|
58
|
-
const value = process.env[key];
|
|
59
|
-
if (value === undefined) return defaultValue;
|
|
60
|
-
const parsed = parseInt(value, 10);
|
|
61
|
-
return isNaN(parsed) ? defaultValue : parsed;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static getEnvString(key, defaultValue) {
|
|
65
|
-
return process.env[key] || defaultValue;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Carrega configurações de variáveis de ambiente
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const logger = require('../utils/logger');
|
|
6
|
+
|
|
7
|
+
class EnvLoader {
|
|
8
|
+
static load() {
|
|
9
|
+
const config = {};
|
|
10
|
+
|
|
11
|
+
// Carrega configuração de serviços
|
|
12
|
+
config.services = {
|
|
13
|
+
dynamodb: this.getEnvBool('AWS_LOCAL_SIMULATOR_DYNAMODB', true),
|
|
14
|
+
s3: this.getEnvBool('AWS_LOCAL_SIMULATOR_S3', true),
|
|
15
|
+
sqs: this.getEnvBool('AWS_LOCAL_SIMULATOR_SQS', true),
|
|
16
|
+
sns: this.getEnvBool('AWS_LOCAL_SIMULATOR_SNS', false),
|
|
17
|
+
lambda: this.getEnvBool('AWS_LOCAL_SIMULATOR_LAMBDA', true),
|
|
18
|
+
apigateway: this.getEnvBool('AWS_LOCAL_SIMULATOR_APIGATEWAY', false),
|
|
19
|
+
eventbridge: this.getEnvBool('AWS_LOCAL_SIMULATOR_EVENTBRIDGE', false)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Carrega portas
|
|
23
|
+
config.ports = {
|
|
24
|
+
dynamodb: this.getEnvInt('AWS_LOCAL_SIMULATOR_DYNAMODB_PORT', 8000),
|
|
25
|
+
s3: this.getEnvInt('AWS_LOCAL_SIMULATOR_S3_PORT', 4566),
|
|
26
|
+
sqs: this.getEnvInt('AWS_LOCAL_SIMULATOR_SQS_PORT', 9324),
|
|
27
|
+
lambda: this.getEnvInt('AWS_LOCAL_SIMULATOR_LAMBDA_PORT', 3001),
|
|
28
|
+
sns: this.getEnvInt('AWS_LOCAL_SIMULATOR_SNS_PORT', 9911),
|
|
29
|
+
apigateway: this.getEnvInt('AWS_LOCAL_SIMULATOR_APIGATEWAY_PORT', 4567),
|
|
30
|
+
eventbridge: this.getEnvInt('AWS_LOCAL_SIMULATOR_EVENTBRIDGE_PORT', 4010)
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Carrega diretório de dados
|
|
34
|
+
config.dataDir = process.env.AWS_LOCAL_SIMULATOR_DATA || './.aws-local-simulator-data';
|
|
35
|
+
|
|
36
|
+
// Carrega nível de log
|
|
37
|
+
config.logLevel = process.env.AWS_LOCAL_SIMULATOR_LOG || 'info';
|
|
38
|
+
|
|
39
|
+
// Carrega CORS
|
|
40
|
+
config.cors = this.getEnvBool('AWS_LOCAL_SIMULATOR_CORS', true);
|
|
41
|
+
|
|
42
|
+
// Carrega auto-create
|
|
43
|
+
config.autoCreateTables = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_TABLES', true);
|
|
44
|
+
config.autoCreateBuckets = this.getEnvBool('AWS_LOCAL_SIMULATOR_AUTO_CREATE_BUCKETS', true);
|
|
45
|
+
|
|
46
|
+
logger.debug('Variáveis de ambiente carregadas:', config);
|
|
47
|
+
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static getEnvBool(key, defaultValue) {
|
|
52
|
+
const value = process.env[key];
|
|
53
|
+
if (value === undefined) return defaultValue;
|
|
54
|
+
return value === 'true' || value === '1' || value === 'yes';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static getEnvInt(key, defaultValue) {
|
|
58
|
+
const value = process.env[key];
|
|
59
|
+
if (value === undefined) return defaultValue;
|
|
60
|
+
const parsed = parseInt(value, 10);
|
|
61
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static getEnvString(key, defaultValue) {
|
|
65
|
+
return process.env[key] || defaultValue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
69
|
module.exports = EnvLoader;
|