@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,160 @@
1
+ /**
2
+ * Route Table Model
3
+ */
4
+
5
+ const { v4: uuidv4 } = require('uuid');
6
+
7
+ class Route {
8
+ constructor(destinationCidrBlock, target, targetType = 'local') {
9
+ this.DestinationCidrBlock = destinationCidrBlock;
10
+ this.State = 'active';
11
+ this.Origin = 'CreateRouteTable';
12
+ this.CreatedAt = new Date().toISOString();
13
+
14
+ // Set target based on type
15
+ switch (targetType) {
16
+ case 'local':
17
+ this.Target = 'local';
18
+ break;
19
+ case 'igw':
20
+ this.GatewayId = target;
21
+ this.Target = target;
22
+ break;
23
+ case 'nat':
24
+ this.NatGatewayId = target;
25
+ this.Target = target;
26
+ break;
27
+ case 'vpce':
28
+ this.VpcEndpointId = target;
29
+ this.Target = target;
30
+ break;
31
+ case 'instance':
32
+ this.InstanceId = target;
33
+ this.Target = target;
34
+ break;
35
+ case 'eni':
36
+ this.NetworkInterfaceId = target;
37
+ this.Target = target;
38
+ break;
39
+ default:
40
+ this.GatewayId = target;
41
+ this.Target = target;
42
+ }
43
+ }
44
+
45
+ toJSON() {
46
+ const result = {
47
+ DestinationCidrBlock: this.DestinationCidrBlock,
48
+ State: this.State,
49
+ Origin: this.Origin
50
+ };
51
+
52
+ if (this.GatewayId) result.GatewayId = this.GatewayId;
53
+ if (this.NatGatewayId) result.NatGatewayId = this.NatGatewayId;
54
+ if (this.VpcEndpointId) result.VpcEndpointId = this.VpcEndpointId;
55
+ if (this.InstanceId) result.InstanceId = this.InstanceId;
56
+ if (this.NetworkInterfaceId) result.NetworkInterfaceId = this.NetworkInterfaceId;
57
+
58
+ return result;
59
+ }
60
+ }
61
+
62
+ class RouteTableAssociation {
63
+ constructor(subnetId, routeTableId, isMain = false) {
64
+ this.RouteTableAssociationId = `rtbassoc-${uuidv4().substring(0, 8)}`;
65
+ this.SubnetId = subnetId;
66
+ this.RouteTableId = routeTableId;
67
+ this.Main = isMain;
68
+ this.CreatedAt = new Date().toISOString();
69
+ }
70
+
71
+ toJSON() {
72
+ return {
73
+ RouteTableAssociationId: this.RouteTableAssociationId,
74
+ SubnetId: this.SubnetId,
75
+ RouteTableId: this.RouteTableId,
76
+ Main: this.Main
77
+ };
78
+ }
79
+ }
80
+
81
+ class RouteTable {
82
+ constructor(vpcId, tags = [], isMain = false) {
83
+ this.RouteTableId = `rtb-${uuidv4().substring(0, 8)}`;
84
+ this.VpcId = vpcId;
85
+ this.Routes = [];
86
+ this.Associations = [];
87
+ this.Tags = tags;
88
+ this.IsMain = isMain;
89
+ this.State = 'active';
90
+ this.CreatedAt = new Date().toISOString();
91
+
92
+ // Local route é adicionada automaticamente
93
+ this.addLocalRoute(vpcId);
94
+ }
95
+
96
+ addLocalRoute(vpcCidr) {
97
+ const localRoute = new Route(vpcCidr, 'local', 'local');
98
+ this.Routes.push(localRoute);
99
+ }
100
+
101
+ addRoute(destinationCidrBlock, target, targetType = 'igw') {
102
+ // Verificar se rota já existe
103
+ const exists = this.Routes.some(r => r.DestinationCidrBlock === destinationCidrBlock);
104
+ if (exists) {
105
+ throw new Error(`Route with destination ${destinationCidrBlock} already exists`);
106
+ }
107
+
108
+ const route = new Route(destinationCidrBlock, target, targetType);
109
+ this.Routes.push(route);
110
+ return route;
111
+ }
112
+
113
+ removeRoute(destinationCidrBlock) {
114
+ const index = this.Routes.findIndex(r => r.DestinationCidrBlock === destinationCidrBlock);
115
+ if (index === -1) {
116
+ throw new Error(`Route with destination ${destinationCidrBlock} not found`);
117
+ }
118
+
119
+ const route = this.Routes[index];
120
+ this.Routes.splice(index, 1);
121
+ return route;
122
+ }
123
+
124
+ addAssociation(subnetId) {
125
+ const exists = this.Associations.some(a => a.SubnetId === subnetId);
126
+ if (exists) {
127
+ throw new Error(`Subnet ${subnetId} is already associated with this route table`);
128
+ }
129
+
130
+ const association = new RouteTableAssociation(subnetId, this.RouteTableId);
131
+ this.Associations.push(association);
132
+ return association;
133
+ }
134
+
135
+ removeAssociation(subnetId) {
136
+ const index = this.Associations.findIndex(a => a.SubnetId === subnetId);
137
+ if (index === -1) {
138
+ throw new Error(`Subnet ${subnetId} is not associated with this route table`);
139
+ }
140
+
141
+ const association = this.Associations[index];
142
+ this.Associations.splice(index, 1);
143
+ return association;
144
+ }
145
+
146
+ toJSON() {
147
+ return {
148
+ RouteTableId: this.RouteTableId,
149
+ VpcId: this.VpcId,
150
+ Routes: this.Routes.map(r => r.toJSON()),
151
+ Associations: this.Associations.map(a => a.toJSON()),
152
+ Tags: this.Tags,
153
+ IsMain: this.IsMain,
154
+ State: this.State,
155
+ CreatedAt: this.CreatedAt
156
+ };
157
+ }
158
+ }
159
+
160
+ module.exports = { RouteTable, Route, RouteTableAssociation };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Subnet Model
3
+ */
4
+
5
+ const { v4: uuidv4 } = require('uuid');
6
+
7
+ class Subnet {
8
+ constructor(vpcId, cidrBlock, availabilityZone, tags = [], config = {}) {
9
+ this.SubnetId = `subnet-${uuidv4().substring(0, 8)}`;
10
+ this.VpcId = vpcId;
11
+ this.CidrBlock = cidrBlock;
12
+ this.AvailabilityZone = availabilityZone;
13
+ this.State = 'available';
14
+ this.AvailableIpAddressCount = this.calculateAvailableIps(cidrBlock);
15
+ this.MapPublicIpOnLaunch = config.MapPublicIpOnLaunch || false;
16
+ this.Tags = tags;
17
+ this.CreatedAt = new Date().toISOString();
18
+ this.AssignIpv6AddressOnCreation = config.AssignIpv6AddressOnCreation || false;
19
+ }
20
+
21
+ calculateAvailableIps(cidrBlock) {
22
+ // Simples cálculo: /24 = 256 - 5 (reservados AWS) = 251
23
+ const parts = cidrBlock.split('/');
24
+ if (parts.length === 2) {
25
+ const prefixLength = parseInt(parts[1]);
26
+ const totalIps = Math.pow(2, 32 - prefixLength);
27
+ return Math.max(1, totalIps - 5); // AWS reserva 5 IPs
28
+ }
29
+ return 250;
30
+ }
31
+
32
+ toJSON() {
33
+ return {
34
+ SubnetId: this.SubnetId,
35
+ VpcId: this.VpcId,
36
+ CidrBlock: this.CidrBlock,
37
+ AvailabilityZone: this.AvailabilityZone,
38
+ State: this.State,
39
+ AvailableIpAddressCount: this.AvailableIpAddressCount,
40
+ MapPublicIpOnLaunch: this.MapPublicIpOnLaunch,
41
+ Tags: this.Tags,
42
+ CreatedAt: this.CreatedAt,
43
+ AssignIpv6AddressOnCreation: this.AssignIpv6AddressOnCreation
44
+ };
45
+ }
46
+ }
47
+
48
+ module.exports = Subnet;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * VPC Model
3
+ */
4
+
5
+ const { v4: uuidv4 } = require('uuid');
6
+
7
+ class VPC {
8
+ constructor(cidrBlock, tags = [], config = {}) {
9
+ this.VpcId = `vpc-${uuidv4().substring(0, 8)}`;
10
+ this.CidrBlock = cidrBlock;
11
+ this.State = 'available';
12
+ this.IsDefault = false;
13
+ this.Tags = tags;
14
+ this.CreatedAt = new Date().toISOString();
15
+ this.Ipv6CidrBlockAssociationSet = [];
16
+ this.EnableDnsHostnames = config.EnableDnsHostnames !== false;
17
+ this.EnableDnsSupport = config.EnableDnsSupport !== false;
18
+ this.InstanceTenancy = config.InstanceTenancy || 'default';
19
+ }
20
+
21
+ toJSON() {
22
+ return {
23
+ VpcId: this.VpcId,
24
+ CidrBlock: this.CidrBlock,
25
+ State: this.State,
26
+ IsDefault: this.IsDefault,
27
+ Tags: this.Tags,
28
+ CreatedAt: this.CreatedAt,
29
+ Ipv6CidrBlockAssociationSet: this.Ipv6CidrBlockAssociationSet,
30
+ EnableDnsHostnames: this.EnableDnsHostnames,
31
+ EnableDnsSupport: this.EnableDnsSupport,
32
+ InstanceTenancy: this.InstanceTenancy
33
+ };
34
+ }
35
+ }
36
+
37
+ module.exports = VPC;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * VPC Endpoint Model
3
+ */
4
+
5
+ const { v4: uuidv4 } = require('uuid');
6
+
7
+ class VPCEndpoint {
8
+ constructor(vpcId, serviceName, config = {}) {
9
+ this.VpcEndpointId = `vpce-${uuidv4().substring(0, 8)}`;
10
+ this.VpcId = vpcId;
11
+ this.ServiceName = serviceName;
12
+ this.VpcEndpointType = config.VpcEndpointType || 'Gateway';
13
+ this.State = 'available';
14
+ this.CreationTimestamp = new Date().toISOString();
15
+
16
+ // Para Gateway endpoints (S3, DynamoDB)
17
+ this.RouteTableIds = config.RouteTableIds || [];
18
+
19
+ // Para Interface endpoints
20
+ this.SubnetIds = config.SubnetIds || [];
21
+ this.SecurityGroupIds = config.SecurityGroupIds || [];
22
+ this.PrivateDnsEnabled = config.PrivateDnsEnabled || false;
23
+ this.NetworkInterfaceIds = config.NetworkInterfaceIds || [];
24
+
25
+ this.PolicyDocument = config.PolicyDocument || {
26
+ Statement: [
27
+ {
28
+ Effect: 'Allow',
29
+ Principal: '*',
30
+ Action: '*',
31
+ Resource: '*'
32
+ }
33
+ ]
34
+ };
35
+
36
+ this.Tags = config.Tags || [];
37
+ }
38
+
39
+ addRouteTable(routeTableId) {
40
+ if (!this.RouteTableIds.includes(routeTableId)) {
41
+ this.RouteTableIds.push(routeTableId);
42
+ }
43
+ }
44
+
45
+ removeRouteTable(routeTableId) {
46
+ const index = this.RouteTableIds.indexOf(routeTableId);
47
+ if (index > -1) {
48
+ this.RouteTableIds.splice(index, 1);
49
+ }
50
+ }
51
+
52
+ addSubnet(subnetId) {
53
+ if (!this.SubnetIds.includes(subnetId)) {
54
+ this.SubnetIds.push(subnetId);
55
+ }
56
+ }
57
+
58
+ removeSubnet(subnetId) {
59
+ const index = this.SubnetIds.indexOf(subnetId);
60
+ if (index > -1) {
61
+ this.SubnetIds.splice(index, 1);
62
+ }
63
+ }
64
+
65
+ getServiceType() {
66
+ if (this.ServiceName.includes('.s3')) return 'S3';
67
+ if (this.ServiceName.includes('.dynamodb')) return 'DynamoDB';
68
+ if (this.ServiceName.includes('.lambda')) return 'Lambda';
69
+ if (this.ServiceName.includes('.sqs')) return 'SQS';
70
+ if (this.ServiceName.includes('.sns')) return 'SNS';
71
+ if (this.ServiceName.includes('.ec2')) return 'EC2';
72
+ return 'Custom';
73
+ }
74
+
75
+ toJSON() {
76
+ const result = {
77
+ VpcEndpointId: this.VpcEndpointId,
78
+ VpcId: this.VpcId,
79
+ ServiceName: this.ServiceName,
80
+ VpcEndpointType: this.VpcEndpointType,
81
+ State: this.State,
82
+ CreationTimestamp: this.CreationTimestamp,
83
+ PolicyDocument: this.PolicyDocument,
84
+ Tags: this.Tags
85
+ };
86
+
87
+ if (this.VpcEndpointType === 'Gateway') {
88
+ result.RouteTableIds = this.RouteTableIds;
89
+ } else if (this.VpcEndpointType === 'Interface') {
90
+ result.SubnetIds = this.SubnetIds;
91
+ result.SecurityGroupIds = this.SecurityGroupIds;
92
+ result.PrivateDnsEnabled = this.PrivateDnsEnabled;
93
+ result.NetworkInterfaceIds = this.NetworkInterfaceIds;
94
+ }
95
+
96
+ return result;
97
+ }
98
+ }
99
+
100
+ module.exports = VPCEndpoint;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * VPC Gateway Model (NAT Gateway, Customer Gateway, etc)
3
+ */
4
+
5
+ const { v4: uuidv4 } = require('uuid');
6
+
7
+ class NATGateway {
8
+ constructor(subnetId, allocationId, config = {}) {
9
+ this.NatGatewayId = `natgw-${uuidv4().substring(0, 8)}`;
10
+ this.SubnetId = subnetId;
11
+ this.AllocationId = allocationId;
12
+ this.PublicIp = config.PublicIp || `192.0.2.${Math.floor(Math.random() * 256)}`;
13
+ this.PrivateIp = config.PrivateIp || null;
14
+ this.State = 'available';
15
+ this.CreateTime = new Date().toISOString();
16
+ this.Tags = config.Tags || [];
17
+ }
18
+
19
+ toJSON() {
20
+ return {
21
+ NatGatewayId: this.NatGatewayId,
22
+ SubnetId: this.SubnetId,
23
+ AllocationId: this.AllocationId,
24
+ PublicIp: this.PublicIp,
25
+ PrivateIp: this.PrivateIp,
26
+ State: this.State,
27
+ CreateTime: this.CreateTime,
28
+ Tags: this.Tags
29
+ };
30
+ }
31
+ }
32
+
33
+ class CustomerGateway {
34
+ constructor(type, bgpAsn, config = {}) {
35
+ this.CustomerGatewayId = `cgw-${uuidv4().substring(0, 8)}`;
36
+ this.Type = type; // ipsec.1
37
+ this.BgpAsn = bgpAsn;
38
+ this.IpAddress = config.IpAddress || null;
39
+ this.State = 'available';
40
+ this.CreateTime = new Date().toISOString();
41
+ this.Tags = config.Tags || [];
42
+ }
43
+
44
+ toJSON() {
45
+ return {
46
+ CustomerGatewayId: this.CustomerGatewayId,
47
+ Type: this.Type,
48
+ BgpAsn: this.BgpAsn,
49
+ IpAddress: this.IpAddress,
50
+ State: this.State,
51
+ CreateTime: this.CreateTime,
52
+ Tags: this.Tags
53
+ };
54
+ }
55
+ }
56
+
57
+ class VpnGateway {
58
+ constructor(type, config = {}) {
59
+ this.VpnGatewayId = `vgw-${uuidv4().substring(0, 8)}`;
60
+ this.Type = type; // ipsec.1
61
+ this.State = 'available';
62
+ this.VpcAttachments = config.VpcAttachments || [];
63
+ this.CreateTime = new Date().toISOString();
64
+ this.Tags = config.Tags || [];
65
+ }
66
+
67
+ attachToVpc(vpcId) {
68
+ const exists = this.VpcAttachments.some(a => a.VpcId === vpcId);
69
+ if (exists) {
70
+ throw new Error(`VPN Gateway already attached to VPC ${vpcId}`);
71
+ }
72
+
73
+ this.VpcAttachments.push({
74
+ VpcId: vpcId,
75
+ State: 'attached'
76
+ });
77
+ }
78
+
79
+ detachFromVpc(vpcId) {
80
+ const index = this.VpcAttachments.findIndex(a => a.VpcId === vpcId);
81
+ if (index === -1) {
82
+ throw new Error(`VPN Gateway not attached to VPC ${vpcId}`);
83
+ }
84
+
85
+ this.VpcAttachments.splice(index, 1);
86
+ }
87
+
88
+ toJSON() {
89
+ return {
90
+ VpnGatewayId: this.VpnGatewayId,
91
+ Type: this.Type,
92
+ State: this.State,
93
+ VpcAttachments: this.VpcAttachments,
94
+ CreateTime: this.CreateTime,
95
+ Tags: this.Tags
96
+ };
97
+ }
98
+ }
99
+
100
+ class VpnConnection {
101
+ constructor(type, customerGatewayId, vpnGatewayId, config = {}) {
102
+ this.VpnConnectionId = `vpn-${uuidv4().substring(0, 8)}`;
103
+ this.Type = type; // ipsec.1
104
+ this.CustomerGatewayId = customerGatewayId;
105
+ this.VpnGatewayId = vpnGatewayId;
106
+ this.State = 'available';
107
+ this.Options = config.Options || {
108
+ StaticRoutesOnly: false,
109
+ TunnelOptions: []
110
+ };
111
+ this.CreateTime = new Date().toISOString();
112
+ this.Tags = config.Tags || [];
113
+ }
114
+
115
+ toJSON() {
116
+ return {
117
+ VpnConnectionId: this.VpnConnectionId,
118
+ Type: this.Type,
119
+ CustomerGatewayId: this.CustomerGatewayId,
120
+ VpnGatewayId: this.VpnGatewayId,
121
+ State: this.State,
122
+ Options: this.Options,
123
+ CreateTime: this.CreateTime,
124
+ Tags: this.Tags
125
+ };
126
+ }
127
+ }
128
+
129
+ module.exports = {
130
+ NATGateway,
131
+ CustomerGateway,
132
+ VpnGateway,
133
+ VpnConnection
134
+ };