Skip to content
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

feat: add TLD endpoints #54

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions transip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def __init__(
self.colocations: Type['ApiService'] = (
objects.ColocationService(self) # type: ignore
)
self.tlds: Type['ApiService'] = (
objects.TldService(self) # type: ignore
)

@property
def url(self) -> str:
Expand Down
103 changes: 101 additions & 2 deletions transip/v6/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,20 @@ class DomainService(CreateMixin, GetMixin, DeleteMixin, ListMixin, ApiService):
("domainName",), # required
("contacts", "nameservers", "dnsEntries") # optional
)


class Tld(ApiObject):

_id_attr: str = "name"


class TldService(GetMixin, ListMixin, ApiService):

_path: str = "/tlds"
_obj_cls: Optional[Type[ApiObject]] = Tld

_resp_list_attr: str = "tlds"
_resp_get_attr: str = "tld"


class InvoiceItem(ApiObject):
Expand Down Expand Up @@ -448,9 +462,94 @@ class InvoiceService(GetMixin, ListMixin, ApiService):
_resp_get_attr: str = "invoice"


class VpsAddon(ApiObject):

_id_attr: str = "name"


class VpsAddonService(ListMixin, ApiService):
"""Service to manage addons of a VPS."""

_path: str = "/vps/{parent_id}/addons"
_obj_cls: Optional[Type[ApiObject]] = VpsAddon

_resp_list_attr: str = "addons"

def list(self, needle: Optional[str] = None) -> List[Type[ApiObject]]:
"""
Retrieve a list of addons.
Overwrites the default list() method of the ListMixin as the addons
are stored in further down in the result dictionary.
"""
objs: List[Type[ApiObject]] = []
data = self.client.get(self.path)[self._resp_list_attr]
haystack = []
# Loop over the individual product lists of all product categories,
# e.g. vps, haip
if needle is None:
haystack = data.values()
else:
haystack.append(data[needle])

for obj_list in data.values():
for obj in obj_list:
objs.append(self._obj_cls(self, obj)) # type: ignore
return objs


class VpsLicense(ApiObject):

_id_attr: str = "name"


class VpsLicenseService(ListMixin, ApiService):
"""Service to manage licenses of a VPS."""

_path: str = "/vps/{parent_id}/licenses"
_obj_cls: Optional[Type[ApiObject]] = VpsLicense

_resp_list_attr: str = "licenses"

def list(self, needle: Optional[str] = None) -> List[Type[ApiObject]]:
"""
Retrieve a list of licenses.
Overwrites the default list() method of the ListMixin as the licenses
are stored in further down in the result dictionary.
"""
objs: List[Type[ApiObject]] = []
data = self.client.get(self.path)[self._resp_list_attr]
haystack = []
# Loop over the individual product lists of all product categories,
# e.g. vps, haip
if needle is None:
haystack = data.values()
else:
haystack.append(data[needle])

for obj_list in haystack:
for obj in obj_list:
objs.append(self._obj_cls(self, obj)) # type: ignore
return objs

class Vps(ApiObject):

_id_attr: str = "name"

@property
def addons(self) -> VpsAddonService:
"""Return the service to manage the addons of the VPS."""
return VpsAddonService(
self.service.client,
parent=self # type: ignore
)

@property
def licenses(self) -> VpsLicenseService:
"""Return the service to manage the licenses of the VPS."""
return VpsLicenseService(
self.service.client,
parent=self # type: ignore
)


class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService):
Expand All @@ -460,8 +559,8 @@ class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService):

_resp_list_attr: str = "vpss"
_resp_get_attr: str = "vps"


class Colocation(ApiObject):

_id_attr: str = "name"
Expand Down