Skip to content

Commit 471ffd9

Browse files
authored
feat(webhosting): add a magic link autologin url for webhosting (#500)
1 parent 51152d9 commit 471ffd9

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .types import Hosting
2121
from .types import Offer
2222
from .types import CreateHostingRequest
23+
from .types import CreateSessionRequest
2324
from .types import DeleteHostingRequest
2425
from .types import DnsRecords
2526
from .types import GetDomainDnsRecordsRequest
@@ -31,6 +32,7 @@
3132
from .types import ListOffersRequest
3233
from .types import ListOffersResponse
3334
from .types import RestoreHostingRequest
35+
from .types import Session
3436
from .types import UpdateHostingRequest
3537
from .api import WebhostingV1Alpha1API
3638

@@ -55,6 +57,7 @@
5557
"Hosting",
5658
"Offer",
5759
"CreateHostingRequest",
60+
"CreateSessionRequest",
5861
"DeleteHostingRequest",
5962
"DnsRecords",
6063
"GetDomainDnsRecordsRequest",
@@ -66,6 +69,7 @@
6669
"ListOffersRequest",
6770
"ListOffersResponse",
6871
"RestoreHostingRequest",
72+
"Session",
6973
"UpdateHostingRequest",
7074
"WebhostingV1Alpha1API",
7175
]

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ListControlPanelsResponse,
2626
ListHostingsResponse,
2727
ListOffersResponse,
28+
Session,
2829
UpdateHostingRequest,
2930
)
3031
from .content import (
@@ -36,6 +37,7 @@
3637
unmarshal_ListControlPanelsResponse,
3738
unmarshal_ListHostingsResponse,
3839
unmarshal_ListOffersResponse,
40+
unmarshal_Session,
3941
marshal_CreateHostingRequest,
4042
marshal_UpdateHostingRequest,
4143
)
@@ -570,3 +572,37 @@ async def list_control_panels_all(
570572
"page_size": page_size,
571573
},
572574
)
575+
576+
async def create_session(
577+
self,
578+
*,
579+
hosting_id: str,
580+
region: Optional[Region] = None,
581+
) -> Session:
582+
"""
583+
Create a user session.
584+
:param hosting_id: Hosting ID.
585+
:param region: Region to target. If none is passed will use default region from the config.
586+
:return: :class:`Session <Session>`
587+
588+
Usage:
589+
::
590+
591+
result = await api.create_session(
592+
hosting_id="example",
593+
)
594+
"""
595+
596+
param_region = validate_path_param(
597+
"region", region or self.client.default_region
598+
)
599+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
600+
601+
res = self._request(
602+
"POST",
603+
f"/webhosting/v1alpha1/regions/{param_region}/hostings/{param_hosting_id}/sessions",
604+
body={},
605+
)
606+
607+
self._throw_on_error(res)
608+
return unmarshal_Session(res.json())

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
OfferProduct,
2323
Offer,
2424
ListOffersResponse,
25+
Session,
2526
CreateHostingRequestDomainConfiguration,
2627
CreateHostingRequest,
2728
UpdateHostingRequest,
@@ -452,6 +453,21 @@ def unmarshal_ListOffersResponse(data: Any) -> ListOffersResponse:
452453
return ListOffersResponse(**args)
453454

454455

456+
def unmarshal_Session(data: Any) -> Session:
457+
if not isinstance(data, dict):
458+
raise TypeError(
459+
"Unmarshalling the type 'Session' failed as data isn't a dictionary."
460+
)
461+
462+
args: Dict[str, Any] = {}
463+
464+
field = data.get("url", None)
465+
if field is not None:
466+
args["url"] = field
467+
468+
return Session(**args)
469+
470+
455471
def marshal_CreateHostingRequestDomainConfiguration(
456472
request: CreateHostingRequestDomainConfiguration,
457473
defaults: ProfileDefaults,

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ class CreateHostingRequest:
474474
"""
475475

476476

477+
@dataclass
478+
class CreateSessionRequest:
479+
hosting_id: str
480+
"""
481+
Hosting ID.
482+
"""
483+
484+
region: Optional[Region]
485+
"""
486+
Region to target. If none is passed will use default region from the config.
487+
"""
488+
489+
477490
@dataclass
478491
class DeleteHostingRequest:
479492
hosting_id: str
@@ -682,6 +695,14 @@ class RestoreHostingRequest:
682695
"""
683696

684697

698+
@dataclass
699+
class Session:
700+
url: str
701+
"""
702+
Logged user's session URL.
703+
"""
704+
705+
685706
@dataclass
686707
class UpdateHostingRequest:
687708
hosting_id: str

scaleway/scaleway/webhosting/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .types import Hosting
2121
from .types import Offer
2222
from .types import CreateHostingRequest
23+
from .types import CreateSessionRequest
2324
from .types import DeleteHostingRequest
2425
from .types import DnsRecords
2526
from .types import GetDomainDnsRecordsRequest
@@ -31,6 +32,7 @@
3132
from .types import ListOffersRequest
3233
from .types import ListOffersResponse
3334
from .types import RestoreHostingRequest
35+
from .types import Session
3436
from .types import UpdateHostingRequest
3537
from .api import WebhostingV1Alpha1API
3638

@@ -55,6 +57,7 @@
5557
"Hosting",
5658
"Offer",
5759
"CreateHostingRequest",
60+
"CreateSessionRequest",
5861
"DeleteHostingRequest",
5962
"DnsRecords",
6063
"GetDomainDnsRecordsRequest",
@@ -66,6 +69,7 @@
6669
"ListOffersRequest",
6770
"ListOffersResponse",
6871
"RestoreHostingRequest",
72+
"Session",
6973
"UpdateHostingRequest",
7074
"WebhostingV1Alpha1API",
7175
]

