Skip to content

Commit 4684810

Browse files
feat(webhosting): add free subdomain support (scaleway#1152)
Co-authored-by: Laure-di <[email protected]>
1 parent 23c62c9 commit 4684810

File tree

8 files changed

+464
-176
lines changed

8 files changed

+464
-176
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
from .types import OfferOptionName
2525
from .types import OfferOptionWarning
2626
from .types import PlatformPlatformGroup
27+
from .types import AutoConfigDomainDns
2728
from .types import PlatformControlPanelUrls
29+
from .types import HostingDomainCustomDomain
2830
from .types import OfferOption
2931
from .types import PlatformControlPanel
32+
from .types import HostingDomain
3033
from .types import CreateDatabaseRequestUser
31-
from .types import AutoConfigDomainDns
3234
from .types import CreateHostingRequestDomainConfiguration
3335
from .types import OfferOptionRequest
3436
from .types import SyncDomainDnsRecordsRequestRecord
@@ -130,11 +132,13 @@
130132
"OfferOptionName",
131133
"OfferOptionWarning",
132134
"PlatformPlatformGroup",
135+
"AutoConfigDomainDns",
133136
"PlatformControlPanelUrls",
137+
"HostingDomainCustomDomain",
134138
"OfferOption",
135139
"PlatformControlPanel",
140+
"HostingDomain",
136141
"CreateDatabaseRequestUser",
137-
"AutoConfigDomainDns",
138142
"CreateHostingRequestDomainConfiguration",
139143
"OfferOptionRequest",
140144
"SyncDomainDnsRecordsRequestRecord",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ async def create_hosting(
11121112
region: Optional[ScwRegion] = None,
11131113
project_id: Optional[str] = None,
11141114
tags: Optional[List[str]] = None,
1115+
subdomain: Optional[str] = None,
11151116
offer_options: Optional[List[OfferOptionRequest]] = None,
11161117
language: Optional[StdLanguageCode] = None,
11171118
domain_configuration: Optional[CreateHostingRequestDomainConfiguration] = None,
@@ -1127,6 +1128,7 @@ async def create_hosting(
11271128
:param region: Region to target. If none is passed will use default region from the config.
11281129
:param project_id: ID of the Scaleway Project in which to create the Web Hosting plan.
11291130
:param tags: List of tags for the Web Hosting plan.
1131+
:param subdomain: The name prefix to use as a free subdomain (for example, `mysite`) assigned to the Web Hosting plan. The full domain will be automatically created by adding it to the fixed base domain (e.g. `mysite.scw.site`). You do not need to include the base domain yourself.
11301132
:param offer_options: List of the Web Hosting plan options IDs with their quantities.
11311133
:param language: Default language for the control panel interface.
11321134
:param domain_configuration: Indicates whether to update hosting domain name servers and DNS records for domains managed by Scaleway Elements (deprecated, use auto_config_domain_dns instead).
@@ -1159,6 +1161,7 @@ async def create_hosting(
11591161
region=region,
11601162
project_id=project_id,
11611163
tags=tags,
1164+
subdomain=subdomain,
11621165
offer_options=offer_options,
11631166
language=language,
11641167
domain_configuration=domain_configuration,
@@ -1185,6 +1188,7 @@ async def list_hostings(
11851188
project_id: Optional[str] = None,
11861189
organization_id: Optional[str] = None,
11871190
control_panels: Optional[List[str]] = None,
1191+
subdomain: Optional[str] = None,
11881192
) -> ListHostingsResponse:
11891193
"""
11901194
List all Web Hosting plans.
@@ -1199,6 +1203,7 @@ async def list_hostings(
11991203
:param project_id: Project ID to filter for, only Web Hosting plans from this Project will be returned.
12001204
:param organization_id: Organization ID to filter for, only Web Hosting plans from this Organization will be returned.
12011205
:param control_panels: Name of the control panel to filter for, only Web Hosting plans from this control panel will be returned.
1206+
:param subdomain: Optional free subdomain linked to the Web Hosting plan.
12021207
:return: :class:`ListHostingsResponse <ListHostingsResponse>`
12031208
12041209
Usage:
@@ -1224,6 +1229,7 @@ async def list_hostings(
12241229
"page_size": page_size or self.client.default_page_size,
12251230
"project_id": project_id or self.client.default_project_id,
12261231
"statuses": statuses,
1232+
"subdomain": subdomain,
12271233
"tags": tags,
12281234
},
12291235
)
@@ -1244,6 +1250,7 @@ async def list_hostings_all(
12441250
project_id: Optional[str] = None,
12451251
organization_id: Optional[str] = None,
12461252
control_panels: Optional[List[str]] = None,
1253+
subdomain: Optional[str] = None,
12471254
) -> List[HostingSummary]:
12481255
"""
12491256
List all Web Hosting plans.
@@ -1258,6 +1265,7 @@ async def list_hostings_all(
12581265
:param project_id: Project ID to filter for, only Web Hosting plans from this Project will be returned.
12591266
:param organization_id: Organization ID to filter for, only Web Hosting plans from this Organization will be returned.
12601267
:param control_panels: Name of the control panel to filter for, only Web Hosting plans from this control panel will be returned.
1268+
:param subdomain: Optional free subdomain linked to the Web Hosting plan.
12611269
:return: :class:`List[HostingSummary] <List[HostingSummary]>`
12621270
12631271
Usage:
@@ -1281,6 +1289,7 @@ async def list_hostings_all(
12811289
"project_id": project_id,
12821290
"organization_id": organization_id,
12831291
"control_panels": control_panels,
1292+
"subdomain": subdomain,
12841293
},
12851294
)
12861295

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

Lines changed: 105 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
DnsRecords,
2828
Domain,
2929
PlatformControlPanelUrls,
30+
HostingDomainCustomDomain,
3031
OfferOption,
3132
PlatformControlPanel,
33+
HostingDomain,
3234
HostingUser,
3335
Offer,
3436
Platform,
@@ -366,6 +368,35 @@ def unmarshal_PlatformControlPanelUrls(data: Any) -> PlatformControlPanelUrls:
366368
return PlatformControlPanelUrls(**args)
367369

368370

371+
def unmarshal_HostingDomainCustomDomain(data: Any) -> HostingDomainCustomDomain:
372+
if not isinstance(data, dict):
373+
raise TypeError(
374+
"Unmarshalling the type 'HostingDomainCustomDomain' failed as data isn't a dictionary."
375+
)
376+
377+
args: Dict[str, Any] = {}
378+
379+
field = data.get("domain", None)
380+
if field is not None:
381+
args["domain"] = field
382+
383+
field = data.get("domain_status", None)
384+
if field is not None:
385+
args["domain_status"] = field
386+
387+
field = data.get("dns_status", None)
388+
if field is not None:
389+
args["dns_status"] = field
390+
391+
field = data.get("auto_config_domain_dns", None)
392+
if field is not None:
393+
args["auto_config_domain_dns"] = unmarshal_AutoConfigDomainDns(field)
394+
else:
395+
args["auto_config_domain_dns"] = None
396+
397+
return HostingDomainCustomDomain(**args)
398+
399+
369400
def unmarshal_OfferOption(data: Any) -> OfferOption:
370401
if not isinstance(data, dict):
371402
raise TypeError(
@@ -432,6 +463,27 @@ def unmarshal_PlatformControlPanel(data: Any) -> PlatformControlPanel:
432463
return PlatformControlPanel(**args)
433464

434465

466+
def unmarshal_HostingDomain(data: Any) -> HostingDomain:
467+
if not isinstance(data, dict):
468+
raise TypeError(
469+
"Unmarshalling the type 'HostingDomain' failed as data isn't a dictionary."
470+
)
471+
472+
args: Dict[str, Any] = {}
473+
474+
field = data.get("subdomain", None)
475+
if field is not None:
476+
args["subdomain"] = field
477+
478+
field = data.get("custom_domain", None)
479+
if field is not None:
480+
args["custom_domain"] = unmarshal_HostingDomainCustomDomain(field)
481+
else:
482+
args["custom_domain"] = None
483+
484+
return HostingDomain(**args)
485+
486+
435487
def unmarshal_HostingUser(data: Any) -> HostingUser:
436488
if not isinstance(data, dict):
437489
raise TypeError(
@@ -571,18 +623,6 @@ def unmarshal_Hosting(data: Any) -> Hosting:
571623
if field is not None:
572624
args["status"] = field
573625

574-
field = data.get("domain", None)
575-
if field is not None:
576-
args["domain"] = field
577-
578-
field = data.get("tags", None)
579-
if field is not None:
580-
args["tags"] = field
581-
582-
field = data.get("ipv4", None)
583-
if field is not None:
584-
args["ipv4"] = field
585-
586626
field = data.get("updated_at", None)
587627
if field is not None:
588628
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
@@ -595,17 +635,11 @@ def unmarshal_Hosting(data: Any) -> Hosting:
595635
else:
596636
args["created_at"] = None
597637

598-
field = data.get("protected", None)
599-
if field is not None:
600-
args["protected"] = field
601-
602-
field = data.get("domain_status", None)
603-
if field is not None:
604-
args["domain_status"] = field
605-
606-
field = data.get("region", None)
638+
field = data.get("domain", None)
607639
if field is not None:
608-
args["region"] = field
640+
args["domain"] = field
641+
else:
642+
args["domain"] = None
609643

610644
field = data.get("offer", None)
611645
if field is not None:
@@ -619,6 +653,22 @@ def unmarshal_Hosting(data: Any) -> Hosting:
619653
else:
620654
args["platform"] = None
621655

656+
field = data.get("tags", None)
657+
if field is not None:
658+
args["tags"] = field
659+
660+
field = data.get("ipv4", None)
661+
if field is not None:
662+
args["ipv4"] = field
663+
664+
field = data.get("protected", None)
665+
if field is not None:
666+
args["protected"] = field
667+
668+
field = data.get("region", None)
669+
if field is not None:
670+
args["region"] = field
671+
622672
field = data.get("dns_status", None)
623673
if field is not None:
624674
args["dns_status"] = field
@@ -631,6 +681,18 @@ def unmarshal_Hosting(data: Any) -> Hosting:
631681
else:
632682
args["user"] = None
633683

684+
field = data.get("domain_status", None)
685+
if field is not None:
686+
args["domain_status"] = field
687+
else:
688+
args["domain_status"] = None
689+
690+
field = data.get("domain_info", None)
691+
if field is not None:
692+
args["domain_info"] = unmarshal_HostingDomain(field)
693+
else:
694+
args["domain_info"] = None
695+
634696
return Hosting(**args)
635697

636698

@@ -767,10 +829,6 @@ def unmarshal_HostingSummary(data: Any) -> HostingSummary:
767829
if field is not None:
768830
args["status"] = field
769831

770-
field = data.get("domain", None)
771-
if field is not None:
772-
args["domain"] = field
773-
774832
field = data.get("protected", None)
775833
if field is not None:
776834
args["protected"] = field
@@ -779,10 +837,6 @@ def unmarshal_HostingSummary(data: Any) -> HostingSummary:
779837
if field is not None:
780838
args["offer_name"] = field
781839

782-
field = data.get("domain_status", None)
783-
if field is not None:
784-
args["domain_status"] = field
785-
786840
field = data.get("region", None)
787841
if field is not None:
788842
args["region"] = field
@@ -799,12 +853,30 @@ def unmarshal_HostingSummary(data: Any) -> HostingSummary:
799853
else:
800854
args["updated_at"] = None
801855

856+
field = data.get("domain", None)
857+
if field is not None:
858+
args["domain"] = field
859+
else:
860+
args["domain"] = None
861+
802862
field = data.get("dns_status", None)
803863
if field is not None:
804864
args["dns_status"] = field
805865
else:
806866
args["dns_status"] = None
807867

868+
field = data.get("domain_status", None)
869+
if field is not None:
870+
args["domain_status"] = field
871+
else:
872+
args["domain_status"] = None
873+
874+
field = data.get("domain_info", None)
875+
if field is not None:
876+
args["domain_info"] = unmarshal_HostingDomain(field)
877+
else:
878+
args["domain_info"] = None
879+
808880
return HostingSummary(**args)
809881

810882

@@ -1300,6 +1372,9 @@ def marshal_HostingApiCreateHostingRequest(
13001372
if request.tags is not None:
13011373
output["tags"] = request.tags
13021374

1375+
if request.subdomain is not None:
1376+
output["subdomain"] = request.subdomain
1377+
13031378
if request.offer_options is not None:
13041379
output["offer_options"] = [
13051380
marshal_OfferOptionRequest(item, defaults) for item in request.offer_options

0 commit comments

Comments
 (0)