mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-30 07:18:09 +02:00
Optimized injection layer on lua base, as replace for nginx replace. Also optimized cloudflare cache deletion(no everytime for cleanup). Still CDN is required for logout mechanism via JS and Nextcloud deploy is buggy after changing from nginx to openresty. Propably some variable overwritte topic. Should be solved tomorrow.
This commit is contained in:
30
filter_plugins/to_primary_domain.py
Normal file
30
filter_plugins/to_primary_domain.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from ansible.errors import AnsibleFilterError
|
||||
|
||||
try:
|
||||
import tld
|
||||
from tld.exceptions import TldDomainNotFound, TldBadUrl
|
||||
except ImportError:
|
||||
raise AnsibleFilterError("The 'tld' Python package is required for the to_primary_domain filter. Install with 'pip install tld'.")
|
||||
|
||||
class FilterModule(object):
|
||||
''' Custom filter to extract the primary/zone domain from a full domain name '''
|
||||
|
||||
def filters(self):
|
||||
return {
|
||||
'to_primary_domain': self.to_primary_domain,
|
||||
}
|
||||
|
||||
def to_primary_domain(self, domain):
|
||||
"""
|
||||
Converts a full domain or subdomain into its primary/zone domain.
|
||||
E.g. 'foo.bar.example.co.uk' -> 'example.co.uk'
|
||||
"""
|
||||
if not isinstance(domain, str):
|
||||
raise AnsibleFilterError("Input to to_primary_domain must be a string")
|
||||
try:
|
||||
res = tld.get_fld(domain, fix_protocol=True)
|
||||
if not res:
|
||||
raise AnsibleFilterError(f"Could not extract primary domain from: {domain}")
|
||||
return res
|
||||
except (TldDomainNotFound, TldBadUrl) as exc:
|
||||
raise AnsibleFilterError(str(exc))
|
Reference in New Issue
Block a user