octodns-cloudns 0.0.7__py3-none-any.whl → 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ from octodns.record import Record
8
8
  logging.basicConfig(level=logging.DEBUG)
9
9
  logger = logging.getLogger(__name__)
10
10
 
11
- __version__ = __VERSION__ = '0.0.7'
11
+ __version__ = __VERSION__ = '0.0.11'
12
12
 
13
13
  class ClouDNSClientException(ProviderException):
14
14
  pass
@@ -44,7 +44,8 @@ class ClouDNSClientGeoDNSNotSupported(ClouDNSClientException):
44
44
 
45
45
 
46
46
  class ClouDNSClient(object):
47
- def __init__(self, auth_id, auth_password, sub_auth=False):
47
+ def __init__(self, auth_id, auth_password, id, sub_auth=False):
48
+ self.log = getLogger(f"ClouDNSProvider[{id}]")
48
49
  session = Session()
49
50
  session.headers.update(
50
51
  {
@@ -75,9 +76,9 @@ class ClouDNSClient(object):
75
76
 
76
77
  def _raw_request(self, function, params=''):
77
78
  url = self._urlbase.format(function, params)
78
- logger.debug(f"Request URL: {url}")
79
+ self.log.debug(f"Request URL: {url}")
79
80
  response = self._session.get(url)
80
- logger.debug(f"Request Response: {response.text}")
81
+ self.log.debug(f"Request Response: {response.text}")
81
82
  return response
82
83
 
83
84
  def _handle_response(self, response):
@@ -117,7 +118,7 @@ class ClouDNSClient(object):
117
118
 
118
119
  single_types = ['CNAME', 'A', 'AAAA', 'DNAME', 'ALIAS', 'NS', 'PTR', 'SPF', 'TXT']
119
120
  if rrset_type in single_types:
120
- params += '&record={}'.format(rrset_values[0].replace('\;', ';').replace('+', '%2B'))
121
+ params += '&record={}'.format(rrset_values[0].replace(r'\;', ';').replace('+', '%2B'))
121
122
 
122
123
  if(geodns is True):
123
124
  for location in rrset_locations:
@@ -241,11 +242,11 @@ class ClouDNSProvider(BaseProvider):
241
242
  ]
242
243
  )
243
244
 
244
- def __init__(self, id, auth_id, auth_password, *args, **kwargs):
245
+ def __init__(self, id, auth_id, auth_password, sub_auth=False, *args, **kwargs):
245
246
  self.log = getLogger(f"ClouDNSProvider[{id}]")
246
- self.log.debug("__init__: id=%s, auth_id=***", id)
247
+ self.log.debug("__init__: id=%s, auth_id=***, auth_password=***, sub_auth=%s", id, sub_auth)
247
248
  super().__init__(id, *args, **kwargs)
248
- self._client = ClouDNSClient(auth_id, auth_password)
249
+ self._client = ClouDNSClient(auth_id, auth_password, id, sub_auth)
249
250
 
250
251
  self._zone_records = {}
251
252
 
@@ -371,27 +372,10 @@ class ClouDNSProvider(BaseProvider):
371
372
 
372
373
  values = defaultdict(lambda: defaultdict(list))
373
374
  records_data = self.zone_records(zone)
374
-
375
+
375
376
  if 'status' in records_data and records_data['status'] == 'Failed':
376
- self.log.info("populate: no existing zone, trying to create it")
377
- response = self._client.zone_create(zone.name[:-1], 'master')
378
- if 'id' in response and response['id'] == 'not_found':
379
- e = ClouDNSClientUnknownDomainName(
380
- 'Missing domain name'
381
- )
382
- e.__cause__ = None
383
- raise e
384
-
385
- if (self.isGeoDNS(response['statusDescription'])):
386
- response = self._client.zone_create(zone.name[:-1], 'geodns')
387
-
388
- if(response['status'] == 'Failed'):
389
- e = ClouDNSClientUnknownDomainName(f"{response['status']} : {response['statusDescription']}")
390
- e.__cause__ = None
391
- raise e
392
- self.log.info("populate: zone has been successfully created")
393
- records_data = self._client.zone_records(zone.name[:-1])
394
-
377
+ return []
378
+
395
379
  for record_id, record in records_data.items():
396
380
  _type = record["type"]
397
381
 
@@ -412,7 +396,7 @@ class ClouDNSProvider(BaseProvider):
412
396
  )
413
397
  zone.add_record(record, lenient=lenient)
414
398
  exists = zone.name in self._zone_records
