@gugananuvem/aws-local-simulator 1.0.35 → 1.0.39

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 (149) hide show
  1. package/README.md +662 -658
  2. package/package.json +10 -3
  3. package/src/config/default-config.js +71 -0
  4. package/src/config/env-loader.js +4 -2
  5. package/src/middleware/authorization.js +271 -0
  6. package/src/middleware/cloudtrail-logger.js +333 -0
  7. package/src/middleware/error-handler.js +138 -0
  8. package/src/middleware/index.js +79 -0
  9. package/src/middleware/policy-enforcement.js +407 -0
  10. package/src/server.js +74 -4
  11. package/src/services/acm/index.js +66 -0
  12. package/src/services/acm/models/certificate.js +202 -0
  13. package/src/services/acm/server.js +224 -0
  14. package/src/services/acm/simulator.js +293 -0
  15. package/src/services/alb/index.js +104 -0
  16. package/src/services/alb/models/loadBalancer.js +88 -0
  17. package/src/services/alb/models/targetGroup.js +128 -0
  18. package/src/services/alb/server.js +160 -0
  19. package/src/services/alb/simulator.js +262 -0
  20. package/src/services/apigateway/index.js +22 -0
  21. package/src/services/apigateway/server.js +247 -35
  22. package/src/services/apigateway/simulator.js +780 -26
  23. package/src/services/asg/index.js +100 -0
  24. package/src/services/asg/models/autoScalingGroup.js +110 -0
  25. package/src/services/asg/models/launchTemplate.js +41 -0
  26. package/src/services/asg/models/scalingPolicy.js +51 -0
  27. package/src/services/asg/server.js +236 -0
  28. package/src/services/asg/simulator.js +410 -0
  29. package/src/services/aurora/cluster-manager.js +731 -0
  30. package/src/services/aurora/data-api.js +514 -0
  31. package/src/services/aurora/db-engine.js +270 -0
  32. package/src/services/aurora/index.js +159 -0
  33. package/src/services/aurora/rds-api.js +189 -0
  34. package/src/services/aurora/server.js +213 -0
  35. package/src/services/aurora/sql-translator.js +334 -0
  36. package/src/services/cloudformation/index.js +2 -2
  37. package/src/services/cloudformation/server.js +1 -0
  38. package/src/services/cloudfront/cache-engine.js +225 -0
  39. package/src/services/cloudfront/geo-restrictions.js +377 -0
  40. package/src/services/cloudfront/index.js +220 -0
  41. package/src/services/cloudfront/models/behavior.js +158 -0
  42. package/src/services/cloudfront/models/distribution.js +284 -0
  43. package/src/services/cloudfront/models/index.js +99 -0
  44. package/src/services/cloudfront/models/invalidation.js +109 -0
  45. package/src/services/cloudfront/models/origin.js +155 -0
  46. package/src/services/cloudfront/origin-router.js +552 -0
  47. package/src/services/cloudfront/origin-validator.js +398 -0
  48. package/src/services/cloudfront/server.js +512 -0
  49. package/src/services/cloudfront/signed-url-generator.js +377 -0
  50. package/src/services/cloudfront/simulator.js +425 -0
  51. package/src/services/cloudfront/store.js +326 -0
  52. package/src/services/cloudshell/env-builder.js +27 -0
  53. package/src/services/cloudshell/index.js +48 -0
  54. package/src/services/cloudshell/routes.js +60 -0
  55. package/src/services/cloudshell/session-manager.js +226 -0
  56. package/src/services/cloudshell/static/.gitkeep +0 -0
  57. package/src/services/cloudshell/static/index.html +406 -0
  58. package/src/services/cloudshell/websocket-handler.js +107 -0
  59. package/src/services/cloudtrail/index.js +2 -3
  60. package/src/services/cloudtrail/server.js +68 -0
  61. package/src/services/cognito/server.js +4 -1
  62. package/src/services/dynamodb/server.js +4 -1
  63. package/src/services/dynamodb/simulator.js +2 -1
  64. package/src/services/ec2/index.js +101 -0
  65. package/src/services/ec2/instanceServer.js +311 -0
  66. package/src/services/ec2/models/ami.js +39 -0
  67. package/src/services/ec2/models/instance.js +98 -0
  68. package/src/services/ec2/models/networkInterface.js +74 -0
  69. package/src/services/ec2/models/securityGroup.js +71 -0
  70. package/src/services/ec2/server.js +350 -0
  71. package/src/services/ec2/simulator.js +436 -0
  72. package/src/services/eventbridge/server.js +36 -0
  73. package/src/services/eventbridge/simulator.js +230 -45
  74. package/src/services/iam/index.js +65 -0
  75. package/src/services/iam/middleware.js +99 -0
  76. package/src/services/iam/server.js +331 -0
  77. package/src/services/iam/simulator.js +1432 -0
  78. package/src/services/index.js +28 -0
  79. package/src/services/kinesis-analytics/index.js +105 -0
  80. package/src/services/kinesis-analytics/models/application.js +325 -0
  81. package/src/services/kinesis-analytics/models/index.js +12 -0
  82. package/src/services/kinesis-analytics/server.js +250 -0
  83. package/src/services/kinesis-analytics/simulator.js +407 -0
  84. package/src/services/kinesis-analytics/store.js +176 -0
  85. package/src/services/kinesis-data-streams/index.js +106 -0
  86. package/src/services/kinesis-data-streams/models/index.js +12 -0
  87. package/src/services/kinesis-data-streams/models/record.js +70 -0
  88. package/src/services/kinesis-data-streams/models/stream.js +280 -0
  89. package/src/services/kinesis-data-streams/server.js +255 -0
  90. package/src/services/kinesis-data-streams/simulator.js +514 -0
  91. package/src/services/kinesis-data-streams/store.js +163 -0
  92. package/src/services/kinesis-firehose/index.js +106 -0
  93. package/src/services/kinesis-firehose/models/delivery-stream.js +265 -0
  94. package/src/services/kinesis-firehose/models/index.js +10 -0
  95. package/src/services/kinesis-firehose/server.js +215 -0
  96. package/src/services/kinesis-firehose/simulator.js +388 -0
  97. package/src/services/kinesis-firehose/store.js +163 -0
  98. package/src/services/kms/server.js +4 -1
  99. package/src/services/lambda/index.js +26 -0
  100. package/src/services/lambda/server.js +12 -1
  101. package/src/services/lambda/simulator.js +4 -0
  102. package/src/services/opensearch/index.js +105 -0
  103. package/src/services/opensearch/models/document.js +115 -0
  104. package/src/services/opensearch/models/index.js +73 -0
  105. package/src/services/opensearch/server.js +310 -0
  106. package/src/services/opensearch/simulator.js +605 -0
  107. package/src/services/opensearch/store.js +162 -0
  108. package/src/services/organizations/control-tower-simulator.js +321 -0
  109. package/src/services/organizations/control-tower-store.js +182 -0
  110. package/src/services/organizations/iam-integration.js +413 -0
  111. package/src/services/organizations/index.js +172 -0
  112. package/src/services/organizations/models/index.js +13 -0
  113. package/src/services/organizations/models/invitation.js +48 -0
  114. package/src/services/organizations/models/organization.js +566 -0
  115. package/src/services/organizations/models/role.js +244 -0
  116. package/src/services/organizations/models/scp.js +131 -0
  117. package/src/services/organizations/server.js +736 -0
  118. package/src/services/organizations/simulator.js +593 -0
  119. package/src/services/organizations/store.js +235 -0
  120. package/src/services/organizations/vpc-integration.js +453 -0
  121. package/src/services/route53/index.js +67 -0
  122. package/src/services/route53/models/healthCheck.js +101 -0
  123. package/src/services/route53/models/hostedZone.js +37 -0
  124. package/src/services/route53/models/resourceRecord.js +106 -0
  125. package/src/services/route53/server.js +841 -0
  126. package/src/services/route53/simulator.js +350 -0
  127. package/src/services/s3/index.js +62 -0
  128. package/src/services/s3/presigned-url-generator.js +337 -0
  129. package/src/services/s3/server.js +231 -0
  130. package/src/services/s3/simulator.js +551 -4
  131. package/src/services/sns/index.js +31 -0
  132. package/src/services/sns/server.js +9 -0
  133. package/src/services/sqs/index.js +38 -0
  134. package/src/services/sqs/server.js +57 -4
  135. package/src/services/sqs/simulator.js +423 -33
  136. package/src/services/sts/simulator.js +209 -17
  137. package/src/services/vpc/README.md +459 -0
  138. package/src/services/vpc/ec2ResponseFormatter.js +431 -0
  139. package/src/services/vpc/index.js +90 -0
  140. package/src/services/vpc/models/internetGateway.js +71 -0
  141. package/src/services/vpc/models/routeTable.js +160 -0
  142. package/src/services/vpc/models/subnet.js +48 -0
  143. package/src/services/vpc/models/vpc.js +37 -0
  144. package/src/services/vpc/models/vpcEndpoint.js +100 -0
  145. package/src/services/vpc/models/vpcGateway.js +134 -0
  146. package/src/services/vpc/server.js +836 -0
  147. package/src/services/vpc/simulator.js +613 -0
  148. package/src/utils/policy-cache.js +215 -0
  149. package/aws-config +0 -154
