Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
chore: add extract fulldomain serializer

See merge request locker/api-core!463
  • Loading branch information
phuongntt-cystack committed Jun 21, 2024
2 parents 72765b1 + 498f328 commit d726758
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions locker_server/api/v1_0/exclude_domains/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from rest_framework import serializers

from locker_server.shared.utils.network import is_valid_ip, extract_root_domain, is_valid_domain
from locker_server.shared.utils.network import is_valid_ip, extract_root_domain, is_valid_domain, extract_full_domain


class ExcludeDomainSerializer(serializers.Serializer):
Expand All @@ -23,8 +23,8 @@ def validate(self, data):
raise serializers.ValidationError(detail={'domain': [
'This domain or ip is invalid', 'Domain hoặc ip không hợp lệ'
]})
# if is_domain:
# data["domain"] = extract_root_domain(domain=domain)
if is_domain:
data["domain"] = extract_full_domain(domain=domain)
return data

def to_representation(self, instance):
Expand Down
8 changes: 8 additions & 0 deletions locker_server/shared/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ def extract_root_domain(domain: str) -> str:
return "{}.{}".format(extracted.domain, extracted.suffix)


def extract_full_domain(domain: str) -> str:
extracted = tldextract.extract(domain)
full_domain = "{}.{}".format(extracted.domain, extracted.suffix)
if extracted.subdomain is not None:
full_domain = "{}.{}".format(extracted.subdomain, full_domain)
return full_domain


def detect_device(ua_string: str):
"""
Detect device information from request
Expand Down

0 comments on commit d726758

Please sign in to comment.