415
- print(
399
+ self.log.debug(
416
400
  "populate: found %s records, exists=%s",
417
401
  len(zone.records) - before,
418
402
  exists,
@@ -644,6 +628,13 @@ class ClouDNSProvider(BaseProvider):
644
628
  and value.precision_vert == record['v_precision']
645
629
  ):
646
630
  record_ids.append(record_id)
631
+ elif existing._type == 'CNAME' and record['type'] == 'CNAME':
632
+ if (
633
+ existing.name == record['host']
634
+ and existing._type == record['type']
635
+ and existing.value == record['record']+'.'
636
+ ):
637
+ record_ids.append(record_id)
647
638
  else:
648
639
  if (record == 'Failed' or record == 'Missing domain-name'):
649
640
  continue
@@ -679,27 +670,24 @@ class ClouDNSProvider(BaseProvider):
679
670
  desired = plan.desired
680
671
 
681
672
  changes = plan.changes
682
- zone = desired.name[:-1]
673
+ zone_name = desired.name[:-1]
683
674
  self.log.debug("_apply: zone=%s, len(changes)=%d", desired.name, len(changes))
684
675
 
685
- try:
686
- self._client.zone(zone)
687
- except ClouDNSClientNotFound:
688
- self.log.info("_apply: no existing zone, trying to create it")
689
- try:
690
- self._client.zone_create(zone, 'master')
691
- self.log.info("_apply: zone has been successfully created")
692
- except ClouDNSClientNotFound:
693
- e = ClouDNSClientUnknownDomainName(
694
- "Domain " + zone + " is not "
695
- "registered at ClouDNS. "
696
- "Please register or "
697
- "transfer it here "
698
- "to be able to manage its "
699
- "DNS zone."
700
- )
701
- e.__cause__ = None
702
- raise e
676
+ # Does the zone actually exist?
677
+ zone = self._client.zone(zone_name)
678
+ if zone['status'] == 'Failed':
679
+ # All errors other than nonexistent zone.
680
+ if not zone['statusDescription'] == 'Missing domain-name':
681
+ raise ClouDNSClientException(zone)
682
+
683
+ # Check if subscription only allows GeoDNS zones.
684
+ geodns_only = self.isGeoDNS(zone['statusDescription'])
685
+
686
+ # Trying to create the zone.
687
+ zone = self._client.zone_create(zone_name, 'geodns' if geodns_only else 'master')
688
+ if zone['status'] == 'Failed':
689
+ raise ClouDNSClientException(zone)
690
+ self.log.info("_apply: zone has been successfully created")
703
691
 
704
692
  for change in changes:
705
693
  class_name = change.__class__.__name__
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: octodns-cloudns
3
- Version: 0.0.7
3
+ Version: 0.0.11
4
4
  Summary: ClouDNS API provider for octoDNS
5
5
  Home-page: https://github.com/octodns/octodns-cloudns
6
6
  Author: ClouDNS
@@ -40,28 +40,30 @@ An [octoDNS](https://github.com/octodns/octodns/) provider that targets ClouDNS.
40
40
  pip install octodns-cloudns
41
41
  ```
42
42
 
43
- #### requirements.txt/setup.py
44
-
45
- Pinning specific versions or SHAs is recommended to avoid unplanned upgrades.
43
+ ### Configuration
46
44
 
47
- ##### Versions
45
+ For more safety, we recommend you to use an API sub-user with limited permissions.
46
+ You can create it from [your ClouDNS account](https://www.cloudns.net/api-settings/)
47
+ and store your credentials in environment variables:
48
48
 
49
- ```
50
- # Start with the latest versions and don't just copy what's here
51
- octodns==0.9.14
52
- octodns-cloudns==0.0.1
49
+ ```bash
50
+ export CLOUDNS_API_AUTH_ID=XXXXX
51
+ export CLOUDNS_API_AUTH_PASSWORD=XXXXX
53
52
  ```
54
53
 
55
- ### Configuration
54
+ Then add your ClouDNS account to your octoDNS configuration file:
56
55
 
57
56
  ```yaml
58
57
  providers:
59
58
  cloudns_account:
60
- class: octodns.provider.cloudns.ClouDNSProvider
61
- auth_id: <api_auth_id>
62
- auth_password: <api_auth_password>
59
+ class: octodns_cloudns.ClouDNSProvider
60
+ auth_id: env/CLOUDNS_API_AUTH_ID
61
+ auth_password: env/CLOUDNS_API_AUTH_PASSWORD
62
+ # "sub_auth" must be enabled if *only* you log in using a sub-user.
63
+ sub_auth: true
63
64
  ```
64
65
 
66
+
65
67
  ### Support Information
66
68
 
67
69
  #### GeoDNS records
@@ -0,0 +1,6 @@
1
+ octodns_cloudns/__init__.py,sha256=V9YpwsD5Zr_Ar_ScNPyP7g0HUPIYDkA_NO-H6crQd08,27446
2
+ octodns_cloudns-0.0.11.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
+ octodns_cloudns-0.0.11.dist-info/METADATA,sha256=s716VVNH2DbEJ7h5b7LaXJWiqBmYnb18w5JJU_S-48w,2625
4
+ octodns_cloudns-0.0.11.dist-info/WHEEL,sha256=WnJ8fYhv8N4SYVK2lLYNI6N0kVATA7b0piVUNvqIIJE,91
5
+ octodns_cloudns-0.0.11.dist-info/top_level.txt,sha256=t-gGz4zcl1yUE6hyw-aaR6KggpKY25v5xwsSJw-zBdY,16
6
+ octodns_cloudns-0.0.11.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.3.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- octodns_cloudns/__init__.py,sha256=9sjFwxl8YsQvY72Fzu3scPqJzbA4wITiUfMYjtyZ9IM,27844
2
- octodns_cloudns-0.0.7.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
- octodns_cloudns-0.0.7.dist-info/METADATA,sha256=36DM7VzJyeSqvlSatYuLqtod8401_noGLUcJSbcJ_rQ,2387
4
- octodns_cloudns-0.0.7.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
5
- octodns_cloudns-0.0.7.dist-info/top_level.txt,sha256=t-gGz4zcl1yUE6hyw-aaR6KggpKY25v5xwsSJw-zBdY,16
6
- octodns_cloudns-0.0.7.dist-info/RECORD,,