|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2020, 2021 Roald Nefs <info@roaldnefs.com> |
| 4 | +# |
| 5 | +# This file is part of python-transip. |
| 6 | + |
| 7 | +# python-transip is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | + |
| 12 | +# python-transip is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | + |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with python-transip. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +from typing import Optional, Type |
| 21 | + |
| 22 | +from transip.base import ApiService, ApiObject |
| 23 | +from transip.mixins import ( |
| 24 | + GetMixin, DeleteMixin, ListMixin, CreateMixin, UpdateMixin, |
| 25 | + CreateAttrsTuple, UpdateAttrsTuple |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +class AvailabilityZone(ApiObject): |
| 30 | + |
| 31 | + _id_attr: str = "name" |
| 32 | + |
| 33 | + |
| 34 | +class AvailabilityZoneService(ListMixin, ApiService): |
| 35 | + |
| 36 | + _path: str = "/availability-zones" |
| 37 | + _obj_cls: Optional[Type[ApiObject]] = AvailabilityZone |
| 38 | + |
| 39 | + _resp_list_attr: str = "availabilityZones" |
| 40 | + |
| 41 | + |
| 42 | +class SshKey(ApiObject): |
| 43 | + |
| 44 | + _id_attr: str = "id" |
| 45 | + |
| 46 | + |
| 47 | +class SshKeyService(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, ListMixin, |
| 48 | + ApiService): |
| 49 | + |
| 50 | + _path: str = "/ssh-keys" |
| 51 | + _obj_cls: Optional[Type[ApiObject]] = SshKey |
| 52 | + |
| 53 | + _resp_list_attr: str = "sshKeys" |
| 54 | + _resp_get_attr: str = "sshKey" |
| 55 | + |
| 56 | + _create_attrs: Optional[CreateAttrsTuple] = ( |
| 57 | + ("sshKey",), # required |
| 58 | + ("description",) # optional |
| 59 | + ) |
| 60 | + _update_attrs: Optional[UpdateAttrsTuple] = ( |
| 61 | + ("description",), # required |
| 62 | + tuple() # optional |
| 63 | + ) |
| 64 | + |
| 65 | + |
| 66 | +class WhoisContact(ApiObject): |
| 67 | + |
| 68 | + _id_attr: Optional[str] = None |
| 69 | + |
| 70 | + |
| 71 | +class WhoisContactService(ListMixin, ApiService): |
| 72 | + """Service to manage domain contacts of a domain.""" |
| 73 | + |
| 74 | + _path: str = "/domains/{parent_id}/contacts" |
| 75 | + _obj_cls: Optional[Type[ApiObject]] = WhoisContact |
| 76 | + |
| 77 | + _resp_list_attr: str = "contacts" |
| 78 | + |
| 79 | + |
| 80 | +class DnsEntry(ApiObject): |
| 81 | + |
| 82 | + _id_attr: Optional[str] = None |
| 83 | + |
| 84 | + |
| 85 | +class DnsEntryService(CreateMixin, ListMixin, ApiService): |
| 86 | + """Service to manage DNS entries of a domain.""" |
| 87 | + |
| 88 | + _path: str = "/domains/{parent_id}/dns" |
| 89 | + _obj_cls: Optional[Type[ApiObject]] = DnsEntry |
| 90 | + |
| 91 | + _resp_list_attr: str = "dnsEntries" |
| 92 | + _req_create_attr: str = "dnsEntry" |
| 93 | + _create_attrs: Optional[CreateAttrsTuple] = ( |
| 94 | + ("name", "expire", "type", "content"), # required |
| 95 | + tuple() # optional |
| 96 | + ) |
| 97 | + |
| 98 | + |
| 99 | +class Nameserver(ApiObject): |
| 100 | + |
| 101 | + _id_attr: Optional[str] = "hostname" |
| 102 | + |
| 103 | + |
| 104 | +class NameserverService(ListMixin, ApiService): |
| 105 | + """Service to nameservers of a domain.""" |
| 106 | + |
| 107 | + _path: str = "/domains/{parent_id}/nameservers" |
| 108 | + _obj_cls: Optional[Type[ApiObject]] = Nameserver |
| 109 | + |
| 110 | + _resp_list_attr: str = "nameservers" |
| 111 | + |
| 112 | + |
| 113 | +class Domain(ApiObject): |
| 114 | + |
| 115 | + _id_attr: str = "name" |
| 116 | + |
| 117 | + @property |
| 118 | + def contacts(self) -> WhoisContactService: |
| 119 | + """Return the service to manage the WHOIS contacts of the domain.""" |
| 120 | + return WhoisContactService( |
| 121 | + self.service.client, |
| 122 | + parent=self # type: ignore |
| 123 | + ) |
| 124 | + |
| 125 | + @property |
| 126 | + def dns(self) -> DnsEntryService: |
| 127 | + """Return the service to manage the DNS entries of the domain.""" |
| 128 | + return DnsEntryService( |
| 129 | + self.service.client, |
| 130 | + parent=self # type: ignore |
| 131 | + ) |
| 132 | + |
| 133 | + @property |
| 134 | + def nameservers(self) -> NameserverService: |
| 135 | + """Return the service to manage the nameservers of the domain.""" |
| 136 | + return NameserverService( |
| 137 | + self.service.client, |
| 138 | + parent=self # type: ignore |
| 139 | + ) |
| 140 | + |
| 141 | + |
| 142 | +class DomainService(CreateMixin, GetMixin, DeleteMixin, ListMixin, ApiService): |
| 143 | + """Service to manage domains.""" |
| 144 | + |
| 145 | + _path: str = "/domains" |
| 146 | + _obj_cls: Optional[Type[ApiObject]] = Domain |
| 147 | + |
| 148 | + _resp_list_attr: str = "domains" |
| 149 | + _resp_get_attr: str = "domain" |
| 150 | + |
| 151 | + _create_attrs: Optional[CreateAttrsTuple] = ( |
| 152 | + ("domainName",), # required |
| 153 | + ("contacts", "nameservers", "dnsEntries") # optional |
| 154 | + ) |
| 155 | + |
| 156 | + |
| 157 | +class Invoice(ApiObject): |
| 158 | + |
| 159 | + _id_attr: str = "invoiceNumber" |
| 160 | + |
| 161 | + |
| 162 | +class InvoiceService(GetMixin, ListMixin, ApiService): |
| 163 | + |
| 164 | + _path: str = "/invoices" |
| 165 | + _obj_cls: Optional[Type[ApiObject]] = Invoice |
| 166 | + |
| 167 | + _resp_list_attr: str = "invoices" |
| 168 | + _resp_get_attr: str = "invoice" |
| 169 | + |
| 170 | + |
| 171 | +class Vps(ApiObject): |
| 172 | + |
| 173 | + _id_attr: str = "name" |
| 174 | + |
| 175 | + |
| 176 | +class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService): |
| 177 | + |
| 178 | + _path: str = "/vps" |
| 179 | + _obj_cls: Optional[Type[ApiObject]] = Vps |
| 180 | + |
| 181 | + _resp_list_attr: str = "vpss" |
| 182 | + _resp_get_attr: str = "vps" |
0 commit comments