Browse Source

feat(api): add a setting to specify which suffixes we manage

Peter Thomassen 6 năm trước cách đây
mục cha
commit
4ef79f8543
4 tập tin đã thay đổi với 13 bổ sung11 xóa
  1. 3 0
      api/api/settings.py
  2. 8 8
      api/desecapi/models.py
  3. 1 1
      api/desecapi/tests/base.py
  4. 1 2
      api/desecapi/views.py

+ 3 - 0
api/api/settings.py

@@ -140,6 +140,9 @@ AUTH_USER_MODEL = 'desecapi.User'
 # default NS records
 DEFAULT_NS = ['ns1.desec.io.', 'ns2.desec.io.']
 
+# Public Suffix settings
+LOCAL_PUBLIC_SUFFIXES = {'dedyn.io'}
+
 # PowerDNS API access
 NSLORD_PDNS_API = 'http://nslord:8081/api/v1/servers/localhost'
 NSLORD_PDNS_API_TOKEN = os.environ['DESECSTACK_NSLORD_APIKEY']

+ 8 - 8
api/desecapi/models.py

@@ -218,11 +218,11 @@ class Domain(models.Model, mixins.SetterMixin):
         # Make our RRsets consistent with pdns (specifically, NS may exist)
         self.sync_from_pdns()
 
-        # For dedyn.io domains, propagate NS and DS delegation RRsets
-        subname, parent_pdns_id = self.pdns_id.split('.', 1)
-        if parent_pdns_id == 'dedyn.io.':
+        # For domains under our registry, propagate NS and DS delegation RRsets
+        subname, parent_domain = self.name.split('.', 1)
+        if parent_domain in settings.LOCAL_PUBLIC_SUFFIXES:
             try:
-                parent = Domain.objects.get(name='dedyn.io')
+                parent = Domain.objects.get(name=parent_domain)
             except Domain.DoesNotExist:
                 pass
             else:
@@ -368,11 +368,11 @@ class Domain(models.Model, mixins.SetterMixin):
 
     @transaction.atomic
     def delete(self, *args, **kwargs):
-        # Delete delegation for dynDNS domains (direct child of dedyn.io)
-        subname, parent_pdns_id = self.pdns_id.split('.', 1)
-        if parent_pdns_id == 'dedyn.io.':
+        # Delete delegation if domain is under our registry
+        subname, parent_domain = self.name.split('.', 1)
+        if parent_domain in settings.LOCAL_PUBLIC_SUFFIXES:
             try:
-                parent = Domain.objects.get(name='dedyn.io')
+                parent = Domain.objects.get(name=parent_domain)
             except Domain.DoesNotExist:
                 pass
             else:

+ 1 - 1
api/desecapi/tests/base.py

@@ -525,7 +525,7 @@ class DesecTestCase(MockPDNSTestCase):
     """
     client_class = DesecAPIClient
 
-    AUTO_DELEGATION_DOMAINS = ['dedyn.io']  # TODO replace with project wide settings
+    AUTO_DELEGATION_DOMAINS = list(settings.LOCAL_PUBLIC_SUFFIXES)
     PUBLIC_SUFFIXES = ['de', 'com', 'io', 'gov.cd', 'edu.ec', 'xxx', 'pinb.gov.pl', 'valer.ostfold.no', 'kota.aichi.jp']
 
     @classmethod

+ 1 - 2
api/desecapi/views.py

@@ -114,8 +114,7 @@ class DomainList(generics.ListCreateAPIView):
         domain_list = {'.'.join(domain_parts[i:]) for i in range(1, len(domain_parts))}
 
         # Remove public suffixes and then use this list to control registration
-        public_suffixes = {'dedyn.io'}
-        domain_list = domain_list - public_suffixes
+        domain_list -= settings.LOCAL_PUBLIC_SUFFIXES
 
         queryset = Domain.objects.filter(Q(name=domain_name) | (Q(name__in=domain_list) & ~Q(owner=self.request.user)))
         if queryset.exists():