Skip to content

Commit cfb0bfd

Browse files
authored
feat(webhosting): edit method to allow user creation (#792)
1 parent 1a5422b commit cfb0bfd

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .types import PlatformControlPanelUrls
2222
from .types import OfferOption
2323
from .types import PlatformControlPanel
24+
from .types import CreateDatabaseRequestUser
2425
from .types import CreateHostingRequestDomainConfiguration
2526
from .types import OfferOptionRequest
2627
from .types import DnsRecord
@@ -112,6 +113,7 @@
112113
"PlatformControlPanelUrls",
113114
"OfferOption",
114115
"PlatformControlPanel",
116+
"CreateDatabaseRequestUser",
115117
"CreateHostingRequestDomainConfiguration",
116118
"OfferOptionRequest",
117119
"DnsRecord",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ListWebsitesRequestOrderBy,
2525
CheckUserOwnsDomainResponse,
2626
ControlPanel,
27+
CreateDatabaseRequestUser,
2728
CreateHostingRequestDomainConfiguration,
2829
Database,
2930
DatabaseApiAssignDatabaseUserRequest,
@@ -185,12 +186,18 @@ async def create_database(
185186
hosting_id: str,
186187
database_name: str,
187188
region: Optional[Region] = None,
189+
new_user: Optional[CreateDatabaseRequestUser] = None,
190+
existing_username: Optional[str] = None,
188191
) -> Database:
189192
"""
190193
"Create a new database within your hosting plan".
191194
:param hosting_id: UUID of the hosting plan where the database will be created.
192195
:param database_name: Name of the database to be created.
193196
:param region: Region to target. If none is passed will use default region from the config.
197+
:param new_user: (Optional) Username and password to create a user and link to the database.
198+
One-Of ('user'): at most one of 'new_user', 'existing_username' could be set.
199+
:param existing_username: (Optional) Username to link an existing user to the database.
200+
One-Of ('user'): at most one of 'new_user', 'existing_username' could be set.
194201
:return: :class:`Database <Database>`
195202
196203
Usage:
@@ -215,6 +222,8 @@ async def create_database(
215222
hosting_id=hosting_id,
216223
database_name=database_name,
217224
region=region,
225+
new_user=new_user,
226+
existing_username=existing_username,
218227
),
219228
self.client,
220229
),

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from scaleway_core.bridge import (
99
unmarshal_Money,
1010
)
11+
from scaleway_core.utils import (
12+
OneOfPossibility,
13+
resolve_one_of,
14+
)
1115
from .types import (
1216
DatabaseUser,
1317
Database,
@@ -40,6 +44,7 @@
4044
Session,
4145
DatabaseApiAssignDatabaseUserRequest,
4246
DatabaseApiChangeDatabaseUserPasswordRequest,
47+
CreateDatabaseRequestUser,
4348
DatabaseApiCreateDatabaseRequest,
4449
DatabaseApiCreateDatabaseUserRequest,
4550
DatabaseApiUnassignDatabaseUserRequest,
@@ -852,11 +857,34 @@ def marshal_DatabaseApiChangeDatabaseUserPasswordRequest(
852857
return output
853858

854859

860+
def marshal_CreateDatabaseRequestUser(
861+
request: CreateDatabaseRequestUser,
862+
defaults: ProfileDefaults,
863+
) -> Dict[str, Any]:
864+
output: Dict[str, Any] = {}
865+
866+
if request.username is not None:
867+
output["username"] = request.username
868+
869+
if request.password is not None:
870+
output["password"] = request.password
871+
872+
return output
873+
874+
855875
def marshal_DatabaseApiCreateDatabaseRequest(
856876
request: DatabaseApiCreateDatabaseRequest,
857877
defaults: ProfileDefaults,
858878
) -> Dict[str, Any]:
859879
output: Dict[str, Any] = {}
880+
output.update(
881+
resolve_one_of(
882+
[
883+
OneOfPossibility("new_user", request.new_user),
884+
OneOfPossibility("existing_username", request.existing_username),
885+
]
886+
),
887+
)
860888

861889
if request.database_name is not None:
862890
output["database_name"] = request.database_name

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ class PlatformControlPanel:
243243
"""
244244

245245

246+
@dataclass
247+
class CreateDatabaseRequestUser:
248+
username: str
249+
250+
password: str
251+
252+
246253
@dataclass
247254
class CreateHostingRequestDomainConfiguration:
248255
update_nameservers: bool
@@ -632,6 +639,10 @@ class DatabaseApiCreateDatabaseRequest:
632639
Region to target. If none is passed will use default region from the config.
633640
"""
634641

642+
new_user: Optional[CreateDatabaseRequestUser]
643+
644+
existing_username: Optional[str]
645+
635646

636647
@dataclass
637648
class DatabaseApiCreateDatabaseUserRequest:

scaleway/scaleway/webhosting/v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .types import PlatformControlPanelUrls
2222
from .types import OfferOption
2323
from .types import PlatformControlPanel
24+
from .types import CreateDatabaseRequestUser
2425
from .types import CreateHostingRequestDomainConfiguration
2526
from .types import OfferOptionRequest
2627
from .types import DnsRecord
@@ -112,6 +113,7 @@
112113
"PlatformControlPanelUrls",
113114
"OfferOption",
114115
"PlatformControlPanel",
116+
"CreateDatabaseRequestUser",
115117
"CreateHostingRequestDomainConfiguration",
116118
"OfferOptionRequest",
117119
"DnsRecord",

scaleway/scaleway/webhosting/v1/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ListWebsitesRequestOrderBy,
2525
CheckUserOwnsDomainResponse,
2626
ControlPanel,
27+
CreateDatabaseRequestUser,
2728
CreateHostingRequestDomainConfiguration,
2829
Database,
2930
DatabaseApiAssignDatabaseUserRequest,
@@ -185,12 +186,18 @@ def create_database(
185186
hosting_id: str,
186187
database_name: str,
187188
region: Optional[Region] = None,
189+
new_user: Optional[CreateDatabaseRequestUser] = None,
190+
existing_username: Optional[str] = None,
188191
) -> Database:
189192
"""
190193
"Create a new database within your hosting plan".
191194
:param hosting_id: UUID of the hosting plan where the database will be created.
192195
:param database_name: Name of the database to be created.
193196
:param region: Region to target. If none is passed will use default region from the config.
197+
:param new_user: (Optional) Username and password to create a user and link to the database.
198+
One-Of ('user'): at most one of 'new_user', 'existing_username' could be set.
199+
:param existing_username: (Optional) Username to link an existing user to the database.
200+
One-Of ('user'): at most one of 'new_user', 'existing_username' could be set.
194201
:return: :class:`Database <Database>`
195202
196203
Usage:
@@ -215,6 +222,8 @@ def create_database(
215222
hosting_id=hosting_id,
216223
database_name=database_name,
217224
region=region,
225+
new_user=new_user,
226+
existing_username=existing_username,
218227
),
219228
self.client,
220229
),

