Skip to content

Commit 7b4a738

Browse files
authored
feat(webhosting): add public search domains (#848)
1 parent 461ac37 commit 7b4a738

File tree

12 files changed

+888
-6
lines changed

12 files changed

+888
-6
lines changed

scaleway-async/scaleway_async/webhosting/v1/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
from .types import DnsRecordStatus
44
from .types import DnsRecordType
55
from .types import DnsRecordsStatus
6+
from .types import DomainAction
7+
from .types import DomainAvailabilityAction
8+
from .types import DomainAvailabilityStatus
9+
from .content import DOMAIN_AVAILABILITY_TRANSIENT_STATUSES
10+
from .types import DomainDnsAction
11+
from .types import DomainStatus
12+
from .content import DOMAIN_TRANSIENT_STATUSES
13+
from .types import DomainZoneOwner
614
from .types import HostingStatus
715
from .content import HOSTING_TRANSIENT_STATUSES
816
from .types import HostingSummaryStatus
@@ -37,6 +45,7 @@
3745
from .types import HostingSummary
3846
from .types import MailAccount
3947
from .types import Website
48+
from .types import DomainAvailability
4049
from .types import CheckUserOwnsDomainResponse
4150
from .types import ControlPanelApiListControlPanelsRequest
4251
from .types import DatabaseApiAssignDatabaseUserRequest
@@ -52,8 +61,11 @@
5261
from .types import DatabaseApiUnassignDatabaseUserRequest
5362
from .types import DnsApiCheckUserOwnsDomainRequest
5463
from .types import DnsApiGetDomainDnsRecordsRequest
64+
from .types import DnsApiGetDomainRequest
65+
from .types import DnsApiSearchDomainsRequest
5566
from .types import DnsApiSyncDomainDnsRecordsRequest
5667
from .types import DnsRecords
68+
from .types import Domain
5769
from .types import FtpAccountApiChangeFtpAccountPasswordRequest
5870
from .types import FtpAccountApiCreateFtpAccountRequest
5971
from .types import FtpAccountApiListFtpAccountsRequest
@@ -82,6 +94,7 @@
8294
from .types import OfferApiListOffersRequest
8395
from .types import ResetHostingPasswordResponse
8496
from .types import ResourceSummary
97+
from .types import SearchDomainsResponse
8598
from .types import Session
8699
from .types import WebsiteApiListWebsitesRequest
87100
from .api import WebhostingV1ControlPanelAPI
@@ -97,6 +110,14 @@
97110
"DnsRecordStatus",
98111
"DnsRecordType",
99112
"DnsRecordsStatus",
113+
"DomainAction",
114+
"DomainAvailabilityAction",
115+
"DomainAvailabilityStatus",
116+
"DOMAIN_AVAILABILITY_TRANSIENT_STATUSES",
117+
"DomainDnsAction",
118+
"DomainStatus",
119+
"DOMAIN_TRANSIENT_STATUSES",
120+
"DomainZoneOwner",
100121
"HostingStatus",
101122
"HOSTING_TRANSIENT_STATUSES",
102123
"HostingSummaryStatus",
@@ -131,6 +152,7 @@
131152
"HostingSummary",
132153
"MailAccount",
133154
"Website",
155+
"DomainAvailability",
134156
"CheckUserOwnsDomainResponse",
135157
"ControlPanelApiListControlPanelsRequest",
136158
"DatabaseApiAssignDatabaseUserRequest",
@@ -146,8 +168,11 @@
146168
"DatabaseApiUnassignDatabaseUserRequest",
147169
"DnsApiCheckUserOwnsDomainRequest",
148170
"DnsApiGetDomainDnsRecordsRequest",
171+
"DnsApiGetDomainRequest",
172+
"DnsApiSearchDomainsRequest",
149173
"DnsApiSyncDomainDnsRecordsRequest",
150174
"DnsRecords",
175+
"Domain",
151176
"FtpAccountApiChangeFtpAccountPasswordRequest",
152177
"FtpAccountApiCreateFtpAccountRequest",
153178
"FtpAccountApiListFtpAccountsRequest",
@@ -176,6 +201,7 @@
176201
"OfferApiListOffersRequest",
177202
"ResetHostingPasswordResponse",
178203
"ResourceSummary",
204+
"SearchDomainsResponse",
179205
"Session",
180206
"WebsiteApiListWebsitesRequest",
181207
"WebhostingV1ControlPanelAPI",

scaleway-async/scaleway_async/webhosting/v1/api.py

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
DnsApiCheckUserOwnsDomainRequest,
3737
DnsApiSyncDomainDnsRecordsRequest,
3838
DnsRecords,
39+
Domain,
3940
FtpAccount,
4041
FtpAccountApiChangeFtpAccountPasswordRequest,
4142
FtpAccountApiCreateFtpAccountRequest,
@@ -59,11 +60,13 @@
5960
OfferOptionRequest,
6061
ResetHostingPasswordResponse,
6162
ResourceSummary,
63+
SearchDomainsResponse,
6264
Session,
6365
SyncDomainDnsRecordsRequestRecord,
6466
Website,
6567
)
6668
from .content import (
69+
DOMAIN_TRANSIENT_STATUSES,
6770
HOSTING_TRANSIENT_STATUSES,
6871
)
6972
from .marshalling import (
@@ -73,6 +76,7 @@
7376
unmarshal_MailAccount,
7477
unmarshal_CheckUserOwnsDomainResponse,
7578
unmarshal_DnsRecords,
79+
unmarshal_Domain,
7680
unmarshal_Hosting,
7781
unmarshal_ListControlPanelsResponse,
7882
unmarshal_ListDatabaseUsersResponse,
@@ -84,6 +88,7 @@
8488
unmarshal_ListWebsitesResponse,
8589
unmarshal_ResetHostingPasswordResponse,
8690
unmarshal_ResourceSummary,
91+
unmarshal_SearchDomainsResponse,
8792
unmarshal_Session,
8893
marshal_DatabaseApiAssignDatabaseUserRequest,
8994
marshal_DatabaseApiChangeDatabaseUserPasswordRequest,
@@ -792,7 +797,7 @@ async def check_user_owns_domain(
792797
project_id: Optional[str] = None,
793798
) -> CheckUserOwnsDomainResponse:
794799
"""
795-
"Check whether you own this domain or not.".
800+
Check whether you own this domain or not.
796801
:param domain: Domain for which ownership is to be verified.
797802
:param region: Region to target. If none is passed will use default region from the config.
798803
:param project_id: ID of the project currently in use.
@@ -834,15 +839,17 @@ async def sync_domain_dns_records(
834839
update_web_records: bool,
835840
update_mail_records: bool,
836841
update_all_records: bool,
842+
update_nameservers: bool,
837843
region: Optional[ScwRegion] = None,
838844
custom_records: Optional[List[SyncDomainDnsRecordsRequestRecord]] = None,
839845
) -> DnsRecords:
840846
"""
841-
"Synchronize your DNS records on the Elements Console and on cPanel.".
847+
Synchronize your DNS records on the Elements Console and on cPanel.
842848
:param domain: Domain for which the DNS records will be synchronized.
843849
:param update_web_records: Whether or not to synchronize the web records.
844850
:param update_mail_records: Whether or not to synchronize the mail records.
845851
:param update_all_records: Whether or not to synchronize all types of records. This one has priority.
852+
:param update_nameservers: Whether or not to synchronize domain nameservers.
846853
:param region: Region to target. If none is passed will use default region from the config.
847854
:param custom_records: Custom records to synchronize.
848855
:return: :class:`DnsRecords <DnsRecords>`
@@ -855,6 +862,7 @@ async def sync_domain_dns_records(
855862
update_web_records=False,
856863
update_mail_records=False,
857864
update_all_records=False,
865+
update_nameservers=False,
858866
)
859867
"""
860868

@@ -872,6 +880,7 @@ async def sync_domain_dns_records(
872880
update_web_records=update_web_records,
873881
update_mail_records=update_mail_records,
874882
update_all_records=update_all_records,
883+
update_nameservers=update_nameservers,
875884
region=region,
876885
custom_records=custom_records,
877886
),
@@ -882,6 +891,121 @@ async def sync_domain_dns_records(
882891
self._throw_on_error(res)
883892
return unmarshal_DnsRecords(res.json())
884893

894+
async def search_domains(
895+
self,
896+
*,
897+
domain_name: str,
898+
region: Optional[ScwRegion] = None,
899+
project_id: Optional[str] = None,
900+
) -> SearchDomainsResponse:
901+
"""
902+
Search for available domains based on domain name.
903+
:param domain_name: Domain name to search.
904+
:param region: Region to target. If none is passed will use default region from the config.
905+
:param project_id: ID of the Scaleway Project in which to search the domain to create the Web Hosting plan.
906+
:return: :class:`SearchDomainsResponse <SearchDomainsResponse>`
907+
908+
Usage:
909+
::
910+
911+
result = await api.search_domains(
912+
domain_name="example",
913+
)
914+
"""
915+
916+
param_region = validate_path_param(
917+
"region", region or self.client.default_region
918+
)
919+
920+
res = self._request(
921+
"GET",
922+
f"/webhosting/v1/regions/{param_region}/search-domains",
923+
params={
924+
"domain_name": domain_name,
925+
"project_id": project_id or self.client.default_project_id,
926+
},
927+
)
928+
929+
self._throw_on_error(res)
930+
return unmarshal_SearchDomainsResponse(res.json())
931+
932+
async def get_domain(
933+
self,
934+
*,
935+
domain_name: str,
936+
region: Optional[ScwRegion] = None,
937+
project_id: Optional[str] = None,
938+
) -> Domain:
939+
"""
940+
Retrieve detailed information about a specific domain, including its status, DNS configuration, and ownership.
941+
:param domain_name: Domain name to get.
942+
:param region: Region to target. If none is passed will use default region from the config.
943+
:param project_id: ID of the Scaleway Project in which to get the domain to create the Web Hosting plan.
944+
:return: :class:`Domain <Domain>`
945+
946+
Usage:
947+
::
948+
949+
result = await api.get_domain(
950+
domain_name="example",
951+
)
952+
"""
953+
954+
param_region = validate_path_param(
955+
"region", region or self.client.default_region
956+
)
957+
param_domain_name = validate_path_param("domain_name", domain_name)
958+
959+
res = self._request(
960+
"GET",
961+
f"/webhosting/v1/regions/{param_region}/domains/{param_domain_name}",
962+
params={
963+
"project_id": project_id or self.client.default_project_id,
964+
},
965+
)
966+
967+
self._throw_on_error(res)
968+
return unmarshal_Domain(res.json())
969+
970+
async def wait_for_domain(
971+
self,
972+
*,
973+
domain_name: str,
974+
region: Optional[ScwRegion] = None,
975+
project_id: Optional[str] = None,
976+
options: Optional[WaitForOptions[Domain, Union[bool, Awaitable[bool]]]] = None,
977+
) -> Domain:
978+
"""
979+
Retrieve detailed information about a specific domain, including its status, DNS configuration, and ownership.
980+
:param domain_name: Domain name to get.
981+
:param region: Region to target. If none is passed will use default region from the config.
982+
:param project_id: ID of the Scaleway Project in which to get the domain to create the Web Hosting plan.
983+
:return: :class:`Domain <Domain>`
984+
985+
Usage:
986+
::
987+
988+
result = await api.get_domain(
989+
domain_name="example",
990+
)
991+
"""
992+
993+
if not options:
994+
options = WaitForOptions()
995+
996+
if not options.stop:
997+
options.stop = lambda res: res.status not in DOMAIN_TRANSIENT_STATUSES
998+
999+
return await wait_for_resource_async(
1000+
fetcher=self.get_domain,
1001+
options=options,
1002+
args={
1003+
"domain_name": domain_name,
1004+
"region": region,
1005+
"project_id": project_id,
1006+
},
1007+
)
1008+
8851009

8861010
class WebhostingV1OfferAPI(API):
8871011
"""

scaleway-async/scaleway_async/webhosting/v1/content.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
33
from typing import List
44

55
from .types import (
6+
DomainAvailabilityStatus,
7+
DomainStatus,
68
HostingStatus,
79
HostingSummaryStatus,
810
)
911

12+
DOMAIN_AVAILABILITY_TRANSIENT_STATUSES: List[DomainAvailabilityStatus] = [
13+
DomainAvailabilityStatus.VALIDATING,
14+
]
15+
"""
16+
Lists transient statutes of the enum :class:`DomainAvailabilityStatus <DomainAvailabilityStatus>`.
17+
"""
18+
DOMAIN_TRANSIENT_STATUSES: List[DomainStatus] = [
19+
DomainStatus.VALIDATING,
20+
]
21+
"""
22+
Lists transient statutes of the enum :class:`DomainStatus <DomainStatus>`.
23+
"""
1024
HOSTING_TRANSIENT_STATUSES: List[HostingStatus] = [
1125
HostingStatus.DELIVERING,
1226
HostingStatus.DELETING,

0 commit comments

Comments
 (0)