Skip to content

feat(webhosting): add a magic link autologin url for webhosting #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .types import Hosting
from .types import Offer
from .types import CreateHostingRequest
from .types import CreateSessionRequest
from .types import DeleteHostingRequest
from .types import DnsRecords
from .types import GetDomainDnsRecordsRequest
Expand All @@ -31,6 +32,7 @@
from .types import ListOffersRequest
from .types import ListOffersResponse
from .types import RestoreHostingRequest
from .types import Session
from .types import UpdateHostingRequest
from .api import WebhostingV1Alpha1API

Expand All @@ -55,6 +57,7 @@
"Hosting",
"Offer",
"CreateHostingRequest",
"CreateSessionRequest",
"DeleteHostingRequest",
"DnsRecords",
"GetDomainDnsRecordsRequest",
Expand All @@ -66,6 +69,7 @@
"ListOffersRequest",
"ListOffersResponse",
"RestoreHostingRequest",
"Session",
"UpdateHostingRequest",
"WebhostingV1Alpha1API",
]
36 changes: 36 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
ListControlPanelsResponse,
ListHostingsResponse,
ListOffersResponse,
Session,
UpdateHostingRequest,
)
from .content import (
Expand All @@ -36,6 +37,7 @@
unmarshal_ListControlPanelsResponse,
unmarshal_ListHostingsResponse,
unmarshal_ListOffersResponse,
unmarshal_Session,
marshal_CreateHostingRequest,
marshal_UpdateHostingRequest,
)
Expand Down Expand Up @@ -570,3 +572,37 @@ async def list_control_panels_all(
"page_size": page_size,
},
)

async def create_session(
self,
*,
hosting_id: str,
region: Optional[Region] = None,
) -> Session:
"""
Create a user session.
:param hosting_id: Hosting ID.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Session <Session>`

Usage:
::

result = await api.create_session(
hosting_id="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/v1alpha1/regions/{param_region}/hostings/{param_hosting_id}/sessions",
body={},
)

self._throw_on_error(res)
return unmarshal_Session(res.json())
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
OfferProduct,
Offer,
ListOffersResponse,
Session,
CreateHostingRequestDomainConfiguration,
CreateHostingRequest,
UpdateHostingRequest,
Expand Down Expand Up @@ -452,6 +453,21 @@ def unmarshal_ListOffersResponse(data: Any) -> ListOffersResponse:
return ListOffersResponse(**args)


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

args: Dict[str, Any] = {}

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

return Session(**args)


def marshal_CreateHostingRequestDomainConfiguration(
request: CreateHostingRequestDomainConfiguration,
defaults: ProfileDefaults,
Expand Down
21 changes: 21 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ class CreateHostingRequest:
"""


@dataclass
class CreateSessionRequest:
hosting_id: str
"""
Hosting ID.
"""

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


@dataclass
class DeleteHostingRequest:
hosting_id: str
Expand Down Expand Up @@ -682,6 +695,14 @@ class RestoreHostingRequest:
"""


@dataclass
class Session:
url: str
"""
Logged user's session URL.
"""


@dataclass
class UpdateHostingRequest:
hosting_id: str
Expand Down
4 changes: 4 additions & 0 deletions scaleway/scaleway/webhosting/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .types import Hosting
from .types import Offer
from .types import CreateHostingRequest
from .types import CreateSessionRequest
from .types import DeleteHostingRequest
from .types import DnsRecords
from .types import GetDomainDnsRecordsRequest
Expand All @@ -31,6 +32,7 @@
from .types import ListOffersRequest
from .types import ListOffersResponse
from .types import RestoreHostingRequest
from .types import Session
from .types import UpdateHostingRequest
from .api import WebhostingV1Alpha1API

Expand All @@ -55,6 +57,7 @@
"Hosting",
"Offer",
"CreateHostingRequest",
"CreateSessionRequest",
"DeleteHostingRequest",
"DnsRecords",
"GetDomainDnsRecordsRequest",
Expand All @@ -66,6 +69,7 @@
"ListOffersRequest",
"ListOffersResponse",
"RestoreHostingRequest",
"Session",
"UpdateHostingRequest",
"WebhostingV1Alpha1API",
]
36 changes: 36 additions & 0 deletions scaleway/scaleway/webhosting/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
ListControlPanelsResponse,
ListHostingsResponse,
ListOffersResponse,
Session,
UpdateHostingRequest,
)
from .content import (
Expand All @@ -36,6 +37,7 @@
unmarshal_ListControlPanelsResponse,
unmarshal_ListHostingsResponse,
unmarshal_ListOffersResponse,
unmarshal_Session,
marshal_CreateHostingRequest,
marshal_UpdateHostingRequest,
)
Expand Down Expand Up @@ -570,3 +572,37 @@ def list_control_panels_all(
"page_size": page_size,
},
)

def create_session(
self,
*,
hosting_id: str,
region: Optional[Region] = None,
) -> Session:
"""
Create a user session.
:param hosting_id: Hosting ID.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Session <Session>`

Usage:
::

result = api.create_session(
hosting_id="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/v1alpha1/regions/{param_region}/hostings/{param_hosting_id}/sessions",
body={},
)

self._throw_on_error(res)
return unmarshal_Session(res.json())
16 changes: 16 additions & 0 deletions scaleway/scaleway/webhosting/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
OfferProduct,
Offer,
ListOffersResponse,
Session,
CreateHostingRequestDomainConfiguration,
CreateHostingRequest,
UpdateHostingRequest,
Expand Down Expand Up @@ -452,6 +453,21 @@ def unmarshal_ListOffersResponse(data: Any) -> ListOffersResponse:
return ListOffersResponse(**args)


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

args: Dict[str, Any] = {}

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

return Session(**args)


def marshal_CreateHostingRequestDomainConfiguration(
request: CreateHostingRequestDomainConfiguration,
defaults: ProfileDefaults,
Expand Down
21 changes: 21 additions & 0 deletions scaleway/scaleway/webhosting/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ class CreateHostingRequest:
"""


@dataclass
class CreateSessionRequest:
hosting_id: str
"""
Hosting ID.
"""

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


@dataclass
class DeleteHostingRequest:
hosting_id: str
Expand Down Expand Up @@ -682,6 +695,14 @@ class RestoreHostingRequest:
"""


@dataclass
class Session:
url: str
"""
Logged user's session URL.
"""


@dataclass
class UpdateHostingRequest:
hosting_id: str
Expand Down