forked from scaleway/scaleway-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
592 lines (500 loc) · 16.4 KB
/
api.py
File metadata and controls
592 lines (500 loc) · 16.4 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
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from typing import Awaitable, Optional, Union
from scaleway_core.api import API
from scaleway_core.utils import (
WaitForOptions,
validate_path_param,
fetch_all_pages_async,
wait_for_resource_async,
)
from .types import (
DomainStatus,
ListDomainsRequestOrderBy,
ListMailboxesRequestOrderBy,
MailboxStatus,
MailboxSubscriptionPeriod,
BatchCreateMailboxesRequest,
BatchCreateMailboxesRequestMailboxParameters,
BatchCreateMailboxesResponse,
CreateDomainRequest,
Domain,
GetDomainRecordsResponse,
ListDomainsResponse,
ListMailboxesResponse,
Mailbox,
UpdateMailboxRequest,
)
from .content import (
DOMAIN_TRANSIENT_STATUSES,
MAILBOX_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_Mailbox,
unmarshal_Domain,
unmarshal_BatchCreateMailboxesResponse,
unmarshal_GetDomainRecordsResponse,
unmarshal_ListDomainsResponse,
unmarshal_ListMailboxesResponse,
marshal_BatchCreateMailboxesRequest,
marshal_CreateDomainRequest,
marshal_UpdateMailboxRequest,
)
class MailboxV1Alpha1API(API):
"""
This API allows you to manage your Mailbox services.
"""
async def create_domain(
self,
*,
name: str,
project_id: Optional[str] = None,
) -> Domain:
"""
Register a domain in a project.
You must specify a `project_id` and a `domain_name` to register a domain in a specific Project.
:param name: Fully qualified domain name.
:param project_id: ID of the project to which the domain belongs.
:return: :class:`Domain <Domain>`
Usage:
::
result = await api.create_domain(
name="example",
)
"""
res = self._request(
"POST",
"/mailbox/v1alpha1/domains",
body=marshal_CreateDomainRequest(
CreateDomainRequest(
name=name,
project_id=project_id,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Domain(res.json())
async def list_domains(
self,
*,
order_by: Optional[ListDomainsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
project_id: Optional[str] = None,
statuses: Optional[list[DomainStatus]] = None,
search: Optional[str] = None,
) -> ListDomainsResponse:
"""
List domains in an organization.
The return list can be filtered with request parameters.
:param order_by:
:param page:
:param page_size:
:param project_id:
:param statuses:
:param search:
:return: :class:`ListDomainsResponse <ListDomainsResponse>`
Usage:
::
result = await api.list_domains()
"""
res = self._request(
"GET",
"/mailbox/v1alpha1/domains",
params={
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"search": search,
"statuses": statuses,
},
)
self._throw_on_error(res)
return unmarshal_ListDomainsResponse(res.json())
async def list_domains_all(
self,
*,
order_by: Optional[ListDomainsRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
project_id: Optional[str] = None,
statuses: Optional[list[DomainStatus]] = None,
search: Optional[str] = None,
) -> list[Domain]:
"""
List domains in an organization.
The return list can be filtered with request parameters.
:param order_by:
:param page:
:param page_size:
:param project_id:
:param statuses:
:param search:
:return: :class:`list[Domain] <list[Domain]>`
Usage:
::
result = await api.list_domains_all()
"""
return await fetch_all_pages_async(
type=ListDomainsResponse,
key="domains",
fetcher=self.list_domains,
args={
"order_by": order_by,
"page": page,
"page_size": page_size,
"project_id": project_id,
"statuses": statuses,
"search": search,
},
)
async def get_domain(
self,
*,
domain_id: str,
) -> Domain:
"""
Get a domain by its ID.
:param domain_id: ID of the domain to get.
:return: :class:`Domain <Domain>`
Usage:
::
result = await api.get_domain(
domain_id="example",
)
"""
param_domain_id = validate_path_param("domain_id", domain_id)
res = self._request(
"GET",
f"/mailbox/v1alpha1/domains/{param_domain_id}",
)
self._throw_on_error(res)
return unmarshal_Domain(res.json())
async def wait_for_domain(
self,
*,
domain_id: str,
options: Optional[WaitForOptions[Domain, Union[bool, Awaitable[bool]]]] = None,
) -> Domain:
"""
Get a domain by its ID.
:param domain_id: ID of the domain to get.
:return: :class:`Domain <Domain>`
Usage:
::
result = await api.get_domain(
domain_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in DOMAIN_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_domain,
options=options,
args={
"domain_id": domain_id,
},
)
async def delete_domain(
self,
*,
domain_id: str,
) -> Domain:
"""
Delete a domain by its ID.
:param domain_id: ID of the domain to delete.
:return: :class:`Domain <Domain>`
Usage:
::
result = await api.delete_domain(
domain_id="example",
)
"""
param_domain_id = validate_path_param("domain_id", domain_id)
res = self._request(
"DELETE",
f"/mailbox/v1alpha1/domains/{param_domain_id}",
)
self._throw_on_error(res)
return unmarshal_Domain(res.json())
async def get_domain_records(
self,
*,
domain_id: str,
) -> GetDomainRecordsResponse:
"""
Get domain records by its ID.
:param domain_id: (Optional) ID of the domain in which to get the records.
:return: :class:`GetDomainRecordsResponse <GetDomainRecordsResponse>`
Usage:
::
result = await api.get_domain_records(
domain_id="example",
)
"""
param_domain_id = validate_path_param("domain_id", domain_id)
res = self._request(
"GET",
f"/mailbox/v1alpha1/domains/{param_domain_id}/records",
)
self._throw_on_error(res)
return unmarshal_GetDomainRecordsResponse(res.json())
async def validate_domain_records(
self,
*,
domain_id: str,
) -> None:
"""
:param domain_id:
Usage:
::
result = await api.validate_domain_records(
domain_id="example",
)
"""
param_domain_id = validate_path_param("domain_id", domain_id)
res = self._request(
"POST",
f"/mailbox/v1alpha1/domains/{param_domain_id}/validate-records",
body={},
)
self._throw_on_error(res)
async def batch_create_mailboxes(
self,
*,
domain_id: str,
mailboxes: Optional[list[BatchCreateMailboxesRequestMailboxParameters]] = None,
subscription_period: Optional[MailboxSubscriptionPeriod] = None,
) -> BatchCreateMailboxesResponse:
"""
:param domain_id: ID of the domain in which to create the mailboxes.
:param mailboxes: Parameters for the mailboxes to create.
:param subscription_period: Subscription renewal period, it can be monthly or yearly.
:return: :class:`BatchCreateMailboxesResponse <BatchCreateMailboxesResponse>`
Usage:
::
result = await api.batch_create_mailboxes(
domain_id="example",
)
"""
res = self._request(
"POST",
"/mailbox/v1alpha1/batch-create-mailboxes",
body=marshal_BatchCreateMailboxesRequest(
BatchCreateMailboxesRequest(
domain_id=domain_id,
mailboxes=mailboxes,
subscription_period=subscription_period,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_BatchCreateMailboxesResponse(res.json())
async def list_mailboxes(
self,
*,
order_by: Optional[ListMailboxesRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
domain_id: Optional[str] = None,
statuses: Optional[list[MailboxStatus]] = None,
search: Optional[str] = None,
) -> ListMailboxesResponse:
"""
List mailboxes in an organization.
The return list can be filtered with request parameters.
:param order_by: Order matching mailbox by different criteria.
:param page: Requested page number. Value must be greater or equal to 1.
:param page_size: Requested page size. Value must be between 1 and 1000.
:param domain_id: (Optional) ID of the domain in which to list the mailboxes.
:param statuses: (Optional) Filter mailboxes by their statuses.
:param search: (Optional) Search term to filter mailboxes on name and local_part.
:return: :class:`ListMailboxesResponse <ListMailboxesResponse>`
Usage:
::
result = await api.list_mailboxes()
"""
res = self._request(
"GET",
"/mailbox/v1alpha1/mailboxes",
params={
"domain_id": domain_id,
"order_by": order_by,
"page": page,
"page_size": page_size or self.client.default_page_size,
"search": search,
"statuses": statuses,
},
)
self._throw_on_error(res)
return unmarshal_ListMailboxesResponse(res.json())
async def list_mailboxes_all(
self,
*,
order_by: Optional[ListMailboxesRequestOrderBy] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
domain_id: Optional[str] = None,
statuses: Optional[list[MailboxStatus]] = None,
search: Optional[str] = None,
) -> list[Mailbox]:
"""
List mailboxes in an organization.
The return list can be filtered with request parameters.
:param order_by: Order matching mailbox by different criteria.
:param page: Requested page number. Value must be greater or equal to 1.
:param page_size: Requested page size. Value must be between 1 and 1000.
:param domain_id: (Optional) ID of the domain in which to list the mailboxes.
:param statuses: (Optional) Filter mailboxes by their statuses.
:param search: (Optional) Search term to filter mailboxes on name and local_part.
:return: :class:`list[Mailbox] <list[Mailbox]>`
Usage:
::
result = await api.list_mailboxes_all()
"""
return await fetch_all_pages_async(
type=ListMailboxesResponse,
key="mailboxes",
fetcher=self.list_mailboxes,
args={
"order_by": order_by,
"page": page,
"page_size": page_size,
"domain_id": domain_id,
"statuses": statuses,
"search": search,
},
)
async def get_mailbox(
self,
*,
mailbox_id: str,
) -> Mailbox:
"""
Get a mailbox by its ID.
:param mailbox_id: ID of the mailbox to get.
:return: :class:`Mailbox <Mailbox>`
Usage:
::
result = await api.get_mailbox(
mailbox_id="example",
)
"""
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
res = self._request(
"GET",
f"/mailbox/v1alpha1/mailboxes/{param_mailbox_id}",
)
self._throw_on_error(res)
return unmarshal_Mailbox(res.json())
async def wait_for_mailbox(
self,
*,
mailbox_id: str,
options: Optional[WaitForOptions[Mailbox, Union[bool, Awaitable[bool]]]] = None,
) -> Mailbox:
"""
Get a mailbox by its ID.
:param mailbox_id: ID of the mailbox to get.
:return: :class:`Mailbox <Mailbox>`
Usage:
::
result = await api.get_mailbox(
mailbox_id="example",
)
"""
if not options:
options = WaitForOptions()
if not options.stop:
options.stop = lambda res: res.status not in MAILBOX_TRANSIENT_STATUSES
return await wait_for_resource_async(
fetcher=self.get_mailbox,
options=options,
args={
"mailbox_id": mailbox_id,
},
)
async def update_mailbox(
self,
*,
mailbox_id: str,
subscription_period: Optional[MailboxSubscriptionPeriod] = None,
new_password: Optional[str] = None,
) -> Mailbox:
"""
Update a mailbox subscription period or password with its ID.
:param mailbox_id: ID of the mailbox to update.
:param subscription_period: (Optional) New subscription period for the mailbox.
:param new_password: (Optional) New password of the mailbox.
:return: :class:`Mailbox <Mailbox>`
Usage:
::
result = await api.update_mailbox(
mailbox_id="example",
)
"""
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
res = self._request(
"PATCH",
f"/mailbox/v1alpha1/mailboxes/{param_mailbox_id}",
body=marshal_UpdateMailboxRequest(
UpdateMailboxRequest(
mailbox_id=mailbox_id,
subscription_period=subscription_period,
new_password=new_password,
),
self.client,
),
)
self._throw_on_error(res)
return unmarshal_Mailbox(res.json())
async def delete_mailbox(
self,
*,
mailbox_id: str,
) -> Mailbox:
"""
Delete a mailbox by its ID.
:param mailbox_id: ID of the mailbox to delete.
:return: :class:`Mailbox <Mailbox>`
Usage:
::
result = await api.delete_mailbox(
mailbox_id="example",
)
"""
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
res = self._request(
"DELETE",
f"/mailbox/v1alpha1/mailboxes/{param_mailbox_id}",
)
self._throw_on_error(res)
return unmarshal_Mailbox(res.json())
async def restore_mailbox(
self,
*,
mailbox_id: str,
) -> Mailbox:
"""
Restore a mailbox in deletion scheduled status by its ID.
:param mailbox_id: ID of the mailbox to restore.
:return: :class:`Mailbox <Mailbox>`
Usage:
::
result = await api.restore_mailbox(
mailbox_id="example",
)
"""
param_mailbox_id = validate_path_param("mailbox_id", mailbox_id)
res = self._request(
"POST",
f"/mailbox/v1alpha1/mailboxes/{param_mailbox_id}/restore",
body={},
)
self._throw_on_error(res)
return unmarshal_Mailbox(res.json())