scaleway/scaleway/webhosting/v1/marshalling.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from scaleway_core.bridge import (
99
unmarshal_Money,
1010
)
11+
from scaleway_core.utils import (
12+
OneOfPossibility,
13+
resolve_one_of,
14+
)
1115
from .types import (
1216
DatabaseUser,
1317
Database,
@@ -40,6 +44,7 @@
4044
Session,
4145
DatabaseApiAssignDatabaseUserRequest,
4246
DatabaseApiChangeDatabaseUserPasswordRequest,
47+
CreateDatabaseRequestUser,
4348
DatabaseApiCreateDatabaseRequest,
4449
DatabaseApiCreateDatabaseUserRequest,
4550
DatabaseApiUnassignDatabaseUserRequest,
@@ -852,11 +857,34 @@ def marshal_DatabaseApiChangeDatabaseUserPasswordRequest(
852857
return output
853858

854859

860+
def marshal_CreateDatabaseRequestUser(
861+
request: CreateDatabaseRequestUser,
862+
defaults: ProfileDefaults,
863+
) -> Dict[str, Any]:
864+
output: Dict[str, Any] = {}
865+
866+
if request.username is not None:
867+
output["username"] = request.username
868+
869+
if request.password is not None:
870+
output["password"] = request.password
871+
872+
return output
873+
874+
855875
def marshal_DatabaseApiCreateDatabaseRequest(
856876
request: DatabaseApiCreateDatabaseRequest,
857877
defaults: ProfileDefaults,
858878
) -> Dict[str, Any]:
859879
output: Dict[str, Any] = {}
880+
output.update(
881+
resolve_one_of(
882+
[
883+
OneOfPossibility("new_user", request.new_user),
884+
OneOfPossibility("existing_username", request.existing_username),
885+
]
886+
),
887+
)
860888

861889
if request.database_name is not None:
862890
output["database_name"] = request.database_name

scaleway/scaleway/webhosting/v1/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ class PlatformControlPanel:
243243
"""
244244

245245

246+
@dataclass
247+
class CreateDatabaseRequestUser:
248+
username: str
249+
250+
password: str
251+
252+
246253
@dataclass
247254
class CreateHostingRequestDomainConfiguration:
248255
update_nameservers: bool
@@ -632,6 +639,10 @@ class DatabaseApiCreateDatabaseRequest:
632639
Region to target. If none is passed will use default region from the config.
633640
"""
634641

642+
new_user: Optional[CreateDatabaseRequestUser]
643+
644+
existing_username: Optional[str]
645+
635646

636647
@dataclass
637648
class DatabaseApiCreateDatabaseUserRequest:

0 commit comments

Comments
 (0)