@scaleway/sdk-vpcgw 1.0.1

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.
@@ -0,0 +1,440 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
3
+ const unmarshalDHCP = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'DHCP' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ address: data.address,
11
+ createdAt: unmarshalDate(data.created_at),
12
+ dnsLocalName: data.dns_local_name,
13
+ dnsSearch: data.dns_search,
14
+ dnsServersOverride: data.dns_servers_override,
15
+ enableDynamic: data.enable_dynamic,
16
+ id: data.id,
17
+ organizationId: data.organization_id,
18
+ poolHigh: data.pool_high,
19
+ poolLow: data.pool_low,
20
+ projectId: data.project_id,
21
+ pushDefaultRoute: data.push_default_route,
22
+ pushDnsServer: data.push_dns_server,
23
+ rebindTimer: data.rebind_timer,
24
+ renewTimer: data.renew_timer,
25
+ subnet: data.subnet,
26
+ updatedAt: unmarshalDate(data.updated_at),
27
+ validLifetime: data.valid_lifetime,
28
+ zone: data.zone
29
+ };
30
+ };
31
+ const unmarshalIpamConfig = (data) => {
32
+ if (!isJSONObject(data)) {
33
+ throw new TypeError(
34
+ `Unmarshalling the type 'IpamConfig' failed as data isn't a dictionary.`
35
+ );
36
+ }
37
+ return {
38
+ ipamIpId: data.ipam_ip_id,
39
+ pushDefaultRoute: data.push_default_route
40
+ };
41
+ };
42
+ const unmarshalGatewayNetwork = (data) => {
43
+ if (!isJSONObject(data)) {
44
+ throw new TypeError(
45
+ `Unmarshalling the type 'GatewayNetwork' failed as data isn't a dictionary.`
46
+ );
47
+ }
48
+ return {
49
+ address: data.address,
50
+ createdAt: unmarshalDate(data.created_at),
51
+ dhcp: data.dhcp ? unmarshalDHCP(data.dhcp) : void 0,
52
+ enableDhcp: data.enable_dhcp,
53
+ enableMasquerade: data.enable_masquerade,
54
+ gatewayId: data.gateway_id,
55
+ id: data.id,
56
+ ipamConfig: data.ipam_config ? unmarshalIpamConfig(data.ipam_config) : void 0,
57
+ macAddress: data.mac_address,
58
+ privateNetworkId: data.private_network_id,
59
+ status: data.status,
60
+ updatedAt: unmarshalDate(data.updated_at),
61
+ zone: data.zone
62
+ };
63
+ };
64
+ const unmarshalIP = (data) => {
65
+ if (!isJSONObject(data)) {
66
+ throw new TypeError(
67
+ `Unmarshalling the type 'IP' failed as data isn't a dictionary.`
68
+ );
69
+ }
70
+ return {
71
+ address: data.address,
72
+ createdAt: unmarshalDate(data.created_at),
73
+ gatewayId: data.gateway_id,
74
+ id: data.id,
75
+ organizationId: data.organization_id,
76
+ projectId: data.project_id,
77
+ reverse: data.reverse,
78
+ tags: data.tags,
79
+ updatedAt: unmarshalDate(data.updated_at),
80
+ zone: data.zone
81
+ };
82
+ };
83
+ const unmarshalDHCPEntry = (data) => {
84
+ if (!isJSONObject(data)) {
85
+ throw new TypeError(
86
+ `Unmarshalling the type 'DHCPEntry' failed as data isn't a dictionary.`
87
+ );
88
+ }
89
+ return {
90
+ createdAt: unmarshalDate(data.created_at),
91
+ gatewayNetworkId: data.gateway_network_id,
92
+ hostname: data.hostname,
93
+ id: data.id,
94
+ ipAddress: data.ip_address,
95
+ macAddress: data.mac_address,
96
+ type: data.type,
97
+ updatedAt: unmarshalDate(data.updated_at),
98
+ zone: data.zone
99
+ };
100
+ };
101
+ const unmarshalGatewayType = (data) => {
102
+ if (!isJSONObject(data)) {
103
+ throw new TypeError(
104
+ `Unmarshalling the type 'GatewayType' failed as data isn't a dictionary.`
105
+ );
106
+ }
107
+ return {
108
+ bandwidth: data.bandwidth,
109
+ name: data.name,
110
+ zone: data.zone
111
+ };
112
+ };
113
+ const unmarshalGateway = (data) => {
114
+ if (!isJSONObject(data)) {
115
+ throw new TypeError(
116
+ `Unmarshalling the type 'Gateway' failed as data isn't a dictionary.`
117
+ );
118
+ }
119
+ return {
120
+ bastionEnabled: data.bastion_enabled,
121
+ bastionPort: data.bastion_port,
122
+ canUpgradeTo: data.can_upgrade_to,
123
+ createdAt: unmarshalDate(data.created_at),
124
+ gatewayNetworks: unmarshalArrayOfObject(
125
+ data.gateway_networks,
126
+ unmarshalGatewayNetwork
127
+ ),
128
+ id: data.id,
129
+ ip: data.ip ? unmarshalIP(data.ip) : void 0,
130
+ ipMobilityEnabled: data.ip_mobility_enabled,
131
+ isLegacy: data.is_legacy,
132
+ name: data.name,
133
+ organizationId: data.organization_id,
134
+ projectId: data.project_id,
135
+ smtpEnabled: data.smtp_enabled,
136
+ status: data.status,
137
+ tags: data.tags,
138
+ type: data.type ? unmarshalGatewayType(data.type) : void 0,
139
+ updatedAt: unmarshalDate(data.updated_at),
140
+ upstreamDnsServers: data.upstream_dns_servers,
141
+ version: data.version,
142
+ zone: data.zone
143
+ };
144
+ };
145
+ const unmarshalPATRule = (data) => {
146
+ if (!isJSONObject(data)) {
147
+ throw new TypeError(
148
+ `Unmarshalling the type 'PATRule' failed as data isn't a dictionary.`
149
+ );
150
+ }
151
+ return {
152
+ createdAt: unmarshalDate(data.created_at),
153
+ gatewayId: data.gateway_id,
154
+ id: data.id,
155
+ privateIp: data.private_ip,
156
+ privatePort: data.private_port,
157
+ protocol: data.protocol,
158
+ publicPort: data.public_port,
159
+ updatedAt: unmarshalDate(data.updated_at),
160
+ zone: data.zone
161
+ };
162
+ };
163
+ const unmarshalListDHCPEntriesResponse = (data) => {
164
+ if (!isJSONObject(data)) {
165
+ throw new TypeError(
166
+ `Unmarshalling the type 'ListDHCPEntriesResponse' failed as data isn't a dictionary.`
167
+ );
168
+ }
169
+ return {
170
+ dhcpEntries: unmarshalArrayOfObject(data.dhcp_entries, unmarshalDHCPEntry),
171
+ totalCount: data.total_count
172
+ };
173
+ };
174
+ const unmarshalListDHCPsResponse = (data) => {
175
+ if (!isJSONObject(data)) {
176
+ throw new TypeError(
177
+ `Unmarshalling the type 'ListDHCPsResponse' failed as data isn't a dictionary.`
178
+ );
179
+ }
180
+ return {
181
+ dhcps: unmarshalArrayOfObject(data.dhcps, unmarshalDHCP),
182
+ totalCount: data.total_count
183
+ };
184
+ };
185
+ const unmarshalListGatewayNetworksResponse = (data) => {
186
+ if (!isJSONObject(data)) {
187
+ throw new TypeError(
188
+ `Unmarshalling the type 'ListGatewayNetworksResponse' failed as data isn't a dictionary.`
189
+ );
190
+ }
191
+ return {
192
+ gatewayNetworks: unmarshalArrayOfObject(
193
+ data.gateway_networks,
194
+ unmarshalGatewayNetwork
195
+ ),
196
+ totalCount: data.total_count
197
+ };
198
+ };
199
+ const unmarshalListGatewayTypesResponse = (data) => {
200
+ if (!isJSONObject(data)) {
201
+ throw new TypeError(
202
+ `Unmarshalling the type 'ListGatewayTypesResponse' failed as data isn't a dictionary.`
203
+ );
204
+ }
205
+ return {
206
+ types: unmarshalArrayOfObject(data.types, unmarshalGatewayType)
207
+ };
208
+ };
209
+ const unmarshalListGatewaysResponse = (data) => {
210
+ if (!isJSONObject(data)) {
211
+ throw new TypeError(
212
+ `Unmarshalling the type 'ListGatewaysResponse' failed as data isn't a dictionary.`
213
+ );
214
+ }
215
+ return {
216
+ gateways: unmarshalArrayOfObject(data.gateways, unmarshalGateway),
217
+ totalCount: data.total_count
218
+ };
219
+ };
220
+ const unmarshalListIPsResponse = (data) => {
221
+ if (!isJSONObject(data)) {
222
+ throw new TypeError(
223
+ `Unmarshalling the type 'ListIPsResponse' failed as data isn't a dictionary.`
224
+ );
225
+ }
226
+ return {
227
+ ips: unmarshalArrayOfObject(data.ips, unmarshalIP),
228
+ totalCount: data.total_count
229
+ };
230
+ };
231
+ const unmarshalListPATRulesResponse = (data) => {
232
+ if (!isJSONObject(data)) {
233
+ throw new TypeError(
234
+ `Unmarshalling the type 'ListPATRulesResponse' failed as data isn't a dictionary.`
235
+ );
236
+ }
237
+ return {
238
+ patRules: unmarshalArrayOfObject(data.pat_rules, unmarshalPATRule),
239
+ totalCount: data.total_count
240
+ };
241
+ };
242
+ const unmarshalSetDHCPEntriesResponse = (data) => {
243
+ if (!isJSONObject(data)) {
244
+ throw new TypeError(
245
+ `Unmarshalling the type 'SetDHCPEntriesResponse' failed as data isn't a dictionary.`
246
+ );
247
+ }
248
+ return {
249
+ dhcpEntries: unmarshalArrayOfObject(data.dhcp_entries, unmarshalDHCPEntry)
250
+ };
251
+ };
252
+ const unmarshalSetPATRulesResponse = (data) => {
253
+ if (!isJSONObject(data)) {
254
+ throw new TypeError(
255
+ `Unmarshalling the type 'SetPATRulesResponse' failed as data isn't a dictionary.`
256
+ );
257
+ }
258
+ return {
259
+ patRules: unmarshalArrayOfObject(data.pat_rules, unmarshalPATRule)
260
+ };
261
+ };
262
+ const marshalCreateDHCPRequest = (request, defaults) => ({
263
+ address: request.address,
264
+ dns_local_name: request.dnsLocalName,
265
+ dns_search: request.dnsSearch,
266
+ dns_servers_override: request.dnsServersOverride,
267
+ enable_dynamic: request.enableDynamic,
268
+ pool_high: request.poolHigh,
269
+ pool_low: request.poolLow,
270
+ project_id: request.projectId ?? defaults.defaultProjectId,
271
+ push_default_route: request.pushDefaultRoute,
272
+ push_dns_server: request.pushDnsServer,
273
+ rebind_timer: request.rebindTimer,
274
+ renew_timer: request.renewTimer,
275
+ subnet: request.subnet,
276
+ valid_lifetime: request.validLifetime
277
+ });
278
+ const marshalCreateDHCPEntryRequest = (request, defaults) => ({
279
+ gateway_network_id: request.gatewayNetworkId,
280
+ ip_address: request.ipAddress,
281
+ mac_address: request.macAddress
282
+ });
283
+ const marshalCreateGatewayNetworkRequestIpamConfig = (request, defaults) => ({
284
+ ipam_ip_id: request.ipamIpId,
285
+ push_default_route: request.pushDefaultRoute
286
+ });
287
+ const marshalCreateGatewayNetworkRequest = (request, defaults) => ({
288
+ enable_dhcp: request.enableDhcp,
289
+ enable_masquerade: request.enableMasquerade,
290
+ gateway_id: request.gatewayId,
291
+ private_network_id: request.privateNetworkId,
292
+ ...resolveOneOf([
293
+ { param: "dhcp_id", value: request.dhcpId },
294
+ {
295
+ param: "dhcp",
296
+ value: request.dhcp !== void 0 ? marshalCreateDHCPRequest(request.dhcp, defaults) : void 0
297
+ },
298
+ { param: "address", value: request.address },
299
+ {
300
+ param: "ipam_config",
301
+ value: request.ipamConfig !== void 0 ? marshalCreateGatewayNetworkRequestIpamConfig(
302
+ request.ipamConfig
303
+ ) : void 0
304
+ }
305
+ ])
306
+ });
307
+ const marshalCreateGatewayRequest = (request, defaults) => ({
308
+ bastion_port: request.bastionPort,
309
+ enable_bastion: request.enableBastion,
310
+ enable_smtp: request.enableSmtp,
311
+ ip_id: request.ipId,
312
+ name: request.name || randomName("gw"),
313
+ project_id: request.projectId ?? defaults.defaultProjectId,
314
+ tags: request.tags,
315
+ type: request.type,
316
+ upstream_dns_servers: request.upstreamDnsServers
317
+ });
318
+ const marshalCreateIPRequest = (request, defaults) => ({
319
+ project_id: request.projectId ?? defaults.defaultProjectId,
320
+ tags: request.tags
321
+ });
322
+ const marshalCreatePATRuleRequest = (request, defaults) => ({
323
+ gateway_id: request.gatewayId,
324
+ private_ip: request.privateIp,
325
+ private_port: request.privatePort,
326
+ protocol: request.protocol,
327
+ public_port: request.publicPort
328
+ });
329
+ const marshalSetDHCPEntriesRequestEntry = (request, defaults) => ({
330
+ ip_address: request.ipAddress,
331
+ mac_address: request.macAddress
332
+ });
333
+ const marshalSetDHCPEntriesRequest = (request, defaults) => ({
334
+ dhcp_entries: request.dhcpEntries !== void 0 ? request.dhcpEntries.map(
335
+ (elt) => marshalSetDHCPEntriesRequestEntry(elt)
336
+ ) : void 0,
337
+ gateway_network_id: request.gatewayNetworkId
338
+ });
339
+ const marshalSetPATRulesRequestRule = (request, defaults) => ({
340
+ private_ip: request.privateIp,
341
+ private_port: request.privatePort,
342
+ protocol: request.protocol,
343
+ public_port: request.publicPort
344
+ });
345
+ const marshalSetPATRulesRequest = (request, defaults) => ({
346
+ gateway_id: request.gatewayId,
347
+ pat_rules: request.patRules.map(
348
+ (elt) => marshalSetPATRulesRequestRule(elt)
349
+ )
350
+ });
351
+ const marshalUpdateDHCPEntryRequest = (request, defaults) => ({
352
+ ip_address: request.ipAddress
353
+ });
354
+ const marshalUpdateDHCPRequest = (request, defaults) => ({
355
+ address: request.address,
356
+ dns_local_name: request.dnsLocalName,
357
+ dns_search: request.dnsSearch,
358
+ dns_servers_override: request.dnsServersOverride,
359
+ enable_dynamic: request.enableDynamic,
360
+ pool_high: request.poolHigh,
361
+ pool_low: request.poolLow,
362
+ push_default_route: request.pushDefaultRoute,
363
+ push_dns_server: request.pushDnsServer,
364
+ rebind_timer: request.rebindTimer,
365
+ renew_timer: request.renewTimer,
366
+ subnet: request.subnet,
367
+ valid_lifetime: request.validLifetime
368
+ });
369
+ const marshalUpdateGatewayNetworkRequestIpamConfig = (request, defaults) => ({
370
+ ipam_ip_id: request.ipamIpId,
371
+ push_default_route: request.pushDefaultRoute
372
+ });
373
+ const marshalUpdateGatewayNetworkRequest = (request, defaults) => ({
374
+ enable_dhcp: request.enableDhcp,
375
+ enable_masquerade: request.enableMasquerade,
376
+ ...resolveOneOf([
377
+ { param: "dhcp_id", value: request.dhcpId },
378
+ { param: "address", value: request.address },
379
+ {
380
+ param: "ipam_config",
381
+ value: request.ipamConfig !== void 0 ? marshalUpdateGatewayNetworkRequestIpamConfig(
382
+ request.ipamConfig
383
+ ) : void 0
384
+ }
385
+ ])
386
+ });
387
+ const marshalUpdateGatewayRequest = (request, defaults) => ({
388
+ bastion_port: request.bastionPort,
389
+ enable_bastion: request.enableBastion,
390
+ enable_smtp: request.enableSmtp,
391
+ name: request.name,
392
+ tags: request.tags,
393
+ upstream_dns_servers: request.upstreamDnsServers
394
+ });
395
+ const marshalUpdateIPRequest = (request, defaults) => ({
396
+ gateway_id: request.gatewayId,
397
+ reverse: request.reverse,
398
+ tags: request.tags
399
+ });
400
+ const marshalUpdatePATRuleRequest = (request, defaults) => ({
401
+ private_ip: request.privateIp,
402
+ private_port: request.privatePort,
403
+ protocol: request.protocol,
404
+ public_port: request.publicPort
405
+ });
406
+ const marshalUpgradeGatewayRequest = (request, defaults) => ({
407
+ type: request.type
408
+ });
409
+ export {
410
+ marshalCreateDHCPEntryRequest,
411
+ marshalCreateDHCPRequest,
412
+ marshalCreateGatewayNetworkRequest,
413
+ marshalCreateGatewayRequest,
414
+ marshalCreateIPRequest,
415
+ marshalCreatePATRuleRequest,
416
+ marshalSetDHCPEntriesRequest,
417
+ marshalSetPATRulesRequest,
418
+ marshalUpdateDHCPEntryRequest,
419
+ marshalUpdateDHCPRequest,
420
+ marshalUpdateGatewayNetworkRequest,
421
+ marshalUpdateGatewayRequest,
422
+ marshalUpdateIPRequest,
423
+ marshalUpdatePATRuleRequest,
424
+ marshalUpgradeGatewayRequest,
425
+ unmarshalDHCP,
426
+ unmarshalDHCPEntry,
427
+ unmarshalGateway,
428
+ unmarshalGatewayNetwork,
429
+ unmarshalIP,
430
+ unmarshalListDHCPEntriesResponse,
431
+ unmarshalListDHCPsResponse,
432
+ unmarshalListGatewayNetworksResponse,
433
+ unmarshalListGatewayTypesResponse,
434
+ unmarshalListGatewaysResponse,
435
+ unmarshalListIPsResponse,
436
+ unmarshalListPATRulesResponse,
437
+ unmarshalPATRule,
438
+ unmarshalSetDHCPEntriesResponse,
439
+ unmarshalSetPATRulesResponse
440
+ };