mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 18:29:21 +00:00 
			
		
		
		
	Optimized redirect
This commit is contained in:
		| @@ -8,9 +8,8 @@ class FilterModule(object): | ||||
|         """ | ||||
|         Build a flat list of redirect mappings for all apps: | ||||
|           - source: each alias domain | ||||
|           - target: the first canonical domain (app.domains.canonical[0] or default) | ||||
|  | ||||
|         Logic for computing aliases and canonicals is identical to alias_domains_map + canonical_domains_map. | ||||
|           - target: the first canonical domain | ||||
|         Skip mappings where source == target, since they make no sense. | ||||
|         """ | ||||
|         def parse_entry(domains_cfg, key, app_id): | ||||
|             if key not in domains_cfg: | ||||
| @@ -55,12 +54,9 @@ class FilterModule(object): | ||||
|         for app_id, cfg in apps.items(): | ||||
|             domains_cfg = cfg.get('domains') | ||||
|             if domains_cfg is None: | ||||
|                 # no domains key → no aliases | ||||
|                 alias_map[app_id] = [] | ||||
|                 continue | ||||
|  | ||||
|             if isinstance(domains_cfg, dict) and not domains_cfg: | ||||
|                 # empty domains dict → only default | ||||
|                 alias_map[app_id] = [default_domain(app_id, primary_domain)] | ||||
|                 continue | ||||
|  | ||||
| @@ -79,13 +75,16 @@ class FilterModule(object): | ||||
|  | ||||
|             alias_map[app_id] = aliases | ||||
|  | ||||
|         # 3) Build flat list of {source, target} entries | ||||
|         # 3) Build flat list of {source, target} entries, | ||||
|         #    skipping self-mappings | ||||
|         mappings = [] | ||||
|         for app_id, sources in alias_map.items(): | ||||
|             # pick first canonical domain as target | ||||
|             canon_list = canonical_map.get(app_id, []) | ||||
|             target = canon_list[0] if canon_list else default_domain(app_id, primary_domain) | ||||
|             for src in sources: | ||||
|                 if src == target: | ||||
|                     # skip self-redirects | ||||
|                     continue | ||||
|                 mappings.append({ | ||||
|                     'source': src, | ||||
|                     'target': target | ||||
|   | ||||
| @@ -1,2 +1,2 @@ | ||||
| base_domain:      "{{ domain | regex_replace('^(?:.*\\.)?(.+\\..+)$', '\\1') }}" | ||||
| verification_url: "{{ web_protocol }}://{{domains.matomo}}/index.php?module=API&method=SitesManager.getSitesIdFromSiteUrl&url=https://{{base_domain}}&format=json&token_auth={{applications.matomo.credentials.auth_token}}" | ||||
| verification_url: "{{ web_protocol }}://{{domains | get_domain('mastodon')}}/index.php?module=API&method=SitesManager.getSitesIdFromSiteUrl&url=https://{{base_domain}}&format=json&token_auth={{applications.matomo.credentials.auth_token}}" | ||||
| @@ -30,9 +30,7 @@ class TestDomainMappings(unittest.TestCase): | ||||
|     def test_empty_domains_cfg(self): | ||||
|         apps = {'app1': {'domains': {}}} | ||||
|         default = 'app1.example.com' | ||||
|         expected = [ | ||||
|             {'source': default, 'target': default} | ||||
|         ] | ||||
|         expected = [] | ||||
|         result = self.filter.domain_mappings(apps, self.primary) | ||||
|         self.assertEqual(result, expected) | ||||
|  | ||||
| @@ -45,7 +43,6 @@ class TestDomainMappings(unittest.TestCase): | ||||
|         default = 'app1.example.com' | ||||
|         expected = [ | ||||
|             {'source': 'alias.com',    'target': default}, | ||||
|             {'source': default,        'target': default}, | ||||
|         ] | ||||
|         result = self.filter.domain_mappings(apps, self.primary) | ||||
|         # order not important | ||||
| @@ -84,10 +81,7 @@ class TestDomainMappings(unittest.TestCase): | ||||
|             'app2': {'domains': {'canonical': ['c2.com']}}, | ||||
|         } | ||||
|         expected = [ | ||||
|             # app1 | ||||
|             {'source': 'a1.com',              'target': 'app1.example.com'}, | ||||
|             {'source': 'app1.example.com',    'target': 'app1.example.com'}, | ||||
|             # app2 | ||||
|             {'source': 'app2.example.com',    'target': 'c2.com'}, | ||||
|         ] | ||||
|         result = self.filter.domain_mappings(apps, self.primary) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user