@@ -0,0 +1,244 @@
1
+ /**
2
+ * AWS Organizations - Role Model
3
+ * Integração com IAM para gerenciar roles em contas diferentes
4
+ */
5
+
6
+ const { v4: uuidv4 } = require('uuid');
7
+
8
+ class OrganizationRole {
9
+ constructor(roleName, trustPolicy, config = {}) {
10
+ this.id = uuidv4().substring(0, 8);
11
+ this.name = roleName;
12
+ this.arn = `arn:aws:iam::${config.accountId || '123456789012'}:role/${roleName}`;
13
+ this.pathPrefix = config.pathPrefix || '/';
14
+
15
+ // Trust Policy (AssumeRolePolicyDocument)
16
+ this.trustPolicy = trustPolicy;
17
+
18
+ // Policies inline
19
+ this.inlinePolicies = new Map();
20
+
21
+ // Managed policies anexadas
22
+ this.managedPolicies = [];
23
+
24
+ // Metadados
25
+ this.createdAt = new Date().toISOString();
26
+ this.lastModifiedAt = new Date().toISOString();
27
+ this.accountId = config.accountId || '123456789012';
28
+ this.maxSessionDuration = config.maxSessionDuration || 3600;
29
+ this.description = config.description || '';
30
+
31
+ // Permissões efetivas calculadas
32
+ this.effectivePermissions = new Map();
33
+ }
34
+
35
+ /**
36
+ * Adiciona uma inline policy
37
+ */
38
+ putInlinePolicy(policyName, policyDocument) {
39
+ this.inlinePolicies.set(policyName, {
40
+ name: policyName,
41
+ document: policyDocument,
42
+ createdAt: new Date().toISOString()
43
+ });
44
+
45
+ this.lastModifiedAt = new Date().toISOString();
46
+ this.recalculateEffectivePermissions();
47
+
48
+ return true;
49
+ }
50
+
51
+ /**
52
+ * Remove uma inline policy
53
+ */
54
+ deleteInlinePolicy(policyName) {
55
+ const deleted = this.inlinePolicies.delete(policyName);
56
+
57
+ if (deleted) {
58
+ this.lastModifiedAt = new Date().toISOString();
59
+ this.recalculateEffectivePermissions();
60
+ }
61
+
62
+ return deleted;
63
+ }
64
+
65
+ /**
66
+ * Obtém inline policy
67
+ */
68
+ getInlinePolicy(policyName) {
69
+ return this.inlinePolicies.get(policyName);
70
+ }
71
+
72
+ /**
73
+ * Lista inline policies
74
+ */
75
+ listInlinePolicies() {
76
+ return Array.from(this.inlinePolicies.values());
77
+ }
78
+
79
+ /**
80
+ * Anexa managed policy
81
+ */
82
+ attachManagedPolicy(policyArn) {
83
+ if (!this.managedPolicies.includes(policyArn)) {
84
+ this.managedPolicies.push(policyArn);
85
+ this.lastModifiedAt = new Date().toISOString();
86
+ this.recalculateEffectivePermissions();
87
+ }
88
+
89
+ return true;
90
+ }
91
+
92
+ /**
93
+ * Desanexa managed policy
94
+ */
95
+ detachManagedPolicy(policyArn) {
96
+ const index = this.managedPolicies.indexOf(policyArn);
97
+
98
+ if (index > -1) {
99
+ this.managedPolicies.splice(index, 1);
100
+ this.lastModifiedAt = new Date().toISOString();
101
+ this.recalculateEffectivePermissions();
102
+ return true;
103
+ }
104
+
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Lista managed policies
110
+ */
111
+ listManagedPolicies() {
112
+ return this.managedPolicies;
113
+ }
114
+
115
+ /**
116
+ * Atualiza trust policy
117
+ */
118
+ updateTrustPolicy(newTrustPolicy) {
119
+ this.trustPolicy = newTrustPolicy;
120
+ this.lastModifiedAt = new Date().toISOString();
121
+ }
122
+
123
+ /**
124
+ * Calcula permissões efetivas combinando inline + managed
125
+ */
126
+ recalculateEffectivePermissions() {
127
+ this.effectivePermissions.clear();
128
+
129
+ // Processa inline policies
130
+ for (const [policyName, policy] of this.inlinePolicies) {
131
+ if (policy.document && policy.document.Statement) {
132
+ for (const statement of policy.document.Statement) {
133
+ this.addStatementToEffectivePermissions(statement);
134
+ }
135
+ }
136
+ }
137
+
138
+ // Managed policies seriam processadas aqui se disponíveis
139
+ // Por enquanto apenas rastreamos os ARNs
140
+ }
141
+
142
+ /**
143
+ * Adiciona statement às permissões efetivas
144
+ */
145
+ addStatementToEffectivePermissions(statement) {
146
+ if (!statement.Action) return;
147
+
148
+ const actions = Array.isArray(statement.Action) ? statement.Action : [statement.Action];
149
+ const resources = Array.isArray(statement.Resource) ? statement.Resource : [statement.Resource || '*'];
150
+
151
+ for (const action of actions) {
152
+ for (const resource of resources) {
153
+ const key = `${action}:${resource}`;
154
+ this.effectivePermissions.set(key, {
155
+ action,
156
+ resource,
157
+ effect: statement.Effect,
158
+ condition: statement.Condition
159
+ });
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Verifica se uma ação é permitida
166
+ */
167
+ canPerformAction(action, resource = '*') {
168
+ // Verifica inline policies
169
+ for (const [policyName, policy] of this.inlinePolicies) {
170
+ if (policy.document && policy.document.Statement) {
171
+ for (const statement of policy.document.Statement) {
172
+ if (this.matchesStatement(statement, action, resource)) {
173
+ if (statement.Effect === 'Allow') {
174
+ return true;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ return false;
182
+ }
183
+
184
+ /**
185
+ * Verifica se um statement match
186
+ */
187
+ matchesStatement(statement, action, resource) {
188
+ if (!statement.Action) return false;
189
+
190
+ const actions = Array.isArray(statement.Action) ? statement.Action : [statement.Action];
191
+ const resources = Array.isArray(statement.Resource) ? statement.Resource : [statement.Resource || '*'];
192
+
193
+ const actionMatch = actions.some(a => this.matchesWildcard(a, action));
194
+ const resourceMatch = resources.some(r => this.matchesWildcard(r, resource));
195
+
196
+ return actionMatch && resourceMatch;
197
+ }
198
+
199
+ /**
200
+ * Suporta wildcards
201
+ */
202
+ matchesWildcard(pattern, value) {
203
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
204
+ return regex.test(value);
205
+ }
206
+
207
+ /**
208
+ * Assume role - valida trust policy
209
+ */
210
+ canAssumeRole(principalArn, principalType = 'AWS') {
211
+ if (!this.trustPolicy || !this.trustPolicy.Statement) {
212
+ return false;
213
+ }
214
+
215
+ for (const statement of this.trustPolicy.Statement) {
216
+ if (statement.Effect !== 'Allow') continue;
217
+ if (statement.Principal?.AWS && this.matchesWildcard(statement.Principal.AWS, principalArn)) {
218
+ return true;
219
+ }
220
+ if (statement.Principal === '*') {
221
+ return true;
222
+ }
223
+ }
224
+
225
+ return false;
226
+ }
227
+
228
+ toJSON() {
229
+ return {
230
+ id: this.id,
231
+ name: this.name,
232
+ arn: this.arn,
233
+ accountId: this.accountId,
234
+ createdAt: this.createdAt,
235
+ lastModifiedAt: this.lastModifiedAt,
236
+ inlinePoliciesCount: this.inlinePolicies.size,
237
+ managedPoliciesCount: this.managedPolicies.length,
238
+ maxSessionDuration: this.maxSessionDuration,
239
+ description: this.description
240
+ };
241
+ }
242
+ }
243
+
244
+ module.exports = OrganizationRole;
@@ -0,0 +1,131 @@
1
+ /**
2
+ * AWS Organizations - SCP (Service Control Policy) Model
3
+ * Gerencia policies de controle de serviços com suporte a Allow/Deny
4
+ */
5
+
6
+ const { v4: uuidv4 } = require('uuid');
7
+
8
+ class ServiceControlPolicy {
9
+ constructor(name, document, config = {}) {
10
+ this.id = uuidv4().substring(0, 8);
11
+ this.name = name;
12
+ this.document = document; // JSON policy document
13
+ this.type = 'SERVICE_CONTROL_POLICY';
14
+ this.status = 'ACTIVE';
15
+ this.createdAt = new Date().toISOString();
16
+ this.lastModifiedAt = new Date().toISOString();
17
+
18
+ // Targets (OUs, Accounts)
19
+ this.targets = [];
20
+
21
+ // Metadados
22
+ this.awsManaged = config.awsManaged || false;
23
+ this.customerManaged = !this.awsManaged;
24
+ this.policyArn = `arn:aws:organizations::123456789012:policy/o-xxxxxxxxxx/service_control_policy/p-${this.id}`;
25
+ }
26
+
27
+ /**
28
+ * Valida se uma ação é permitida por esta policy
29
+ */
30
+ evaluateAction(action, resource = '*') {
31
+ if (!this.document || !this.document.Statement) {
32
+ return true; // Nenhuma restrição
33
+ }
34
+
35
+ // Processa statements na ordem
36
+ for (const statement of this.document.Statement) {
37
+ if (this.matchesStatement(statement, action, resource)) {
38
+ // Se Effect é Deny, a ação é bloqueada
39
+ if (statement.Effect === 'Deny') {
40
+ return false;
41
+ }
42
+ // Se Effect é Allow, a ação é permitida
43
+ if (statement.Effect === 'Allow') {
44
+ return true;
45
+ }
46
+ }
47
+ }
48
+
49
+ // Se não encontrou Deny, é permitido por padrão
50
+ return true;
51
+ }
52
+
53
+ /**
54
+ * Verifica se um statement match com a ação
55
+ */
56
+ matchesStatement(statement, action, resource) {
57
+ // Verifica Action
58
+ if (!this.matchesPattern(statement.Action, action)) {
59
+ return false;
60
+ }
61
+
62
+ // Verifica Resource (se especificado)
63
+ if (statement.Resource && !this.matchesPattern(statement.Resource, resource)) {
64
+ return false;
65
+ }
66
+
67
+ // Verifica Condition (se especificado)
68
+ if (statement.Condition && !this.evaluateCondition(statement.Condition)) {
69
+ return false;
70
+ }
71
+
72
+ return true;
73
+ }
74
+
75
+ /**
76
+ * Verifica se um padrão match com um valor
77
+ */
78
+ matchesPattern(pattern, value) {
79
+ if (!pattern) return true;
80
+
81
+ if (typeof pattern === 'string') {
82
+ return this.matchesWildcard(pattern, value);
83
+ }
84
+
85
+ if (Array.isArray(pattern)) {
86
+ return pattern.some(p => this.matchesWildcard(p, value));
87
+ }
88
+
89
+ return false;
90
+ }
91
+
92
+ /**
93
+ * Suporta wildcards: * e ?
94
+ */
95
+ matchesWildcard(pattern, value) {
96
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
97
+ return regex.test(value);
98
+ }
99
+
100
+ /**
101
+ * Avalia condições (versão simplificada)
102
+ */
103
+ evaluateCondition(condition) {
104
+ // Suporte básico a StringEquals, StringLike, etc
105
+ return true; // Por enquanto aceita tudo
106
+ }
107
+
108
+ /**
109
+ * Atualiza o documento da policy
110
+ */
111
+ updateDocument(newDocument) {
112
+ this.document = newDocument;
113
+ this.lastModifiedAt = new Date().toISOString();
114
+ }
115
+
116
+ toJSON() {
117
+ return {
118
+ id: this.id,
119
+ name: this.name,
120
+ type: this.type,
121
+ status: this.status,
122
+ createdAt: this.createdAt,
123
+ lastModifiedAt: this.lastModifiedAt,
124
+ awsManaged: this.awsManaged,
125
+ targetCount: this.targets.length,
126
+ statementCount: this.document?.Statement?.length || 0
127
+ };
128
+ }
129
+ }
130
+
131
+ module.exports = ServiceControlPolicy;