Skip to content

Commit 7e22778

Browse files
authored
feat(webhosting): add the CreateWebsite and DeleteWebsite endpoints (#1336)
1 parent 853ccb3 commit 7e22778

File tree

8 files changed

+332
-62
lines changed

8 files changed

+332
-62
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
from .types import RestoreBackupResponse
128128
from .types import SearchDomainsResponse
129129
from .types import Session
130+
from .types import WebsiteApiCreateWebsiteRequest
131+
from .types import WebsiteApiDeleteWebsiteRequest
130132
from .types import WebsiteApiListWebsitesRequest
131133
from .api import WebhostingV1BackupAPI
132134
from .api import WebhostingV1ControlPanelAPI
@@ -267,6 +269,8 @@
267269
"RestoreBackupResponse",
268270
"SearchDomainsResponse",
269271
"Session",
272+
"WebsiteApiCreateWebsiteRequest",
273+
"WebsiteApiDeleteWebsiteRequest",
270274
"WebsiteApiListWebsitesRequest",
271275
"WebhostingV1BackupAPI",
272276
"WebhostingV1ControlPanelAPI",

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
Session,
8080
SyncDomainDnsRecordsRequestRecord,
8181
Website,
82+
WebsiteApiCreateWebsiteRequest,
8283
)
8384
from .content import (
8485
BACKUP_TRANSIENT_STATUSES,
@@ -92,6 +93,7 @@
9293
unmarshal_FtpAccount,
9394
unmarshal_HostingSummary,
9495
unmarshal_MailAccount,
96+
unmarshal_Website,
9597
unmarshal_CheckFreeDomainAvailabilityResponse,
9698
unmarshal_CheckUserOwnsDomainResponse,
9799
unmarshal_DnsRecords,
@@ -134,6 +136,7 @@
134136
marshal_MailAccountApiChangeMailAccountPasswordRequest,
135137
marshal_MailAccountApiCreateMailAccountRequest,
136138
marshal_MailAccountApiRemoveMailAccountRequest,
139+
marshal_WebsiteApiCreateWebsiteRequest,
137140
)
138141
from ...std.types import (
139142
LanguageCode as StdLanguageCode,
@@ -1949,7 +1952,7 @@ async def add_custom_domain(
19491952
region: Optional[ScwRegion] = None,
19501953
) -> HostingSummary:
19511954
"""
1952-
Attach a custom domain to a webhosting.
1955+
Attach a custom domain to a webhosting as an alias to the main domain.
19531956
:param hosting_id: Hosting ID to which the custom domain is attached to.
19541957
:param domain_name: The custom domain name to attach to the hosting.
19551958
:param region: Region to target. If none is passed will use default region from the config.
@@ -2712,3 +2715,82 @@ async def list_websites_all(
27122715
"order_by": order_by,
27132716
},
27142717
)
2718+
2719+
async def create_website(
2720+
self,
2721+
*,
2722+
hosting_id: str,
2723+
domain_name: str,
2724+
region: Optional[ScwRegion] = None,
2725+
) -> Website:
2726+
"""
2727+
Create a new website and attach it to a webhosting.
2728+
:param hosting_id: Hosting ID to which the website is attached to.
2729+
:param domain_name: The new domain name or subdomain to use for the website.
2730+
:param region: Region to target. If none is passed will use default region from the config.
2731+
:return: :class:`Website <Website>`
2732+
2733+
Usage:
2734+
::
2735+
2736+
result = await api.create_website(
2737+
hosting_id="example",
2738+
domain_name="example",
2739+
)
2740+
"""
2741+
2742+
param_region = validate_path_param(
2743+
"region", region or self.client.default_region
2744+
)
2745+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
2746+
2747+
res = self._request(
2748+
"POST",
2749+
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/websites",
2750+
body=marshal_WebsiteApiCreateWebsiteRequest(
2751+
WebsiteApiCreateWebsiteRequest(
2752+
hosting_id=hosting_id,
2753+
domain_name=domain_name,
2754+
region=region,
2755+
),
2756+
self.client,
2757+
),
2758+
)
2759+
2760+
self._throw_on_error(res)
2761+
return unmarshal_Website(res.json())
2762+
2763+
async def delete_website(
2764+
self,
2765+
*,
2766+
hosting_id: str,
2767+
domain_name: str,
2768+
region: Optional[ScwRegion] = None,
2769+
) -> None:
2770+
"""
2771+
Delete a website from a webhosting.
2772+
:param hosting_id: Hosting ID to which the website is detached from.
2773+
:param domain_name: The new domain name or subdomain attached to the website.
2774+
:param region: Region to target. If none is passed will use default region from the config.
2775+
2776+
Usage:
2777+
::
2778+
2779+
result = await api.delete_website(
2780+
hosting_id="example",
2781+
domain_name="example",
2782+
)
2783+
"""
2784+
2785+
param_region = validate_path_param(
2786+
"region", region or self.client.default_region
2787+
)
2788+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
2789+
param_domain_name = validate_path_param("domain_name", domain_name)
2790+
2791+
res = self._request(
2792+
"DELETE",
2793+
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/websites/{param_domain_name}",
2794+
)
2795+
2796+
self._throw_on_error(res)

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

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
HostingDomain,
4141
HostingSummary,
4242
MailAccount,
43+
Website,
4344
FreeDomain,
4445
CheckFreeDomainAvailabilityResponse,
4546
CheckUserOwnsDomainResponse,
@@ -69,7 +70,6 @@
6970
ListOffersResponse,
7071
ProgressSummary,
7172
ListRecentProgressesResponse,
72-
Website,
7373
ListWebsitesResponse,
7474
Progress,
7575
ResetHostingPasswordResponse,
@@ -101,6 +101,7 @@
101101
MailAccountApiChangeMailAccountPasswordRequest,
102102
MailAccountApiCreateMailAccountRequest,
103103
MailAccountApiRemoveMailAccountRequest,
104+
WebsiteApiCreateWebsiteRequest,
104105
)
105106
from ...std.types import (
106107
LanguageCode as StdLanguageCode,
@@ -422,6 +423,35 @@ def unmarshal_MailAccount(data: Any) -> MailAccount:
422423
return MailAccount(**args)
423424

424425

426+
def unmarshal_Website(data: Any) -> Website:
427+
if not isinstance(data, dict):
428+
raise TypeError(
429+
"Unmarshalling the type 'Website' failed as data isn't a dictionary."
430+
)
431+
432+
args: dict[str, Any] = {}
433+
434+
field = data.get("domain", None)
435+
if field is not None:
436+
args["domain"] = field
437+
else:
438+
args["domain"] = None
439+
440+
field = data.get("path", None)
441+
if field is not None:
442+
args["path"] = field
443+
else:
444+
args["path"] = None
445+
446+
field = data.get("ssl_status", None)
447+
if field is not None:
448+
args["ssl_status"] = field
449+
else:
450+
args["ssl_status"] = False
451+
452+
return Website(**args)
453+
454+
425455
def unmarshal_FreeDomain(data: Any) -> FreeDomain:
426456
if not isinstance(data, dict):
427457
raise TypeError(
@@ -1459,35 +1489,6 @@ def unmarshal_ListRecentProgressesResponse(data: Any) -> ListRecentProgressesRes
14591489
return ListRecentProgressesResponse(**args)
14601490

14611491

1462-
def unmarshal_Website(data: Any) -> Website:
1463-
if not isinstance(data, dict):
1464-
raise TypeError(
1465-
"Unmarshalling the type 'Website' failed as data isn't a dictionary."
1466-
)
1467-
1468-
args: dict[str, Any] = {}
1469-
1470-
field = data.get("domain", None)
1471-
if field is not None:
1472-
args["domain"] = field
1473-
else:
1474-
args["domain"] = None
1475-
1476-
field = data.get("path", None)
1477-
if field is not None:
1478-
args["path"] = field
1479-
else:
1480-
args["path"] = None
1481-
1482-
field = data.get("ssl_status", None)
1483-
if field is not None:
1484-
args["ssl_status"] = field
1485-
else:
1486-
args["ssl_status"] = False
1487-
1488-
return Website(**args)
1489-
1490-
14911492
def unmarshal_ListWebsitesResponse(data: Any) -> ListWebsitesResponse:
14921493
if not isinstance(data, dict):
14931494
raise TypeError(
@@ -2152,3 +2153,15 @@ def marshal_MailAccountApiRemoveMailAccountRequest(
21522153
output["username"] = request.username
21532154

21542155
return output
2156+
2157+
2158+
def marshal_WebsiteApiCreateWebsiteRequest(
2159+
request: WebsiteApiCreateWebsiteRequest,
2160+
defaults: ProfileDefaults,
2161+
) -> dict[str, Any]:
2162+
output: dict[str, Any] = {}
2163+
2164+
if request.domain_name is not None:
2165+
output["domain_name"] = request.domain_name
2166+
2167+
return output

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,42 @@ class Session:
24092409
"""
24102410

24112411

2412+
@dataclass
2413+
class WebsiteApiCreateWebsiteRequest:
2414+
hosting_id: str
2415+
"""
2416+
Hosting ID to which the website is attached to.
2417+
"""
2418+
2419+
domain_name: str
2420+
"""
2421+
The new domain name or subdomain to use for the website.
2422+
"""
2423+
2424+
region: Optional[ScwRegion] = None
2425+
"""
2426+
Region to target. If none is passed will use default region from the config.
2427+
"""
2428+
2429+
2430+
@dataclass
2431+
class WebsiteApiDeleteWebsiteRequest:
2432+
hosting_id: str
2433+
"""
2434+
Hosting ID to which the website is detached from.
2435+
"""
2436+
2437+
domain_name: str
2438+
"""
2439+
The new domain name or subdomain attached to the website.
2440+
"""
2441+
2442+
region: Optional[ScwRegion] = None
2443+
"""
2444+
Region to target. If none is passed will use default region from the config.
2445+
"""
2446+
2447+
24122448
@dataclass
24132449
class WebsiteApiListWebsitesRequest:
24142450
hosting_id: str

scaleway/scaleway/webhosting/v1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
from .types import RestoreBackupResponse
128128
from .types import SearchDomainsResponse
129129
from .types import Session
130+
from .types import WebsiteApiCreateWebsiteRequest
131+
from .types import WebsiteApiDeleteWebsiteRequest
130132
from .types import WebsiteApiListWebsitesRequest
131133
from .api import WebhostingV1BackupAPI
132134
from .api import WebhostingV1ControlPanelAPI
@@ -267,6 +269,8 @@
267269
"RestoreBackupResponse",
268270
"SearchDomainsResponse",
269271
"Session",
272+
"WebsiteApiCreateWebsiteRequest",
273+
"WebsiteApiDeleteWebsiteRequest",
270274
"WebsiteApiListWebsitesRequest",
271275
"WebhostingV1BackupAPI",
272276
"WebhostingV1ControlPanelAPI",

0 commit comments

Comments
 (0)