@scaleway/sdk-container 1.2.0

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,501 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
3
+ const unmarshalContainerHealthCheckSpecHTTPProbe = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'ContainerHealthCheckSpecHTTPProbe' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ path: data.path
11
+ };
12
+ };
13
+ const unmarshalContainerHealthCheckSpecTCPProbe = (data) => {
14
+ if (!isJSONObject(data)) {
15
+ throw new TypeError(
16
+ `Unmarshalling the type 'ContainerHealthCheckSpecTCPProbe' failed as data isn't a dictionary.`
17
+ );
18
+ }
19
+ return {};
20
+ };
21
+ const unmarshalContainerHealthCheckSpec = (data) => {
22
+ if (!isJSONObject(data)) {
23
+ throw new TypeError(
24
+ `Unmarshalling the type 'ContainerHealthCheckSpec' failed as data isn't a dictionary.`
25
+ );
26
+ }
27
+ return {
28
+ failureThreshold: data.failure_threshold,
29
+ http: data.http ? unmarshalContainerHealthCheckSpecHTTPProbe(data.http) : void 0,
30
+ interval: data.interval,
31
+ tcp: data.tcp ? unmarshalContainerHealthCheckSpecTCPProbe(data.tcp) : void 0
32
+ };
33
+ };
34
+ const unmarshalContainerScalingOption = (data) => {
35
+ if (!isJSONObject(data)) {
36
+ throw new TypeError(
37
+ `Unmarshalling the type 'ContainerScalingOption' failed as data isn't a dictionary.`
38
+ );
39
+ }
40
+ return {
41
+ concurrentRequestsThreshold: data.concurrent_requests_threshold,
42
+ cpuUsageThreshold: data.cpu_usage_threshold,
43
+ memoryUsageThreshold: data.memory_usage_threshold
44
+ };
45
+ };
46
+ const unmarshalSecretHashedValue = (data) => {
47
+ if (!isJSONObject(data)) {
48
+ throw new TypeError(
49
+ `Unmarshalling the type 'SecretHashedValue' failed as data isn't a dictionary.`
50
+ );
51
+ }
52
+ return {
53
+ hashedValue: data.hashed_value,
54
+ key: data.key
55
+ };
56
+ };
57
+ const unmarshalContainer = (data) => {
58
+ if (!isJSONObject(data)) {
59
+ throw new TypeError(
60
+ `Unmarshalling the type 'Container' failed as data isn't a dictionary.`
61
+ );
62
+ }
63
+ return {
64
+ cpuLimit: data.cpu_limit,
65
+ createdAt: unmarshalDate(data.created_at),
66
+ description: data.description,
67
+ domainName: data.domain_name,
68
+ environmentVariables: data.environment_variables,
69
+ errorMessage: data.error_message,
70
+ healthCheck: data.health_check ? unmarshalContainerHealthCheckSpec(data.health_check) : void 0,
71
+ httpOption: data.http_option,
72
+ id: data.id,
73
+ localStorageLimit: data.local_storage_limit,
74
+ maxConcurrency: data.max_concurrency,
75
+ maxScale: data.max_scale,
76
+ memoryLimit: data.memory_limit,
77
+ minScale: data.min_scale,
78
+ name: data.name,
79
+ namespaceId: data.namespace_id,
80
+ port: data.port,
81
+ privacy: data.privacy,
82
+ protocol: data.protocol,
83
+ readyAt: unmarshalDate(data.ready_at),
84
+ region: data.region,
85
+ registryImage: data.registry_image,
86
+ sandbox: data.sandbox,
87
+ scalingOption: data.scaling_option ? unmarshalContainerScalingOption(data.scaling_option) : void 0,
88
+ secretEnvironmentVariables: unmarshalArrayOfObject(
89
+ data.secret_environment_variables,
90
+ unmarshalSecretHashedValue
91
+ ),
92
+ status: data.status,
93
+ tags: data.tags,
94
+ timeout: data.timeout,
95
+ updatedAt: unmarshalDate(data.updated_at)
96
+ };
97
+ };
98
+ const unmarshalCron = (data) => {
99
+ if (!isJSONObject(data)) {
100
+ throw new TypeError(
101
+ `Unmarshalling the type 'Cron' failed as data isn't a dictionary.`
102
+ );
103
+ }
104
+ return {
105
+ args: data.args,
106
+ containerId: data.container_id,
107
+ id: data.id,
108
+ name: data.name,
109
+ schedule: data.schedule,
110
+ status: data.status
111
+ };
112
+ };
113
+ const unmarshalDomain = (data) => {
114
+ if (!isJSONObject(data)) {
115
+ throw new TypeError(
116
+ `Unmarshalling the type 'Domain' failed as data isn't a dictionary.`
117
+ );
118
+ }
119
+ return {
120
+ containerId: data.container_id,
121
+ errorMessage: data.error_message,
122
+ hostname: data.hostname,
123
+ id: data.id,
124
+ status: data.status,
125
+ url: data.url
126
+ };
127
+ };
128
+ const unmarshalNamespace = (data) => {
129
+ if (!isJSONObject(data)) {
130
+ throw new TypeError(
131
+ `Unmarshalling the type 'Namespace' failed as data isn't a dictionary.`
132
+ );
133
+ }
134
+ return {
135
+ createdAt: unmarshalDate(data.created_at),
136
+ description: data.description,
137
+ environmentVariables: data.environment_variables,
138
+ errorMessage: data.error_message,
139
+ id: data.id,
140
+ name: data.name,
141
+ organizationId: data.organization_id,
142
+ projectId: data.project_id,
143
+ region: data.region,
144
+ registryEndpoint: data.registry_endpoint,
145
+ registryNamespaceId: data.registry_namespace_id,
146
+ secretEnvironmentVariables: unmarshalArrayOfObject(
147
+ data.secret_environment_variables,
148
+ unmarshalSecretHashedValue
149
+ ),
150
+ status: data.status,
151
+ tags: data.tags,
152
+ updatedAt: unmarshalDate(data.updated_at)
153
+ };
154
+ };
155
+ const unmarshalToken = (data) => {
156
+ if (!isJSONObject(data)) {
157
+ throw new TypeError(
158
+ `Unmarshalling the type 'Token' failed as data isn't a dictionary.`
159
+ );
160
+ }
161
+ return {
162
+ containerId: data.container_id,
163
+ description: data.description,
164
+ expiresAt: unmarshalDate(data.expires_at),
165
+ id: data.id,
166
+ namespaceId: data.namespace_id,
167
+ publicKey: data.public_key,
168
+ status: data.status,
169
+ token: data.token
170
+ };
171
+ };
172
+ const unmarshalTriggerMnqNatsClientConfig = (data) => {
173
+ if (!isJSONObject(data)) {
174
+ throw new TypeError(
175
+ `Unmarshalling the type 'TriggerMnqNatsClientConfig' failed as data isn't a dictionary.`
176
+ );
177
+ }
178
+ return {
179
+ mnqCredentialId: data.mnq_credential_id,
180
+ mnqNatsAccountId: data.mnq_nats_account_id,
181
+ mnqProjectId: data.mnq_project_id,
182
+ mnqRegion: data.mnq_region,
183
+ subject: data.subject
184
+ };
185
+ };
186
+ const unmarshalTriggerMnqSqsClientConfig = (data) => {
187
+ if (!isJSONObject(data)) {
188
+ throw new TypeError(
189
+ `Unmarshalling the type 'TriggerMnqSqsClientConfig' failed as data isn't a dictionary.`
190
+ );
191
+ }
192
+ return {
193
+ mnqCredentialId: data.mnq_credential_id,
194
+ mnqProjectId: data.mnq_project_id,
195
+ mnqRegion: data.mnq_region,
196
+ queue: data.queue
197
+ };
198
+ };
199
+ const unmarshalTriggerSqsClientConfig = (data) => {
200
+ if (!isJSONObject(data)) {
201
+ throw new TypeError(
202
+ `Unmarshalling the type 'TriggerSqsClientConfig' failed as data isn't a dictionary.`
203
+ );
204
+ }
205
+ return {
206
+ accessKey: data.access_key,
207
+ endpoint: data.endpoint,
208
+ queueUrl: data.queue_url,
209
+ secretKey: data.secret_key
210
+ };
211
+ };
212
+ const unmarshalTrigger = (data) => {
213
+ if (!isJSONObject(data)) {
214
+ throw new TypeError(
215
+ `Unmarshalling the type 'Trigger' failed as data isn't a dictionary.`
216
+ );
217
+ }
218
+ return {
219
+ containerId: data.container_id,
220
+ description: data.description,
221
+ errorMessage: data.error_message,
222
+ id: data.id,
223
+ inputType: data.input_type,
224
+ name: data.name,
225
+ scwNatsConfig: data.scw_nats_config ? unmarshalTriggerMnqNatsClientConfig(data.scw_nats_config) : void 0,
226
+ scwSqsConfig: data.scw_sqs_config ? unmarshalTriggerMnqSqsClientConfig(data.scw_sqs_config) : void 0,
227
+ sqsConfig: data.sqs_config ? unmarshalTriggerSqsClientConfig(data.sqs_config) : void 0,
228
+ status: data.status
229
+ };
230
+ };
231
+ const unmarshalListContainersResponse = (data) => {
232
+ if (!isJSONObject(data)) {
233
+ throw new TypeError(
234
+ `Unmarshalling the type 'ListContainersResponse' failed as data isn't a dictionary.`
235
+ );
236
+ }
237
+ return {
238
+ containers: unmarshalArrayOfObject(data.containers, unmarshalContainer),
239
+ totalCount: data.total_count
240
+ };
241
+ };
242
+ const unmarshalListCronsResponse = (data) => {
243
+ if (!isJSONObject(data)) {
244
+ throw new TypeError(
245
+ `Unmarshalling the type 'ListCronsResponse' failed as data isn't a dictionary.`
246
+ );
247
+ }
248
+ return {
249
+ crons: unmarshalArrayOfObject(data.crons, unmarshalCron),
250
+ totalCount: data.total_count
251
+ };
252
+ };
253
+ const unmarshalListDomainsResponse = (data) => {
254
+ if (!isJSONObject(data)) {
255
+ throw new TypeError(
256
+ `Unmarshalling the type 'ListDomainsResponse' failed as data isn't a dictionary.`
257
+ );
258
+ }
259
+ return {
260
+ domains: unmarshalArrayOfObject(data.domains, unmarshalDomain),
261
+ totalCount: data.total_count
262
+ };
263
+ };
264
+ const unmarshalListNamespacesResponse = (data) => {
265
+ if (!isJSONObject(data)) {
266
+ throw new TypeError(
267
+ `Unmarshalling the type 'ListNamespacesResponse' failed as data isn't a dictionary.`
268
+ );
269
+ }
270
+ return {
271
+ namespaces: unmarshalArrayOfObject(data.namespaces, unmarshalNamespace),
272
+ totalCount: data.total_count
273
+ };
274
+ };
275
+ const unmarshalListTokensResponse = (data) => {
276
+ if (!isJSONObject(data)) {
277
+ throw new TypeError(
278
+ `Unmarshalling the type 'ListTokensResponse' failed as data isn't a dictionary.`
279
+ );
280
+ }
281
+ return {
282
+ tokens: unmarshalArrayOfObject(data.tokens, unmarshalToken),
283
+ totalCount: data.total_count
284
+ };
285
+ };
286
+ const unmarshalListTriggersResponse = (data) => {
287
+ if (!isJSONObject(data)) {
288
+ throw new TypeError(
289
+ `Unmarshalling the type 'ListTriggersResponse' failed as data isn't a dictionary.`
290
+ );
291
+ }
292
+ return {
293
+ totalCount: data.total_count,
294
+ triggers: unmarshalArrayOfObject(data.triggers, unmarshalTrigger)
295
+ };
296
+ };
297
+ const marshalContainerHealthCheckSpecHTTPProbe = (request, defaults) => ({
298
+ path: request.path
299
+ });
300
+ const marshalContainerHealthCheckSpecTCPProbe = (request, defaults) => ({});
301
+ const marshalContainerHealthCheckSpec = (request, defaults) => ({
302
+ failure_threshold: request.failureThreshold,
303
+ interval: request.interval,
304
+ ...resolveOneOf([
305
+ {
306
+ param: "http",
307
+ value: request.http !== void 0 ? marshalContainerHealthCheckSpecHTTPProbe(request.http) : void 0
308
+ },
309
+ {
310
+ param: "tcp",
311
+ value: request.tcp !== void 0 ? marshalContainerHealthCheckSpecTCPProbe(request.tcp) : void 0
312
+ }
313
+ ])
314
+ });
315
+ const marshalContainerScalingOption = (request, defaults) => ({
316
+ ...resolveOneOf([
317
+ {
318
+ param: "concurrent_requests_threshold",
319
+ value: request.concurrentRequestsThreshold
320
+ },
321
+ { param: "cpu_usage_threshold", value: request.cpuUsageThreshold },
322
+ { param: "memory_usage_threshold", value: request.memoryUsageThreshold }
323
+ ])
324
+ });
325
+ const marshalSecret = (request, defaults) => ({
326
+ key: request.key,
327
+ value: request.value
328
+ });
329
+ const marshalCreateContainerRequest = (request, defaults) => ({
330
+ cpu_limit: request.cpuLimit,
331
+ description: request.description,
332
+ environment_variables: request.environmentVariables,
333
+ health_check: request.healthCheck !== void 0 ? marshalContainerHealthCheckSpec(request.healthCheck) : void 0,
334
+ http_option: request.httpOption,
335
+ local_storage_limit: request.localStorageLimit,
336
+ max_concurrency: request.maxConcurrency,
337
+ max_scale: request.maxScale,
338
+ memory_limit: request.memoryLimit,
339
+ min_scale: request.minScale,
340
+ name: request.name,
341
+ namespace_id: request.namespaceId,
342
+ port: request.port,
343
+ privacy: request.privacy,
344
+ protocol: request.protocol,
345
+ registry_image: request.registryImage,
346
+ sandbox: request.sandbox,
347
+ scaling_option: request.scalingOption !== void 0 ? marshalContainerScalingOption(request.scalingOption) : void 0,
348
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
349
+ (elt) => marshalSecret(elt)
350
+ ) : void 0,
351
+ tags: request.tags,
352
+ timeout: request.timeout
353
+ });
354
+ const marshalCreateCronRequest = (request, defaults) => ({
355
+ args: request.args,
356
+ container_id: request.containerId,
357
+ name: request.name,
358
+ schedule: request.schedule
359
+ });
360
+ const marshalCreateDomainRequest = (request, defaults) => ({
361
+ container_id: request.containerId,
362
+ hostname: request.hostname
363
+ });
364
+ const marshalCreateNamespaceRequest = (request, defaults) => ({
365
+ description: request.description,
366
+ environment_variables: request.environmentVariables,
367
+ name: request.name || randomName("cns"),
368
+ project_id: request.projectId ?? defaults.defaultProjectId,
369
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
370
+ (elt) => marshalSecret(elt)
371
+ ) : void 0,
372
+ tags: request.tags
373
+ });
374
+ const marshalCreateTokenRequest = (request, defaults) => ({
375
+ description: request.description,
376
+ expires_at: request.expiresAt,
377
+ ...resolveOneOf([
378
+ { param: "container_id", value: request.containerId },
379
+ { param: "namespace_id", value: request.namespaceId }
380
+ ])
381
+ });
382
+ const marshalCreateTriggerRequestMnqNatsClientConfig = (request, defaults) => ({
383
+ mnq_nats_account_id: request.mnqNatsAccountId,
384
+ mnq_project_id: request.mnqProjectId,
385
+ mnq_region: request.mnqRegion,
386
+ subject: request.subject
387
+ });
388
+ const marshalCreateTriggerRequestMnqSqsClientConfig = (request, defaults) => ({
389
+ mnq_project_id: request.mnqProjectId,
390
+ mnq_region: request.mnqRegion,
391
+ queue: request.queue
392
+ });
393
+ const marshalCreateTriggerRequestSqsClientConfig = (request, defaults) => ({
394
+ access_key: request.accessKey,
395
+ endpoint: request.endpoint,
396
+ queue_url: request.queueUrl,
397
+ secret_key: request.secretKey
398
+ });
399
+ const marshalCreateTriggerRequest = (request, defaults) => ({
400
+ container_id: request.containerId,
401
+ description: request.description,
402
+ name: request.name,
403
+ ...resolveOneOf([
404
+ {
405
+ param: "scw_sqs_config",
406
+ value: request.scwSqsConfig !== void 0 ? marshalCreateTriggerRequestMnqSqsClientConfig(
407
+ request.scwSqsConfig
408
+ ) : void 0
409
+ },
410
+ {
411
+ param: "scw_nats_config",
412
+ value: request.scwNatsConfig !== void 0 ? marshalCreateTriggerRequestMnqNatsClientConfig(
413
+ request.scwNatsConfig
414
+ ) : void 0
415
+ },
416
+ {
417
+ param: "sqs_config",
418
+ value: request.sqsConfig !== void 0 ? marshalCreateTriggerRequestSqsClientConfig(
419
+ request.sqsConfig
420
+ ) : void 0
421
+ }
422
+ ])
423
+ });
424
+ const marshalUpdateContainerRequest = (request, defaults) => ({
425
+ cpu_limit: request.cpuLimit,
426
+ description: request.description,
427
+ environment_variables: request.environmentVariables,
428
+ health_check: request.healthCheck !== void 0 ? marshalContainerHealthCheckSpec(request.healthCheck) : void 0,
429
+ http_option: request.httpOption,
430
+ local_storage_limit: request.localStorageLimit,
431
+ max_concurrency: request.maxConcurrency,
432
+ max_scale: request.maxScale,
433
+ memory_limit: request.memoryLimit,
434
+ min_scale: request.minScale,
435
+ port: request.port,
436
+ privacy: request.privacy,
437
+ protocol: request.protocol,
438
+ redeploy: request.redeploy,
439
+ registry_image: request.registryImage,
440
+ sandbox: request.sandbox,
441
+ scaling_option: request.scalingOption !== void 0 ? marshalContainerScalingOption(request.scalingOption) : void 0,
442
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
443
+ (elt) => marshalSecret(elt)
444
+ ) : void 0,
445
+ tags: request.tags,
446
+ timeout: request.timeout
447
+ });
448
+ const marshalUpdateCronRequest = (request, defaults) => ({
449
+ args: request.args,
450
+ container_id: request.containerId,
451
+ name: request.name,
452
+ schedule: request.schedule
453
+ });
454
+ const marshalUpdateNamespaceRequest = (request, defaults) => ({
455
+ description: request.description,
456
+ environment_variables: request.environmentVariables,
457
+ secret_environment_variables: request.secretEnvironmentVariables !== void 0 ? request.secretEnvironmentVariables.map(
458
+ (elt) => marshalSecret(elt)
459
+ ) : void 0,
460
+ tags: request.tags
461
+ });
462
+ const marshalUpdateTriggerRequestSqsClientConfig = (request, defaults) => ({
463
+ access_key: request.accessKey,
464
+ secret_key: request.secretKey
465
+ });
466
+ const marshalUpdateTriggerRequest = (request, defaults) => ({
467
+ description: request.description,
468
+ name: request.name,
469
+ ...resolveOneOf([
470
+ {
471
+ param: "sqs_config",
472
+ value: request.sqsConfig !== void 0 ? marshalUpdateTriggerRequestSqsClientConfig(
473
+ request.sqsConfig
474
+ ) : void 0
475
+ }
476
+ ])
477
+ });
478
+ export {
479
+ marshalCreateContainerRequest,
480
+ marshalCreateCronRequest,
481
+ marshalCreateDomainRequest,
482
+ marshalCreateNamespaceRequest,
483
+ marshalCreateTokenRequest,
484
+ marshalCreateTriggerRequest,
485
+ marshalUpdateContainerRequest,
486
+ marshalUpdateCronRequest,
487
+ marshalUpdateNamespaceRequest,
488
+ marshalUpdateTriggerRequest,
489
+ unmarshalContainer,
490
+ unmarshalCron,
491
+ unmarshalDomain,
492
+ unmarshalListContainersResponse,
493
+ unmarshalListCronsResponse,
494
+ unmarshalListDomainsResponse,
495
+ unmarshalListNamespacesResponse,
496
+ unmarshalListTokensResponse,
497
+ unmarshalListTriggersResponse,
498
+ unmarshalNamespace,
499
+ unmarshalToken,
500
+ unmarshalTrigger
501
+ };