Skip to content

Commit

Permalink
feat(webhosting): add SyncDomainDnsRecords method (#799)
Browse files Browse the repository at this point in the history
Co-authored-by: Jules Castéran <[email protected]>
  • Loading branch information
scaleway-bot and Codelax authored Dec 24, 2024
1 parent 2bdbb0d commit 4968c75
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scaleway-async/scaleway_async/secret/v1beta1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def unmarshal_SecretVersion(data: Any) -> SecretVersion:
else:
args["updated_at"] = None

field = data.get("deleted_at", None)
if field is not None:
args["deleted_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["deleted_at"] = None

field = data.get("description", None)
if field is not None:
args["description"] = field
Expand Down
5 changes: 5 additions & 0 deletions scaleway-async/scaleway_async/secret/v1beta1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class SecretVersion:
Last update of the version.
"""

deleted_at: Optional[datetime]
"""
Date and time of the version's deletion.
"""

description: Optional[str]
"""
Description of the version.
Expand Down
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 @@ -24,6 +24,7 @@
from .types import CreateDatabaseRequestUser
from .types import CreateHostingRequestDomainConfiguration
from .types import OfferOptionRequest
from .types import SyncDomainDnsRecordsRequestRecord
from .types import DnsRecord
from .types import Nameserver
from .types import HostingUser
Expand Down Expand Up @@ -51,6 +52,7 @@
from .types import DatabaseApiUnassignDatabaseUserRequest
from .types import DnsApiCheckUserOwnsDomainRequest
from .types import DnsApiGetDomainDnsRecordsRequest
from .types import DnsApiSyncDomainDnsRecordsRequest
from .types import DnsRecords
from .types import FtpAccountApiChangeFtpAccountPasswordRequest
from .types import FtpAccountApiCreateFtpAccountRequest
Expand Down Expand Up @@ -116,6 +118,7 @@
"CreateDatabaseRequestUser",
"CreateHostingRequestDomainConfiguration",
"OfferOptionRequest",
"SyncDomainDnsRecordsRequestRecord",
"DnsRecord",
"Nameserver",
"HostingUser",
Expand Down Expand Up @@ -143,6 +146,7 @@
"DatabaseApiUnassignDatabaseUserRequest",
"DnsApiCheckUserOwnsDomainRequest",
"DnsApiGetDomainDnsRecordsRequest",
"DnsApiSyncDomainDnsRecordsRequest",
"DnsRecords",
"FtpAccountApiChangeFtpAccountPasswordRequest",
"FtpAccountApiCreateFtpAccountRequest",
Expand Down
58 changes: 58 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DatabaseApiUnassignDatabaseUserRequest,
DatabaseUser,
DnsApiCheckUserOwnsDomainRequest,
DnsApiSyncDomainDnsRecordsRequest,
DnsRecords,
FtpAccount,
FtpAccountApiChangeFtpAccountPasswordRequest,
Expand All @@ -59,6 +60,7 @@
ResetHostingPasswordResponse,
ResourceSummary,
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
)
from .content import (
Expand Down Expand Up @@ -89,6 +91,7 @@
marshal_DatabaseApiCreateDatabaseUserRequest,
marshal_DatabaseApiUnassignDatabaseUserRequest,
marshal_DnsApiCheckUserOwnsDomainRequest,
marshal_DnsApiSyncDomainDnsRecordsRequest,
marshal_FtpAccountApiChangeFtpAccountPasswordRequest,
marshal_FtpAccountApiCreateFtpAccountRequest,
marshal_HostingApiCreateHostingRequest,
Expand Down Expand Up @@ -824,6 +827,61 @@ async def check_user_owns_domain(
self._throw_on_error(res)
return unmarshal_CheckUserOwnsDomainResponse(res.json())

async def sync_domain_dns_records(
self,
*,
domain: str,
update_web_records: bool,
update_mail_records: bool,
update_all_records: bool,
region: Optional[Region] = None,
custom_records: Optional[List[SyncDomainDnsRecordsRequestRecord]] = None,
) -> DnsRecords:
"""
"Synchronize your DNS records on the Elements Console and on cPanel.".
:param domain: Domain for which the DNS records will be synchronized.
:param update_web_records: Whether or not to synchronize the web records.
:param update_mail_records: Whether or not to synchronize the mail records.
:param update_all_records: Whether or not to synchronize all types of records. This one has priority.
:param region: Region to target. If none is passed will use default region from the config.
:param custom_records: Custom records to synchronize.
:return: :class:`DnsRecords <DnsRecords>`
Usage:
::
result = await api.sync_domain_dns_records(
domain="example",
update_web_records=False,
update_mail_records=False,
update_all_records=False,
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_domain = validate_path_param("domain", domain)

res = self._request(
"POST",
f"/webhosting/v1/regions/{param_region}/domains/{param_domain}/sync-domain-dns-records",
body=marshal_DnsApiSyncDomainDnsRecordsRequest(
DnsApiSyncDomainDnsRecordsRequest(
domain=domain,
update_web_records=update_web_records,
update_mail_records=update_mail_records,
update_all_records=update_all_records,
region=region,
custom_records=custom_records,
),
self.client,
),
)

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


class WebhostingV1OfferAPI(API):
"""
Expand Down
41 changes: 41 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
DatabaseApiCreateDatabaseUserRequest,
DatabaseApiUnassignDatabaseUserRequest,
DnsApiCheckUserOwnsDomainRequest,
SyncDomainDnsRecordsRequestRecord,
DnsApiSyncDomainDnsRecordsRequest,
FtpAccountApiChangeFtpAccountPasswordRequest,
FtpAccountApiCreateFtpAccountRequest,
CreateHostingRequestDomainConfiguration,
Expand Down Expand Up @@ -939,6 +941,45 @@ def marshal_DnsApiCheckUserOwnsDomainRequest(
return output


def marshal_SyncDomainDnsRecordsRequestRecord(
request: SyncDomainDnsRecordsRequestRecord,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

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

if request.type_ is not None:
output["type"] = str(request.type_)

return output


def marshal_DnsApiSyncDomainDnsRecordsRequest(
request: DnsApiSyncDomainDnsRecordsRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

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

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

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

if request.custom_records is not None:
output["custom_records"] = [
marshal_SyncDomainDnsRecordsRequestRecord(item, defaults)
for item in request.custom_records
]

return output


def marshal_FtpAccountApiChangeFtpAccountPasswordRequest(
request: FtpAccountApiChangeFtpAccountPasswordRequest,
defaults: ProfileDefaults,
Expand Down
40 changes: 40 additions & 0 deletions scaleway-async/scaleway_async/webhosting/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ class OfferOptionRequest:
"""


@dataclass
class SyncDomainDnsRecordsRequestRecord:
name: str

type_: DnsRecordType


@dataclass
class DnsRecord:
name: str
Expand Down Expand Up @@ -859,6 +866,39 @@ class DnsApiGetDomainDnsRecordsRequest:
"""


@dataclass
class DnsApiSyncDomainDnsRecordsRequest:
domain: str
"""
Domain for which the DNS records will be synchronized.
"""

update_web_records: bool
"""
Whether or not to synchronize the web records.
"""

update_mail_records: bool
"""
Whether or not to synchronize the mail records.
"""

update_all_records: bool
"""
Whether or not to synchronize all types of records. This one has priority.
"""

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

custom_records: Optional[List[SyncDomainDnsRecordsRequestRecord]]
"""
Custom records to synchronize.
"""


@dataclass
class DnsRecords:
records: List[DnsRecord]
Expand Down
6 changes: 6 additions & 0 deletions scaleway/scaleway/secret/v1beta1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def unmarshal_SecretVersion(data: Any) -> SecretVersion:
else:
args["updated_at"] = None

field = data.get("deleted_at", None)
if field is not None:
args["deleted_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["deleted_at"] = None

field = data.get("description", None)
if field is not None:
args["description"] = field
Expand Down
5 changes: 5 additions & 0 deletions scaleway/scaleway/secret/v1beta1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class SecretVersion:
Last update of the version.
"""

deleted_at: Optional[datetime]
"""
Date and time of the version's deletion.
"""

description: Optional[str]
"""
Description of the version.
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 @@ -24,6 +24,7 @@
from .types import CreateDatabaseRequestUser
from .types import CreateHostingRequestDomainConfiguration
from .types import OfferOptionRequest
from .types import SyncDomainDnsRecordsRequestRecord
from .types import DnsRecord
from .types import Nameserver
from .types import HostingUser
Expand Down Expand Up @@ -51,6 +52,7 @@
from .types import DatabaseApiUnassignDatabaseUserRequest
from .types import DnsApiCheckUserOwnsDomainRequest
from .types import DnsApiGetDomainDnsRecordsRequest
from .types import DnsApiSyncDomainDnsRecordsRequest
from .types import DnsRecords
from .types import FtpAccountApiChangeFtpAccountPasswordRequest
from .types import FtpAccountApiCreateFtpAccountRequest
Expand Down Expand Up @@ -116,6 +118,7 @@
"CreateDatabaseRequestUser",
"CreateHostingRequestDomainConfiguration",
"OfferOptionRequest",
"SyncDomainDnsRecordsRequestRecord",
"DnsRecord",
"Nameserver",
"HostingUser",
Expand Down Expand Up @@ -143,6 +146,7 @@
"DatabaseApiUnassignDatabaseUserRequest",
"DnsApiCheckUserOwnsDomainRequest",
"DnsApiGetDomainDnsRecordsRequest",
"DnsApiSyncDomainDnsRecordsRequest",
"DnsRecords",
"FtpAccountApiChangeFtpAccountPasswordRequest",
"FtpAccountApiCreateFtpAccountRequest",
Expand Down
58 changes: 58 additions & 0 deletions scaleway/scaleway/webhosting/v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DatabaseApiUnassignDatabaseUserRequest,
DatabaseUser,
DnsApiCheckUserOwnsDomainRequest,
DnsApiSyncDomainDnsRecordsRequest,
DnsRecords,
FtpAccount,
FtpAccountApiChangeFtpAccountPasswordRequest,
Expand All @@ -59,6 +60,7 @@
ResetHostingPasswordResponse,
ResourceSummary,
Session,
SyncDomainDnsRecordsRequestRecord,
Website,
)
from .content import (
Expand Down Expand Up @@ -89,6 +91,7 @@
marshal_DatabaseApiCreateDatabaseUserRequest,
marshal_DatabaseApiUnassignDatabaseUserRequest,
marshal_DnsApiCheckUserOwnsDomainRequest,
marshal_DnsApiSyncDomainDnsRecordsRequest,
marshal_FtpAccountApiChangeFtpAccountPasswordRequest,
marshal_FtpAccountApiCreateFtpAccountRequest,
marshal_HostingApiCreateHostingRequest,
Expand Down Expand Up @@ -824,6 +827,61 @@ def check_user_owns_domain(
self._throw_on_error(res)
return unmarshal_CheckUserOwnsDomainResponse(res.json())

def sync_domain_dns_records(
self,
*,
domain: str,
update_web_records: bool,
update_mail_records: bool,
update_all_records: bool,
region: Optional[Region] = None,
custom_records: Optional[List[SyncDomainDnsRecordsRequestRecord]] = None,
) -> DnsRecords:
"""
"Synchronize your DNS records on the Elements Console and on cPanel.".
:param domain: Domain for which the DNS records will be synchronized.
:param update_web_records: Whether or not to synchronize the web records.
:param update_mail_records: Whether or not to synchronize the mail records.
:param update_all_records: Whether or not to synchronize all types of records. This one has priority.
:param region: Region to target. If none is passed will use default region from the config.
:param custom_records: Custom records to synchronize.
:return: :class:`DnsRecords <DnsRecords>`
Usage:
::
result = api.sync_domain_dns_records(
domain="example",
update_web_records=False,
update_mail_records=False,
update_all_records=False,
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_domain = validate_path_param("domain", domain)

res = self._request(
"POST",
f"/webhosting/v1/regions/{param_region}/domains/{param_domain}/sync-domain-dns-records",
body=marshal_DnsApiSyncDomainDnsRecordsRequest(
DnsApiSyncDomainDnsRecordsRequest(
domain=domain,
update_web_records=update_web_records,
update_mail_records=update_mail_records,
update_all_records=update_all_records,
region=region,
custom_records=custom_records,
),
self.client,
),
)

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


class WebhostingV1OfferAPI(API):
"""
Expand Down
Loading

0 comments on commit 4968c75

Please sign in to comment.