Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
from .types import RestoreBackupResponse
from .types import SearchDomainsResponse
from .types import Session
from .types import WebsiteApiCreateWebsiteRequest
from .types import WebsiteApiDeleteWebsiteRequest
from .types import WebsiteApiListWebsitesRequest
from .api import WebhostingV1BackupAPI
from .api import WebhostingV1ControlPanelAPI
Expand Down Expand Up @@ -267,6 +269,8 @@
"RestoreBackupResponse",
"SearchDomainsResponse",
"Session",
"WebsiteApiCreateWebsiteRequest",
"WebsiteApiDeleteWebsiteRequest",
"WebsiteApiListWebsitesRequest",
"WebhostingV1BackupAPI",
"WebhostingV1ControlPanelAPI",
Expand Down
84 changes: 83 additions & 1 deletion scaleway-async/scaleway_async/webhosting/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
WebsiteApiCreateWebsiteRequest,
)
from .content import (
BACKUP_TRANSIENT_STATUSES,
Expand All @@ -92,6 +93,7 @@
unmarshal_FtpAccount,
unmarshal_HostingSummary,
unmarshal_MailAccount,
unmarshal_Website,
unmarshal_CheckFreeDomainAvailabilityResponse,
unmarshal_CheckUserOwnsDomainResponse,
unmarshal_DnsRecords,
Expand Down Expand Up @@ -134,6 +136,7 @@
marshal_MailAccountApiChangeMailAccountPasswordRequest,
marshal_MailAccountApiCreateMailAccountRequest,
marshal_MailAccountApiRemoveMailAccountRequest,
marshal_WebsiteApiCreateWebsiteRequest,
)
from ...std.types import (
LanguageCode as StdLanguageCode,
Expand Down Expand Up @@ -1949,7 +1952,7 @@ async def add_custom_domain(
region: Optional[ScwRegion] = None,
) -> HostingSummary:
"""
Attach a custom domain to a webhosting.
Attach a custom domain to a webhosting as an alias to the main domain.
:param hosting_id: Hosting ID to which the custom domain is attached to.
:param domain_name: The custom domain name to attach to the hosting.
:param region: Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -2712,3 +2715,82 @@ async def list_websites_all(
"order_by": order_by,
},
)

async def create_website(
self,
*,
hosting_id: str,
domain_name: str,
region: Optional[ScwRegion] = None,
) -> Website:
"""
Create a new website and attach it to a webhosting.
:param hosting_id: Hosting ID to which the website is attached to.
:param domain_name: The new domain name or subdomain to use for the website.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Website <Website>`

Usage:
::

result = await api.create_website(
hosting_id="example",
domain_name="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_hosting_id = validate_path_param("hosting_id", hosting_id)

res = self._request(
"POST",
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/websites",
body=marshal_WebsiteApiCreateWebsiteRequest(
WebsiteApiCreateWebsiteRequest(
hosting_id=hosting_id,
domain_name=domain_name,
region=region,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_Website(res.json())

async def delete_website(
self,
*,
hosting_id: str,
domain_name: str,
region: Optional[ScwRegion] = None,
) -> None:
"""
Delete a website from a webhosting.
:param hosting_id: Hosting ID to which the website is detached from.
:param domain_name: The new domain name or subdomain attached to the website.
:param region: Region to target. If none is passed will use default region from the config.

Usage:
::

result = await api.delete_website(
hosting_id="example",
domain_name="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_hosting_id = validate_path_param("hosting_id", hosting_id)
param_domain_name = validate_path_param("domain_name", domain_name)

res = self._request(
"DELETE",
f"/webhosting/v1/regions/{param_region}/hostings/{param_hosting_id}/websites/{param_domain_name}",
)

self._throw_on_error(res)
73 changes: 43 additions & 30 deletions scaleway-async/scaleway_async/webhosting/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
HostingDomain,
HostingSummary,
MailAccount,
Website,
FreeDomain,
CheckFreeDomainAvailabilityResponse,
CheckUserOwnsDomainResponse,
Expand Down Expand Up @@ -69,7 +70,6 @@
ListOffersResponse,
ProgressSummary,
ListRecentProgressesResponse,
Website,
ListWebsitesResponse,
Progress,
ResetHostingPasswordResponse,
Expand Down Expand Up @@ -101,6 +101,7 @@
MailAccountApiChangeMailAccountPasswordRequest,
MailAccountApiCreateMailAccountRequest,
MailAccountApiRemoveMailAccountRequest,
WebsiteApiCreateWebsiteRequest,
)
from ...std.types import (
LanguageCode as StdLanguageCode,
Expand Down Expand Up @@ -422,6 +423,35 @@ def unmarshal_MailAccount(data: Any) -> MailAccount:
return MailAccount(**args)


def unmarshal_Website(data: Any) -> Website:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'Website' failed as data isn't a dictionary."
)

args: dict[str, Any] = {}

field = data.get("domain", None)
if field is not None:
args["domain"] = field
else:
args["domain"] = None

field = data.get("path", None)
if field is not None:
args["path"] = field
else:
args["path"] = None

field = data.get("ssl_status", None)
if field is not None:
args["ssl_status"] = field
else:
args["ssl_status"] = False

return Website(**args)


def unmarshal_FreeDomain(data: Any) -> FreeDomain:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -1459,35 +1489,6 @@ def unmarshal_ListRecentProgressesResponse(data: Any) -> ListRecentProgressesRes
return ListRecentProgressesResponse(**args)


def unmarshal_Website(data: Any) -> Website:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'Website' failed as data isn't a dictionary."
)

args: dict[str, Any] = {}

field = data.get("domain", None)
if field is not None:
args["domain"] = field
else:
args["domain"] = None

field = data.get("path", None)
if field is not None:
args["path"] = field
else:
args["path"] = None

field = data.get("ssl_status", None)
if field is not None:
args["ssl_status"] = field
else:
args["ssl_status"] = False

return Website(**args)


def unmarshal_ListWebsitesResponse(data: Any) -> ListWebsitesResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down Expand Up @@ -2152,3 +2153,15 @@ def marshal_MailAccountApiRemoveMailAccountRequest(
output["username"] = request.username

return output


def marshal_WebsiteApiCreateWebsiteRequest(
request: WebsiteApiCreateWebsiteRequest,
defaults: ProfileDefaults,
) -> dict[str, Any]:
output: dict[str, Any] = {}

if request.domain_name is not None:
output["domain_name"] = request.domain_name

return output
36 changes: 36 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2409,6 +2409,42 @@ class Session:
"""


@dataclass
class WebsiteApiCreateWebsiteRequest:
hosting_id: str
"""
Hosting ID to which the website is attached to.
"""

domain_name: str
"""
The new domain name or subdomain to use for the website.
"""

region: Optional[ScwRegion] = None
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class WebsiteApiDeleteWebsiteRequest:
hosting_id: str
"""
Hosting ID to which the website is detached from.
"""

domain_name: str
"""
The new domain name or subdomain attached to the website.
"""

region: Optional[ScwRegion] = None
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class WebsiteApiListWebsitesRequest:
hosting_id: str
Expand Down
4 changes: 4 additions & 0 deletions scaleway/scaleway/webhosting/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
from .types import RestoreBackupResponse
from .types import SearchDomainsResponse
from .types import Session
from .types import WebsiteApiCreateWebsiteRequest
from .types import WebsiteApiDeleteWebsiteRequest
from .types import WebsiteApiListWebsitesRequest
from .api import WebhostingV1BackupAPI
from .api import WebhostingV1ControlPanelAPI
Expand Down Expand Up @@ -267,6 +269,8 @@
"RestoreBackupResponse",
"SearchDomainsResponse",
"Session",
"WebsiteApiCreateWebsiteRequest",
"WebsiteApiDeleteWebsiteRequest",
"WebsiteApiListWebsitesRequest",
"WebhostingV1BackupAPI",
"WebhostingV1ControlPanelAPI",
Expand Down
Loading