cloudfloordns.client.sync.domain
1# from dataclasses import dataclass, field 2from collections import ChainMap 3from typing import Optional, Union 4 5from cloudfloordns.models import Contact, Domain, DomainPayload, TLDPrice 6 7DEFAULT_PRIMARY_NS = "ns1.g02.cfdns.net" 8DEFAULT_LIMIT = 99999 9 10 11class Domains: 12 def __init__(self, client) -> None: 13 self._client = client 14 15 def _raw_pricelist(self, timeout=None) -> list: 16 """ 17 List all domains 18 """ 19 url = "/domain/tld/pricelist" 20 return self._client.get( 21 url, 22 # data=data, 23 timeout=timeout, 24 ) 25 26 def pricelist(self, timeout=None) -> list[TLDPrice]: 27 """ 28 List all domains 29 """ 30 res = self._raw_pricelist(timeout=timeout) 31 return [TLDPrice.model_validate(p) for p in res] 32 33 def get_by_name(self, domainname, zone_enabled=None, timeout=None): 34 res = self.list( 35 zone_enabled=zone_enabled, 36 timeout=timeout, 37 ) 38 return next((r for r in res if r.domainname == domainname), None) 39 40 def delete(self, domain: str, timeout=None): 41 url = f"/domain/{domain}/delete_domain" 42 return self._client.delete( 43 url, 44 timeout=timeout, 45 ) 46 47 def raw_get(self, domain, timeout=None) -> Domain: 48 url = f"/domain/{domain}" 49 return self._client.get( 50 url, 51 timeout=timeout, 52 ) 53 54 def get(self, domain, timeout=None) -> Domain: 55 res = self.raw_get(domain, timeout=timeout) 56 return Domain.model_validate(res) 57 58 def raw_register(self, payload: DomainPayload, timeout=None) -> dict: 59 """ 60 This will register a domain on CloudfloorDNS. 61 The registration can be cancelled during a short period (to be confirmed) 62 """ 63 url = "/domain" 64 return self._client.post( 65 url, 66 data=payload.model_dump(by_alias=True), 67 timeout=timeout, 68 ) 69 70 def raw_registry_info(self, domain, timeout=None) -> dict: 71 url = f"/domain/{domain}/get_registry_info" 72 return self._client.get( 73 url, 74 timeout=timeout, 75 ) 76 77 def registry_info(self, domain, timeout=None) -> Domain: 78 """ 79 Return the data currently stored in the registry. 80 NOTE: 81 - The result may differ from `get` method (e.g. if the data push failed) 82 - This is not similar as a WHOIS command since it retrieves redacted data as well 83 """ 84 res = self.raw_registry_info(domain, timeout=timeout) 85 return Domain.model_validate(res) 86 87 def raw_status(self, domain, timeout=None) -> dict: 88 url = f"/domain/{domain}/status" 89 return self._client.get( 90 url, 91 timeout=timeout, 92 ) 93 94 def raw_update( 95 self, domain: str, payload: Union[Domain, DomainPayload], timeout=None 96 ): 97 if isinstance(payload, Domain): 98 payload = payload.register_payload() 99 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 100 url = f"/domain/{domain}" 101 data = payload.dump_for_update() 102 return self._client.patch( 103 url, 104 data=data, 105 timeout=timeout, 106 ) 107 108 def _raw_list(self, limit=None, offset=None, timeout=None) -> list: 109 """ 110 List all domains 111 """ 112 data = {"limit": limit or DEFAULT_LIMIT} 113 if offset: 114 data["offset"] = offset 115 url = "/domain" 116 return self._client.get( 117 url, 118 data=data, 119 timeout=timeout, 120 ) 121 122 def list(self, limit=None, offset=None, timeout=None) -> list[Domain]: 123 """ 124 List all domains 125 """ 126 res = self._raw_list(limit=limit, offset=offset, timeout=timeout) 127 return [Domain.model_validate(d) for d in res] 128 129 # Only updating contacts does not seem to work 130 def update_contact( 131 self, 132 domain: str, 133 owner: Optional[Contact] = None, 134 admin: Optional[Contact] = None, 135 tech: Optional[Contact] = None, 136 bill: Optional[Contact] = None, 137 timeout=None, 138 ): 139 """ 140 This method works according to the documentation, but some required parameters might be missing. 141 """ 142 converted = ( 143 d 144 for d in ( 145 owner and owner.as_owner(), 146 admin and admin.as_admin(), 147 tech and tech.as_tech(), 148 bill and bill.as_bill(), 149 ) 150 if d 151 ) 152 payload = dict(ChainMap(*converted)) 153 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 154 url = f"/domain/{domain}" 155 return self._client.patch( 156 url, 157 data=payload, 158 timeout=timeout, 159 ) 160 161 162__all__ = [ 163 "Domains", 164]
class
Domains:
12class Domains: 13 def __init__(self, client) -> None: 14 self._client = client 15 16 def _raw_pricelist(self, timeout=None) -> list: 17 """ 18 List all domains 19 """ 20 url = "/domain/tld/pricelist" 21 return self._client.get( 22 url, 23 # data=data, 24 timeout=timeout, 25 ) 26 27 def pricelist(self, timeout=None) -> list[TLDPrice]: 28 """ 29 List all domains 30 """ 31 res = self._raw_pricelist(timeout=timeout) 32 return [TLDPrice.model_validate(p) for p in res] 33 34 def get_by_name(self, domainname, zone_enabled=None, timeout=None): 35 res = self.list( 36 zone_enabled=zone_enabled, 37 timeout=timeout, 38 ) 39 return next((r for r in res if r.domainname == domainname), None) 40 41 def delete(self, domain: str, timeout=None): 42 url = f"/domain/{domain}/delete_domain" 43 return self._client.delete( 44 url, 45 timeout=timeout, 46 ) 47 48 def raw_get(self, domain, timeout=None) -> Domain: 49 url = f"/domain/{domain}" 50 return self._client.get( 51 url, 52 timeout=timeout, 53 ) 54 55 def get(self, domain, timeout=None) -> Domain: 56 res = self.raw_get(domain, timeout=timeout) 57 return Domain.model_validate(res) 58 59 def raw_register(self, payload: DomainPayload, timeout=None) -> dict: 60 """ 61 This will register a domain on CloudfloorDNS. 62 The registration can be cancelled during a short period (to be confirmed) 63 """ 64 url = "/domain" 65 return self._client.post( 66 url, 67 data=payload.model_dump(by_alias=True), 68 timeout=timeout, 69 ) 70 71 def raw_registry_info(self, domain, timeout=None) -> dict: 72 url = f"/domain/{domain}/get_registry_info" 73 return self._client.get( 74 url, 75 timeout=timeout, 76 ) 77 78 def registry_info(self, domain, timeout=None) -> Domain: 79 """ 80 Return the data currently stored in the registry. 81 NOTE: 82 - The result may differ from `get` method (e.g. if the data push failed) 83 - This is not similar as a WHOIS command since it retrieves redacted data as well 84 """ 85 res = self.raw_registry_info(domain, timeout=timeout) 86 return Domain.model_validate(res) 87 88 def raw_status(self, domain, timeout=None) -> dict: 89 url = f"/domain/{domain}/status" 90 return self._client.get( 91 url, 92 timeout=timeout, 93 ) 94 95 def raw_update( 96 self, domain: str, payload: Union[Domain, DomainPayload], timeout=None 97 ): 98 if isinstance(payload, Domain): 99 payload = payload.register_payload() 100 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 101 url = f"/domain/{domain}" 102 data = payload.dump_for_update() 103 return self._client.patch( 104 url, 105 data=data, 106 timeout=timeout, 107 ) 108 109 def _raw_list(self, limit=None, offset=None, timeout=None) -> list: 110 """ 111 List all domains 112 """ 113 data = {"limit": limit or DEFAULT_LIMIT} 114 if offset: 115 data["offset"] = offset 116 url = "/domain" 117 return self._client.get( 118 url, 119 data=data, 120 timeout=timeout, 121 ) 122 123 def list(self, limit=None, offset=None, timeout=None) -> list[Domain]: 124 """ 125 List all domains 126 """ 127 res = self._raw_list(limit=limit, offset=offset, timeout=timeout) 128 return [Domain.model_validate(d) for d in res] 129 130 # Only updating contacts does not seem to work 131 def update_contact( 132 self, 133 domain: str, 134 owner: Optional[Contact] = None, 135 admin: Optional[Contact] = None, 136 tech: Optional[Contact] = None, 137 bill: Optional[Contact] = None, 138 timeout=None, 139 ): 140 """ 141 This method works according to the documentation, but some required parameters might be missing. 142 """ 143 converted = ( 144 d 145 for d in ( 146 owner and owner.as_owner(), 147 admin and admin.as_admin(), 148 tech and tech.as_tech(), 149 bill and bill.as_bill(), 150 ) 151 if d 152 ) 153 payload = dict(ChainMap(*converted)) 154 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 155 url = f"/domain/{domain}" 156 return self._client.patch( 157 url, 158 data=payload, 159 timeout=timeout, 160 )
27 def pricelist(self, timeout=None) -> list[TLDPrice]: 28 """ 29 List all domains 30 """ 31 res = self._raw_pricelist(timeout=timeout) 32 return [TLDPrice.model_validate(p) for p in res]
List all domains
59 def raw_register(self, payload: DomainPayload, timeout=None) -> dict: 60 """ 61 This will register a domain on CloudfloorDNS. 62 The registration can be cancelled during a short period (to be confirmed) 63 """ 64 url = "/domain" 65 return self._client.post( 66 url, 67 data=payload.model_dump(by_alias=True), 68 timeout=timeout, 69 )
This will register a domain on CloudfloorDNS. The registration can be cancelled during a short period (to be confirmed)
78 def registry_info(self, domain, timeout=None) -> Domain: 79 """ 80 Return the data currently stored in the registry. 81 NOTE: 82 - The result may differ from `get` method (e.g. if the data push failed) 83 - This is not similar as a WHOIS command since it retrieves redacted data as well 84 """ 85 res = self.raw_registry_info(domain, timeout=timeout) 86 return Domain.model_validate(res)
Return the data currently stored in the registry. NOTE:
- The result may differ from
get
method (e.g. if the data push failed) - This is not similar as a WHOIS command since it retrieves redacted data as well
def
raw_update( self, domain: str, payload: Union[cloudfloordns.models.domain.Domain, cloudfloordns.models.domain.DomainPayload], timeout=None):
95 def raw_update( 96 self, domain: str, payload: Union[Domain, DomainPayload], timeout=None 97 ): 98 if isinstance(payload, Domain): 99 payload = payload.register_payload() 100 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 101 url = f"/domain/{domain}" 102 data = payload.dump_for_update() 103 return self._client.patch( 104 url, 105 data=data, 106 timeout=timeout, 107 )
123 def list(self, limit=None, offset=None, timeout=None) -> list[Domain]: 124 """ 125 List all domains 126 """ 127 res = self._raw_list(limit=limit, offset=offset, timeout=timeout) 128 return [Domain.model_validate(d) for d in res]
List all domains
def
update_contact( self, domain: str, owner: Optional[cloudfloordns.models.domain.Contact] = None, admin: Optional[cloudfloordns.models.domain.Contact] = None, tech: Optional[cloudfloordns.models.domain.Contact] = None, bill: Optional[cloudfloordns.models.domain.Contact] = None, timeout=None):
131 def update_contact( 132 self, 133 domain: str, 134 owner: Optional[Contact] = None, 135 admin: Optional[Contact] = None, 136 tech: Optional[Contact] = None, 137 bill: Optional[Contact] = None, 138 timeout=None, 139 ): 140 """ 141 This method works according to the documentation, but some required parameters might be missing. 142 """ 143 converted = ( 144 d 145 for d in ( 146 owner and owner.as_owner(), 147 admin and admin.as_admin(), 148 tech and tech.as_tech(), 149 bill and bill.as_bill(), 150 ) 151 if d 152 ) 153 payload = dict(ChainMap(*converted)) 154 # print(f"Trying to update domain {domain} with payload:\n{json.dumps(payload, indent=4)}") 155 url = f"/domain/{domain}" 156 return self._client.patch( 157 url, 158 data=payload, 159 timeout=timeout, 160 )
This method works according to the documentation, but some required parameters might be missing.