-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapi.py
More file actions
2030 lines (1771 loc) · 65.9 KB
/
api.py
File metadata and controls
2030 lines (1771 loc) · 65.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from datetime import datetime
from typing import Any, Awaitable, Optional, Union
from scaleway_core.api import API
from scaleway_core.bridge import (
Region as ScwRegion,
)
from scaleway_core.utils import (
OneOfPossibility,
WaitForOptions,
random_name,
resolve_one_of,
validate_path_param,
fetch_all_pages_async,
wait_for_resource_async,
)
from .types import (
FunctionHttpOption,
FunctionPrivacy,
FunctionRuntime,
FunctionSandbox,
ListCronsRequestOrderBy,
ListDomainsRequestOrderBy,
ListFunctionsRequestOrderBy,
ListNamespacesRequestOrderBy,
ListTokensRequestOrderBy,
ListTriggersRequestOrderBy,
CreateCronRequest,
CreateDomainRequest,
CreateFunctionRequest,
CreateNamespaceRequest,
CreateTokenRequest,
CreateTriggerRequest,
CreateTriggerRequestMnqNatsClientConfig,
CreateTriggerRequestMnqSqsClientConfig,
CreateTriggerRequestSqsClientConfig,
Cron,
Domain,
DownloadURL,
Function,
ListCronsResponse,
ListDomainsResponse,
ListFunctionRuntimesResponse,
ListFunctionsResponse,
ListNamespacesResponse,
ListTokensResponse,
ListTriggersResponse,
Namespace,
Secret,
Token,
Trigger,
UpdateCronRequest,
UpdateFunctionRequest,
UpdateNamespaceRequest,
UpdateTriggerRequest,
UpdateTriggerRequestSqsClientConfig,
UploadURL,
)
from .content import (
CRON_TRANSIENT_STATUSES,
DOMAIN_TRANSIENT_STATUSES,
FUNCTION_TRANSIENT_STATUSES,
NAMESPACE_TRANSIENT_STATUSES,
TOKEN_TRANSIENT_STATUSES,
TRIGGER_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Cron,
unmarshal_Domain,
unmarshal_Function,
unmarshal_Namespace,
unmarshal_Token,
unmarshal_Trigger,
unmarshal_DownloadURL,
unmarshal_ListCronsResponse,
unmarshal_ListDomainsResponse,
unmarshal_ListFunctionRuntimesResponse,
unmarshal_ListFunctionsResponse,
unmarshal_ListNamespacesResponse,
unmarshal_ListTokensResponse,
unmarshal_ListTriggersResponse,
unmarshal_UploadURL,
marshal_CreateCronRequest,
marshal_CreateDomainRequest,
marshal_CreateFunctionRequest,
marshal_CreateNamespaceRequest,
marshal_CreateTokenRequest,
marshal_CreateTriggerRequest,
marshal_UpdateCronRequest,
marshal_UpdateFunctionRequest,
marshal_UpdateNamespaceRequest,
marshal_UpdateTriggerRequest,
)
class FunctionV1Beta1API(API):
"""
This API allows you to manage your Serverless Functions.
"""
async def list_namespaces(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListNamespacesRequestOrderBy] = None,
name: Optional[str] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
) -> ListNamespacesResponse:
"""
List all your namespaces.
List all existing namespaces in the specified region.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number.
:param page_size: Number of namespaces per page.
:param order_by: Order of the namespaces.
:param name: Name of the namespace.
:param organization_id: UUID of the Organization the namespace belongs to.
:param project_id: UUID of the Project the namespace belongs to.
:return: :class:`ListNamespacesResponse <ListNamespacesResponse>`
Usage:
::
result = await api.list_namespaces()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/namespaces",
params={
"name": name,
"order_by": order_by,
"organization_id": organization_id
or self.client.default_organization_id,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_ListNamespacesResponse(res.json())
async def list_namespaces_all(
self,
*,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListNamespacesRequestOrderBy] = None,
name: Optional[str] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
) -> list[Namespace]:
"""
List all your namespaces.
List all existing namespaces in the specified region.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number.
:param page_size: Number of namespaces per page.
:param order_by: Order of the namespaces.
:param name: Name of the namespace.
:param organization_id: UUID of the Organization the namespace belongs to.
:param project_id: UUID of the Project the namespace belongs to.
:return: :class:`list[Namespace] <list[Namespace]>`
Usage:
::
result = await api.list_namespaces_all()
"""
return await fetch_all_pages_async(
type=ListNamespacesResponse,
key="namespaces",
fetcher=self.list_namespaces,
args={
"region": region,
"page": page,
"page_size": page_size,
"order_by": order_by,
"name": name,
"organization_id": organization_id,
"project_id": project_id,
},
)
async def get_namespace(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
) -> Namespace:
"""
Get a namespace.
Get the namespace associated with the specified ID.
:param namespace_id: UUID of the namespace.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Namespace <Namespace>`
Usage:
::
result = await api.get_namespace(
namespace_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_namespace_id = validate_path_param("namespace_id", namespace_id)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/namespaces/{param_namespace_id}",
)
self._throw_on_error(res)
return unmarshal_Namespace(res.json())
async def wait_for_namespace(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
options: Optional[
WaitForOptions[Namespace, Union[bool, Awaitable[bool]]]
] = None,
) -> Namespace:
"""
Get a namespace.
Get the namespace associated with the specified ID.
:param namespace_id: UUID of the namespace.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Namespace <Namespace>`
Usage:
::
result = await api.get_namespace(
namespace_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in NAMESPACE_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_namespace,
options=options,
args={
"namespace_id": namespace_id,
"region": region,
},
)
async def create_namespace(
self,
*,
region: Optional[ScwRegion] = None,
name: Optional[str] = None,
environment_variables: Optional[dict[str, str]] = None,
project_id: Optional[str] = None,
description: Optional[str] = None,
secret_environment_variables: Optional[list[Secret]] = None,
tags: Optional[list[str]] = None,
activate_vpc_integration: Optional[bool] = None,
) -> Namespace:
"""
Create a new namespace.
Create a new namespace in a specified Organization or Project.
:param region: Region to target. If none is passed will use default region from the config.
:param name:
:param environment_variables: Environment variables of the namespace.
:param project_id: UUID of the project in which the namespace will be created.
:param description: Description of the namespace.
:param secret_environment_variables: Secret environment variables of the namespace.
:param tags: Tags of the Serverless Function Namespace.
:param activate_vpc_integration: Setting this field to true doesn't matter anymore. It will be removed in a near future.
:return: :class:`Namespace <Namespace>`
Usage:
::
result = await api.create_namespace()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"POST",
f"/functions/v1beta1/regions/{param_region}/namespaces",
body=marshal_CreateNamespaceRequest(
CreateNamespaceRequest(
region=region,
name=name or random_name(prefix="ns"),
environment_variables=environment_variables,
project_id=project_id,
description=description,
secret_environment_variables=secret_environment_variables,
tags=tags,
activate_vpc_integration=activate_vpc_integration,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Namespace(res.json())
async def update_namespace(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
environment_variables: Optional[dict[str, str]] = None,
description: Optional[str] = None,
secret_environment_variables: Optional[list[Secret]] = None,
tags: Optional[list[str]] = None,
) -> Namespace:
"""
Update an existing namespace.
Update the namespace associated with the specified ID.
:param namespace_id: UUID of the namespapce.
:param region: Region to target. If none is passed will use default region from the config.
:param environment_variables: Environment variables of the namespace.
:param description: Description of the namespace.
:param secret_environment_variables: Secret environment variables of the namespace.
:param tags: Tags of the Serverless Function Namespace.
:return: :class:`Namespace <Namespace>`
Usage:
::
result = await api.update_namespace(
namespace_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_namespace_id = validate_path_param("namespace_id", namespace_id)
res = self._request(
"PATCH",
f"/functions/v1beta1/regions/{param_region}/namespaces/{param_namespace_id}",
body=marshal_UpdateNamespaceRequest(
UpdateNamespaceRequest(
namespace_id=namespace_id,
region=region,
environment_variables=environment_variables,
description=description,
secret_environment_variables=secret_environment_variables,
tags=tags,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Namespace(res.json())
async def delete_namespace(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
) -> Namespace:
"""
Delete an existing namespace.
Delete the namespace associated with the specified ID.
:param namespace_id: UUID of the namespace.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Namespace <Namespace>`
Usage:
::
result = await api.delete_namespace(
namespace_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_namespace_id = validate_path_param("namespace_id", namespace_id)
res = self._request(
"DELETE",
f"/functions/v1beta1/regions/{param_region}/namespaces/{param_namespace_id}",
)
self._throw_on_error(res)
return unmarshal_Namespace(res.json())
async def list_functions(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListFunctionsRequestOrderBy] = None,
name: Optional[str] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
) -> ListFunctionsResponse:
"""
List all your functions.
:param namespace_id: UUID of the namespace the function belongs to.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number.
:param page_size: Number of functions per page.
:param order_by: Order of the functions.
:param name: Name of the function.
:param organization_id: UUID of the Organization the function belongs to.
:param project_id: UUID of the Project the function belongs to.
:return: :class:`ListFunctionsResponse <ListFunctionsResponse>`
Usage:
::
result = await api.list_functions(
namespace_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/functions",
params={
"name": name,
"namespace_id": namespace_id,
"order_by": order_by,
"organization_id": organization_id
or self.client.default_organization_id,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
},
)
self._throw_on_error(res)
return unmarshal_ListFunctionsResponse(res.json())
async def list_functions_all(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListFunctionsRequestOrderBy] = None,
name: Optional[str] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
) -> list[Function]:
"""
List all your functions.
:param namespace_id: UUID of the namespace the function belongs to.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number.
:param page_size: Number of functions per page.
:param order_by: Order of the functions.
:param name: Name of the function.
:param organization_id: UUID of the Organization the function belongs to.
:param project_id: UUID of the Project the function belongs to.
:return: :class:`list[Function] <list[Function]>`
Usage:
::
result = await api.list_functions_all(
namespace_id="example",
)
"""
return await fetch_all_pages_async(
type=ListFunctionsResponse,
key="functions",
fetcher=self.list_functions,
args={
"namespace_id": namespace_id,
"region": region,
"page": page,
"page_size": page_size,
"order_by": order_by,
"name": name,
"organization_id": organization_id,
"project_id": project_id,
},
)
async def get_function(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
) -> Function:
"""
Get a function.
Get the function associated with the specified ID.
:param function_id: UUID of the function.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Function <Function>`
Usage:
::
result = await api.get_function(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}",
)
self._throw_on_error(res)
return unmarshal_Function(res.json())
async def wait_for_function(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
options: Optional[
WaitForOptions[Function, Union[bool, Awaitable[bool]]]
] = None,
) -> Function:
"""
Get a function.
Get the function associated with the specified ID.
:param function_id: UUID of the function.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Function <Function>`
Usage:
::
result = await api.get_function(
function_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in FUNCTION_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_function,
options=options,
args={
"function_id": function_id,
"region": region,
},
)
async def create_function(
self,
*,
namespace_id: str,
region: Optional[ScwRegion] = None,
name: Optional[str] = None,
environment_variables: Optional[dict[str, str]] = None,
min_scale: Optional[int] = None,
max_scale: Optional[int] = None,
runtime: Optional[FunctionRuntime] = None,
memory_limit: Optional[int] = None,
timeout: Optional[str] = None,
handler: Optional[str] = None,
privacy: Optional[FunctionPrivacy] = None,
description: Optional[str] = None,
secret_environment_variables: Optional[list[Secret]] = None,
http_option: Optional[FunctionHttpOption] = None,
sandbox: Optional[FunctionSandbox] = None,
tags: Optional[list[str]] = None,
private_network_id: Optional[str] = None,
) -> Function:
"""
Create a new function.
Create a new function in the specified region for a specified Organization or Project.
:param namespace_id: UUID of the namespace the function will be created in.
:param region: Region to target. If none is passed will use default region from the config.
:param name: Name of the function to create.
:param environment_variables: Environment variables of the function.
:param min_scale: Minimum number of instances to scale the function to.
:param max_scale: Maximum number of instances to scale the function to.
:param runtime: Runtime to use with the function.
:param memory_limit: Memory limit of the function in MB.
:param timeout: Request processing time limit for the function.
:param handler: Handler to use with the function.
:param privacy: Privacy setting of the function.
:param description: Description of the function.
:param secret_environment_variables:
:param http_option: Possible values:
- redirected: Responds to HTTP request with a 301 redirect to ask the clients to use HTTPS.
- enabled: Serve both HTTP and HTTPS traffic.
:param sandbox: Execution environment of the function.
:param tags: Tags of the Serverless Function.
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
:return: :class:`Function <Function>`
Usage:
::
result = await api.create_function(
namespace_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"POST",
f"/functions/v1beta1/regions/{param_region}/functions",
body=marshal_CreateFunctionRequest(
CreateFunctionRequest(
namespace_id=namespace_id,
region=region,
name=name or random_name(prefix="fn"),
environment_variables=environment_variables,
min_scale=min_scale,
max_scale=max_scale,
runtime=runtime,
memory_limit=memory_limit,
timeout=timeout,
handler=handler,
privacy=privacy,
description=description,
secret_environment_variables=secret_environment_variables,
http_option=http_option,
sandbox=sandbox,
tags=tags,
private_network_id=private_network_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Function(res.json())
async def update_function(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
environment_variables: Optional[dict[str, str]] = None,
min_scale: Optional[int] = None,
max_scale: Optional[int] = None,
runtime: Optional[FunctionRuntime] = None,
memory_limit: Optional[int] = None,
timeout: Optional[str] = None,
redeploy: Optional[bool] = None,
handler: Optional[str] = None,
privacy: Optional[FunctionPrivacy] = None,
description: Optional[str] = None,
secret_environment_variables: Optional[list[Secret]] = None,
http_option: Optional[FunctionHttpOption] = None,
sandbox: Optional[FunctionSandbox] = None,
tags: Optional[list[str]] = None,
private_network_id: Optional[str] = None,
) -> Function:
"""
Update an existing function.
Update the function associated with the specified ID.
When updating a function, the function is automatically redeployed to apply the changes.
This behavior can be changed by setting the `redeploy` field to `false` in the request.
:param function_id: UUID of the function to update.
:param region: Region to target. If none is passed will use default region from the config.
:param environment_variables: Environment variables of the function to update.
:param min_scale: Minimum number of instances to scale the function to.
:param max_scale: Maximum number of instances to scale the function to.
:param runtime: Runtime to use with the function.
:param memory_limit: Memory limit of the function in MB.
:param timeout: Processing time limit for the function.
:param redeploy: Redeploy failed function.
:param handler: Handler to use with the function.
:param privacy: Privacy setting of the function.
:param description: Description of the function.
:param secret_environment_variables: During an update, secret environment variables that are not specified in this field will be kept unchanged.
In order to delete a specific secret environment variable, you must reference its key, but not provide any value for it.
For example, the following payload will delete the `TO_DELETE` secret environment variable:
```json
{
"secret_environment_variables":[
{"key":"TO_DELETE"}
]
}
```.
:param http_option: Possible values:
- redirected: Responds to HTTP request with a 301 redirect to ask the clients to use HTTPS.
- enabled: Serve both HTTP and HTTPS traffic.
:param sandbox: Execution environment of the function.
:param tags: Tags of the Serverless Function.
:param private_network_id: When connected to a Private Network, the function can access other Scaleway resources in this Private Network.
:return: :class:`Function <Function>`
Usage:
::
result = await api.update_function(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"PATCH",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}",
body=marshal_UpdateFunctionRequest(
UpdateFunctionRequest(
function_id=function_id,
region=region,
environment_variables=environment_variables,
min_scale=min_scale,
max_scale=max_scale,
runtime=runtime,
memory_limit=memory_limit,
timeout=timeout,
redeploy=redeploy,
handler=handler,
privacy=privacy,
description=description,
secret_environment_variables=secret_environment_variables,
http_option=http_option,
sandbox=sandbox,
tags=tags,
private_network_id=private_network_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Function(res.json())
async def delete_function(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
) -> Function:
"""
Delete a function.
Delete the function associated with the specified ID.
:param function_id: UUID of the function to delete.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Function <Function>`
Usage:
::
result = await api.delete_function(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"DELETE",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}",
)
self._throw_on_error(res)
return unmarshal_Function(res.json())
async def deploy_function(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
) -> Function:
"""
Deploy a function.
Deploy a function associated with the specified ID.
:param function_id: UUID of the function to deploy.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Function <Function>`
Usage:
::
result = await api.deploy_function(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"POST",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}/deploy",
body={},
)
self._throw_on_error(res)
return unmarshal_Function(res.json())
async def list_function_runtimes(
self,
*,
region: Optional[ScwRegion] = None,
) -> ListFunctionRuntimesResponse:
"""
List function runtimes.
List available function runtimes.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`ListFunctionRuntimesResponse <ListFunctionRuntimesResponse>`
Usage:
::
result = await api.list_function_runtimes()
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/runtimes",
)
self._throw_on_error(res)
return unmarshal_ListFunctionRuntimesResponse(res.json())
async def get_function_upload_url(
self,
*,
function_id: str,
content_length: int,
region: Optional[ScwRegion] = None,
) -> UploadURL:
"""
Get an upload URL of a function.
Get an upload URL of a function associated with the specified ID.
:param function_id: UUID of the function to get the upload URL for.
:param content_length: Size of the archive to upload in bytes.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`UploadURL <UploadURL>`
Usage:
::
result = await api.get_function_upload_url(
function_id="example",
content_length=1,
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}/upload-url",
params={
"content_length": content_length,
},
)
self._throw_on_error(res)
return unmarshal_UploadURL(res.json())
async def get_function_download_url(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
) -> DownloadURL:
"""
Get a download URL of a function.
Get a download URL for a function associated with the specified ID.
:param function_id: UUID of the function to get the download URL for.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`DownloadURL <DownloadURL>`
Usage:
::
result = await api.get_function_download_url(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
param_function_id = validate_path_param("function_id", function_id)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/functions/{param_function_id}/download-url",
)
self._throw_on_error(res)
return unmarshal_DownloadURL(res.json())
async def list_crons(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
order_by: Optional[ListCronsRequestOrderBy] = None,
) -> ListCronsResponse:
"""
List all crons.
List all the cronjobs in a specified region.
:param function_id: UUID of the function.
:param region: Region to target. If none is passed will use default region from the config.
:param page: Page number.
:param page_size: Number of crons per page.
:param order_by: Order of the crons.
:return: :class:`ListCronsResponse <ListCronsResponse>`
Usage:
::
result = await api.list_crons(
function_id="example",
)
"""
param_region = validate_path_param(
"region", region or self.client.default_region
)
res = self._request(
"GET",
f"/functions/v1beta1/regions/{param_region}/crons",
params={
"function_id": function_id,
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
},
)
self._throw_on_error(res)
return unmarshal_ListCronsResponse(res.json())
async def list_crons_all(
self,
*,
function_id: str,
region: Optional[ScwRegion] = None,
page: Optional[int] = None,