mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-15 08:30:46 +02:00
Removed catetory domain präfix from redirect domains
This commit is contained in:
parent
220e3e1c60
commit
9f865dd215
@ -1,4 +1,7 @@
|
|||||||
from ansible.errors import AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
|
import sys, os
|
||||||
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
from module_utils.entity_name_utils import get_entity_name
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
def filters(self):
|
def filters(self):
|
||||||
@ -30,8 +33,9 @@ class FilterModule(object):
|
|||||||
)
|
)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def default_domain(app_id, primary):
|
def default_domain(app_id:str, primary:str):
|
||||||
return f"{app_id}.{primary}"
|
subdomain = get_entity_name(app_id)
|
||||||
|
return f"{subdomain}.{primary}"
|
||||||
|
|
||||||
# 1) Compute canonical domains per app (always as a list)
|
# 1) Compute canonical domains per app (always as a list)
|
||||||
canonical_map = {}
|
canonical_map = {}
|
||||||
|
1
roles/web-opt-rdr-domains/defaults/main.yml
Normal file
1
roles/web-opt-rdr-domains/defaults/main.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
redirect_domain_mappings: [] # Format [{source: target:},...]
|
@ -22,27 +22,27 @@ class TestDomainMappings(unittest.TestCase):
|
|||||||
self.assertEqual(result, [])
|
self.assertEqual(result, [])
|
||||||
|
|
||||||
def test_app_without_domains(self):
|
def test_app_without_domains(self):
|
||||||
apps = {'app1': {}}
|
apps = {'web-app-port-ui': {}}
|
||||||
# no domains key → no mappings
|
# no domains key → no mappings
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertEqual(result, [])
|
self.assertEqual(result, [])
|
||||||
|
|
||||||
def test_empty_domains_cfg(self):
|
def test_empty_domains_cfg(self):
|
||||||
apps = {'app1': {'domains': {}}}
|
apps = {'web-app-port-ui': {'domains': {}}}
|
||||||
default = 'app1.example.com'
|
default = 'port-ui.example.com'
|
||||||
expected = []
|
expected = []
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_explicit_aliases(self):
|
def test_explicit_aliases(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {
|
'web-app-port-ui': {
|
||||||
'server':{
|
'server':{
|
||||||
'domains': {'aliases': ['alias.com']}
|
'domains': {'aliases': ['alias.com']}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default = 'app1.example.com'
|
default = 'port-ui.example.com'
|
||||||
expected = [
|
expected = [
|
||||||
{'source': 'alias.com', 'target': default},
|
{'source': 'alias.com', 'target': default},
|
||||||
]
|
]
|
||||||
@ -52,21 +52,21 @@ class TestDomainMappings(unittest.TestCase):
|
|||||||
|
|
||||||
def test_canonical_not_default(self):
|
def test_canonical_not_default(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {
|
'web-app-port-ui': {
|
||||||
'server':{
|
'server':{
|
||||||
'domains': {'canonical': ['foo.com']}
|
'domains': {'canonical': ['foo.com']}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expected = [
|
expected = [
|
||||||
{'source': 'app1.example.com', 'target': 'foo.com'}
|
{'source': 'port-ui.example.com', 'target': 'foo.com'}
|
||||||
]
|
]
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_canonical_dict(self):
|
def test_canonical_dict(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {
|
'web-app-port-ui': {
|
||||||
'server':{
|
'server':{
|
||||||
'domains': {
|
'domains': {
|
||||||
'canonical': {'one': 'one.com', 'two': 'two.com'}
|
'canonical': {'one': 'one.com', 'two': 'two.com'}
|
||||||
@ -76,44 +76,44 @@ class TestDomainMappings(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
# first canonical key 'one' → one.com
|
# first canonical key 'one' → one.com
|
||||||
expected = [
|
expected = [
|
||||||
{'source': 'app1.example.com', 'target': 'one.com'}
|
{'source': 'port-ui.example.com', 'target': 'one.com'}
|
||||||
]
|
]
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_multiple_apps(self):
|
def test_multiple_apps(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {
|
'web-app-port-ui': {
|
||||||
'server':{'domains': {'aliases': ['a1.com']}}
|
'server':{'domains': {'aliases': ['a1.com']}}
|
||||||
},
|
},
|
||||||
'app2': {
|
'web-app-mastodon': {
|
||||||
'server':{'domains': {'canonical': ['c2.com']}}
|
'server':{'domains': {'canonical': ['c2.com']}}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected = [
|
expected = [
|
||||||
{'source': 'a1.com', 'target': 'app1.example.com'},
|
{'source': 'a1.com', 'target': 'port-ui.example.com'},
|
||||||
{'source': 'app2.example.com', 'target': 'c2.com'},
|
{'source': 'mastodon.example.com', 'target': 'c2.com'},
|
||||||
]
|
]
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertCountEqual(result, expected)
|
self.assertCountEqual(result, expected)
|
||||||
|
|
||||||
def test_multiple_aliases(self):
|
def test_multiple_aliases(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {
|
'web-app-port-ui': {
|
||||||
'server':{'domains': {'aliases': ['a1.com','a2.com']}
|
'server':{'domains': {'aliases': ['a1.com','a2.com']}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expected = [
|
expected = [
|
||||||
{'source': 'a1.com', 'target': 'app1.example.com'},
|
{'source': 'a1.com', 'target': 'port-ui.example.com'},
|
||||||
{'source': 'a2.com', 'target': 'app1.example.com'}
|
{'source': 'a2.com', 'target': 'port-ui.example.com'}
|
||||||
]
|
]
|
||||||
result = self.filter.domain_mappings(apps, self.primary)
|
result = self.filter.domain_mappings(apps, self.primary)
|
||||||
self.assertCountEqual(result, expected)
|
self.assertCountEqual(result, expected)
|
||||||
|
|
||||||
def test_invalid_aliases_type(self):
|
def test_invalid_aliases_type(self):
|
||||||
apps = {
|
apps = {
|
||||||
'app1': {'server':{'domains': {'aliases': 123}}}
|
'web-app-port-ui': {'server':{'domains': {'aliases': 123}}}
|
||||||
}
|
}
|
||||||
with self.assertRaises(AnsibleFilterError):
|
with self.assertRaises(AnsibleFilterError):
|
||||||
self.filter.domain_mappings(apps, self.primary)
|
self.filter.domain_mappings(apps, self.primary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user