Skip to content

Commit c8937ce

Browse files
feat(webhosting): implement FreeDomainAPI (#1218)
Co-authored-by: Mia-Cross <lmarabese@scaleway.com>
1 parent 7e78213 commit c8937ce

File tree

8 files changed

+674
-0
lines changed

8 files changed

+674
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .types import BackupItemType
44
from .types import BackupStatus
55
from .content import BACKUP_TRANSIENT_STATUSES
6+
from .types import CheckFreeDomainAvailabilityResponseUnavailableReason
67
from .types import DnsRecordStatus
78
from .types import DnsRecordType
89
from .types import DnsRecordsStatus
@@ -35,6 +36,7 @@
3536
from .types import PlatformControlPanel
3637
from .types import BackupItem
3738
from .types import HostingDomain
39+
from .types import FreeDomain
3840
from .types import CreateDatabaseRequestUser
3941
from .types import CreateHostingRequestDomainConfiguration
4042
from .types import OfferOptionRequest
@@ -59,6 +61,7 @@
5961
from .types import BackupApiListBackupsRequest
6062
from .types import BackupApiRestoreBackupItemsRequest
6163
from .types import BackupApiRestoreBackupRequest
64+
from .types import CheckFreeDomainAvailabilityResponse
6265
from .types import CheckUserOwnsDomainResponse
6366
from .types import ControlPanelApiListControlPanelsRequest
6467
from .types import DatabaseApiAssignDatabaseUserRequest
@@ -79,6 +82,8 @@
7982
from .types import DnsApiSyncDomainDnsRecordsRequest
8083
from .types import DnsRecords
8184
from .types import Domain
85+
from .types import FreeDomainApiCheckFreeDomainAvailabilityRequest
86+
from .types import FreeDomainApiListFreeRootDomainsRequest
8287
from .types import FtpAccountApiChangeFtpAccountPasswordRequest
8388
from .types import FtpAccountApiCreateFtpAccountRequest
8489
from .types import FtpAccountApiListFtpAccountsRequest
@@ -99,6 +104,7 @@
99104
from .types import ListControlPanelsResponse
100105
from .types import ListDatabaseUsersResponse
101106
from .types import ListDatabasesResponse
107+
from .types import ListFreeRootDomainsResponse
102108
from .types import ListFtpAccountsResponse
103109
from .types import ListHostingsResponse
104110
from .types import ListMailAccountsResponse
@@ -122,6 +128,7 @@
122128
from .api import WebhostingV1DnsAPI
123129
from .api import WebhostingV1OfferAPI
124130
from .api import WebhostingV1HostingAPI
131+
from .api import WebhostingV1FreeDomainAPI
125132
from .api import WebhostingV1FtpAccountAPI
126133
from .api import WebhostingV1MailAccountAPI
127134
from .api import WebhostingV1WebsiteAPI
@@ -130,6 +137,7 @@
130137
"BackupItemType",
131138
"BackupStatus",
132139
"BACKUP_TRANSIENT_STATUSES",
140+
"CheckFreeDomainAvailabilityResponseUnavailableReason",
133141
"DnsRecordStatus",
134142
"DnsRecordType",
135143
"DnsRecordsStatus",
@@ -162,6 +170,7 @@
162170
"PlatformControlPanel",
163171
"BackupItem",
164172
"HostingDomain",
173+
"FreeDomain",
165174
"CreateDatabaseRequestUser",
166175
"CreateHostingRequestDomainConfiguration",
167176
"OfferOptionRequest",
@@ -186,6 +195,7 @@
186195
"BackupApiListBackupsRequest",
187196
"BackupApiRestoreBackupItemsRequest",
188197
"BackupApiRestoreBackupRequest",
198+
"CheckFreeDomainAvailabilityResponse",
189199
"CheckUserOwnsDomainResponse",
190200
"ControlPanelApiListControlPanelsRequest",
191201
"DatabaseApiAssignDatabaseUserRequest",
@@ -206,6 +216,8 @@
206216
"DnsApiSyncDomainDnsRecordsRequest",
207217
"DnsRecords",
208218
"Domain",
219+
"FreeDomainApiCheckFreeDomainAvailabilityRequest",
220+
"FreeDomainApiListFreeRootDomainsRequest",
209221
"FtpAccountApiChangeFtpAccountPasswordRequest",
210222
"FtpAccountApiCreateFtpAccountRequest",
211223
"FtpAccountApiListFtpAccountsRequest",
@@ -226,6 +238,7 @@
226238
"ListControlPanelsResponse",
227239
"ListDatabaseUsersResponse",
228240
"ListDatabasesResponse",
241+
"ListFreeRootDomainsResponse",
229242
"ListFtpAccountsResponse",
230243
"ListHostingsResponse",
231244
"ListMailAccountsResponse",
@@ -249,6 +262,7 @@
249262
"WebhostingV1DnsAPI",
250263
"WebhostingV1OfferAPI",
251264
"WebhostingV1HostingAPI",
265+
"WebhostingV1FreeDomainAPI",
252266
"WebhostingV1FtpAccountAPI",
253267
"WebhostingV1MailAccountAPI",
254268
"WebhostingV1WebsiteAPI",

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

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
AutoConfigDomainDns,
2727
Backup,
2828
BackupApiRestoreBackupItemsRequest,
29+
CheckFreeDomainAvailabilityResponse,
2930
CheckUserOwnsDomainResponse,
3031
ControlPanel,
3132
CreateDatabaseRequestUser,
@@ -41,6 +42,7 @@
4142
DnsApiSyncDomainDnsRecordsRequest,
4243
DnsRecords,
4344
Domain,
45+
FreeDomainApiCheckFreeDomainAvailabilityRequest,
4446
FtpAccount,
4547
FtpAccountApiChangeFtpAccountPasswordRequest,
4648
FtpAccountApiCreateFtpAccountRequest,
@@ -54,6 +56,7 @@
5456
ListControlPanelsResponse,
5557
ListDatabaseUsersResponse,
5658
ListDatabasesResponse,
59+
ListFreeRootDomainsResponse,
5760
ListFtpAccountsResponse,
5861
ListHostingsResponse,
5962
ListMailAccountsResponse,
@@ -86,6 +89,7 @@
8689
unmarshal_FtpAccount,
8790
unmarshal_HostingSummary,
8891
unmarshal_MailAccount,
92+
unmarshal_CheckFreeDomainAvailabilityResponse,
8993
unmarshal_CheckUserOwnsDomainResponse,
9094
unmarshal_DnsRecords,
9195
unmarshal_Domain,
@@ -95,6 +99,7 @@
9599
unmarshal_ListControlPanelsResponse,
96100
unmarshal_ListDatabaseUsersResponse,
97101
unmarshal_ListDatabasesResponse,
102+
unmarshal_ListFreeRootDomainsResponse,
98103
unmarshal_ListFtpAccountsResponse,
99104
unmarshal_ListHostingsResponse,
100105
unmarshal_ListMailAccountsResponse,
@@ -114,6 +119,7 @@
114119
marshal_DatabaseApiUnassignDatabaseUserRequest,
115120
marshal_DnsApiCheckUserOwnsDomainRequest,
116121
marshal_DnsApiSyncDomainDnsRecordsRequest,
122+
marshal_FreeDomainApiCheckFreeDomainAvailabilityRequest,
117123
marshal_FtpAccountApiChangeFtpAccountPasswordRequest,
118124
marshal_FtpAccountApiCreateFtpAccountRequest,
119125
marshal_HostingApiAddCustomDomainRequest,
@@ -1938,6 +1944,122 @@ async def remove_custom_domain(
19381944
return unmarshal_HostingSummary(res.json())
19391945

19401946

1947+
class WebhostingV1FreeDomainAPI(API):
1948+
"""
1949+
This API allows you to list and check a free domain's validity.
1950+
"""
1951+
1952+
async def check_free_domain_availability(
1953+
self,
1954+
*,
1955+
slug: str,
1956+
root_domain: str,
1957+
region: Optional[ScwRegion] = None,
1958+
) -> CheckFreeDomainAvailabilityResponse:
1959+
"""
1960+
Check whether a given slug and free domain combination is available.
1961+
:param slug: Custom prefix used for the free domain.
1962+
:param root_domain: Free root domain provided by Web Hosting, selected from the list returned by `ListFreeRootDomains`.
1963+
:param region: Region to target. If none is passed will use default region from the config.
1964+
:return: :class:`CheckFreeDomainAvailabilityResponse <CheckFreeDomainAvailabilityResponse>`
1965+
1966+
Usage:
1967+
::
1968+
1969+
result = await api.check_free_domain_availability(
1970+
slug="example",
1971+
root_domain="example",
1972+
)
1973+
"""
1974+
1975+
param_region = validate_path_param(
1976+
"region", region or self.client.default_region
1977+
)
1978+
1979+
res = self._request(
1980+
"POST",
1981+
f"/webhosting/v1/regions/{param_region}/free-domains/check-availability",
1982+
body=marshal_FreeDomainApiCheckFreeDomainAvailabilityRequest(
1983+
FreeDomainApiCheckFreeDomainAvailabilityRequest(
1984+
slug=slug,
1985+
root_domain=root_domain,
1986+
region=region,
1987+
),
1988+
self.client,
1989+
),
1990+
)
1991+
1992+
self._throw_on_error(res)
1993+
return unmarshal_CheckFreeDomainAvailabilityResponse(res.json())
1994+
1995+
async def list_free_root_domains(
1996+
self,
1997+
*,
1998+
region: Optional[ScwRegion] = None,
1999+
page: Optional[int] = None,
2000+
page_size: Optional[int] = None,
2001+
) -> ListFreeRootDomainsResponse:
2002+
"""
2003+
Retrieve the list of free root domains available for a Web Hosting.
2004+
:param region: Region to target. If none is passed will use default region from the config.
2005+
:param page: Page number to return, from the paginated results (must be a positive integer).
2006+
:param page_size: Number of free root domains to return (must be a positive integer lower or equal to 100).
2007+
:return: :class:`ListFreeRootDomainsResponse <ListFreeRootDomainsResponse>`
2008+
2009+
Usage:
2010+
::
2011+
2012+
result = await api.list_free_root_domains()
2013+
"""
2014+
2015+
param_region = validate_path_param(
2016+
"region", region or self.client.default_region
2017+
)
2018+
2019+
res = self._request(
2020+
"GET",
2021+
f"/webhosting/v1/regions/{param_region}/free-domains/root-domains",
2022+
params={
2023+
"page": page,
2024+
"page_size": page_size or self.client.default_page_size,
2025+
},
2026+
)
2027+
2028+
self._throw_on_error(res)
2029+
return unmarshal_ListFreeRootDomainsResponse(res.json())
2030+
2031+
async def list_free_root_domains_all(
2032+
self,
2033+
*,
2034+
region: Optional[ScwRegion] = None,
2035+
page: Optional[int] = None,
2036+
page_size: Optional[int] = None,
2037+
) -> List[str]:
2038+
"""
2039+
Retrieve the list of free root domains available for a Web Hosting.
2040+
:param region: Region to target. If none is passed will use default region from the config.
2041+
:param page: Page number to return, from the paginated results (must be a positive integer).
2042+
:param page_size: Number of free root domains to return (must be a positive integer lower or equal to 100).
2043+
:return: :class:`List[str] <List[str]>`
2044+
2045+
Usage:
2046+
::
2047+
2048+
result = await api.list_free_root_domains_all()
2049+
"""
2050+
2051+
return await fetch_all_pages_async(
2052+
type=ListFreeRootDomainsResponse,
2053+
key="root_domains",
2054+
fetcher=self.list_free_root_domains,
2055+
args={
2056+
"region": region,
2057+
"page": page,
2058+
"page_size": page_size,
2059+
},
2060+
)
2061+
2062+
19412063
class WebhostingV1FtpAccountAPI(API):
19422064
"""
19432065
This API allows you to manage your FTP accounts for your Web Hosting services.

0 commit comments

Comments
 (0)