scaleway/scaleway/webhosting/v1alpha1/api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ListControlPanelsResponse,
2626
ListHostingsResponse,
2727
ListOffersResponse,
28+
Session,
2829
UpdateHostingRequest,
2930
)
3031
from .content import (
@@ -36,6 +37,7 @@
3637
unmarshal_ListControlPanelsResponse,
3738
unmarshal_ListHostingsResponse,
3839
unmarshal_ListOffersResponse,
40+
unmarshal_Session,
3941
marshal_CreateHostingRequest,
4042
marshal_UpdateHostingRequest,
4143
)
@@ -570,3 +572,37 @@ def list_control_panels_all(
570572
"page_size": page_size,
571573
},
572574
)
575+
576+
def create_session(
577+
self,
578+
*,
579+
hosting_id: str,
580+
region: Optional[Region] = None,
581+
) -> Session:
582+
"""
583+
Create a user session.
584+
:param hosting_id: Hosting ID.
585+
:param region: Region to target. If none is passed will use default region from the config.
586+
:return: :class:`Session <Session>`
587+
588+
Usage:
589+
::
590+
591+
result = api.create_session(
592+
hosting_id="example",
593+
)
594+
"""
595+
596+
param_region = validate_path_param(
597+
"region", region or self.client.default_region
598+
)
599+
param_hosting_id = validate_path_param("hosting_id", hosting_id)
600+
601+
res = self._request(
602+
"POST",
603+
f"/webhosting/v1alpha1/regions/{param_region}/hostings/{param_hosting_id}/sessions",
604+
body={},
605+
)
606+
607+
self._throw_on_error(res)
608+
return unmarshal_Session(res.json())

scaleway/scaleway/webhosting/v1alpha1/marshalling.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
OfferProduct,
2323
Offer,
2424
ListOffersResponse,
25+
Session,
2526
CreateHostingRequestDomainConfiguration,
2627
CreateHostingRequest,
2728
UpdateHostingRequest,
@@ -452,6 +453,21 @@ def unmarshal_ListOffersResponse(data: Any) -> ListOffersResponse:
452453
return ListOffersResponse(**args)
453454

454455

456+
def unmarshal_Session(data: Any) -> Session:
457+
if not isinstance(data, dict):
458+
raise TypeError(
459+
"Unmarshalling the type 'Session' failed as data isn't a dictionary."
460+
)
461+
462+
args: Dict[str, Any] = {}
463+
464+
field = data.get("url", None)
465+
if field is not None:
466+
args["url"] = field
467+
468+
return Session(**args)
469+
470+
455471
def marshal_CreateHostingRequestDomainConfiguration(
456472
request: CreateHostingRequestDomainConfiguration,
457473
defaults: ProfileDefaults,

scaleway/scaleway/webhosting/v1alpha1/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ class CreateHostingRequest:
474474
"""
475475

476476

477+
@dataclass
478+
class CreateSessionRequest:
479+
hosting_id: str
480+
"""
481+
Hosting ID.
482+
"""
483+
484+
region: Optional[Region]
485+
"""
486+
Region to target. If none is passed will use default region from the config.
487+
"""
488+
489+
477490
@dataclass
478491
class DeleteHostingRequest:
479492
hosting_id: str
@@ -682,6 +695,14 @@ class RestoreHostingRequest:
682695
"""
683696

684697

698+
@dataclass
699+
class Session:
700+
url: str
701+
"""
702+
Logged user's session URL.
703+
"""
704+
705+
685706
@dataclass
686707
class UpdateHostingRequest:
687708
hosting_id: str

0 commit comments

Comments
 (0)