mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Restructured server config
This commit is contained in:
@@ -33,7 +33,9 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_alias_with_explicit_aliases(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {'aliases': ['alias.com']}
|
||||
'server':{
|
||||
'domains': {'aliases': ['alias.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
# canonical defaults to ['app1.example.com'], so alias should include alias.com and default
|
||||
@@ -44,7 +46,7 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_alias_with_canonical_not_default(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {'canonical': ['foo.com']}
|
||||
'server':{'domains': {'canonical': ['foo.com']}}
|
||||
}
|
||||
}
|
||||
# foo.com is canonical, default not in canonical so added as alias
|
||||
@@ -55,9 +57,11 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_alias_with_existing_default(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {
|
||||
'canonical': ['foo.com'],
|
||||
'aliases': ['app1.example.com']
|
||||
'server':{
|
||||
'domains': {
|
||||
'canonical': ['foo.com'],
|
||||
'aliases': ['app1.example.com']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +72,7 @@ class TestDomainFilters(unittest.TestCase):
|
||||
|
||||
def test_invalid_aliases_type(self):
|
||||
apps = {
|
||||
'app1': {'domains': {'aliases': 123}}
|
||||
'app1': {'server':{'domains': {'aliases': 123}}}
|
||||
}
|
||||
with self.assertRaises(AnsibleFilterError):
|
||||
self.filter_module.alias_domains_map(apps, self.primary)
|
||||
@@ -76,7 +80,9 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_alias_with_empty_domains_cfg(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {}
|
||||
'server':{
|
||||
'domains': {}
|
||||
}
|
||||
}
|
||||
}
|
||||
expected = apps
|
||||
@@ -86,10 +92,12 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_alias_with_canonical_dict_not_default(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {
|
||||
'canonical': {
|
||||
'one': 'one.com',
|
||||
'two': 'two.com'
|
||||
'server':{
|
||||
'domains': {
|
||||
'canonical': {
|
||||
'one': 'one.com',
|
||||
'two': 'two.com'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,9 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_canonical_with_list(self):
|
||||
apps = {
|
||||
'web-app-app1': {
|
||||
'domains': {'canonical': ['foo.com', 'bar.com']}
|
||||
'server':{
|
||||
'domains': {'canonical': ['foo.com', 'bar.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = self.filter_module.canonical_domains_map(apps, self.primary)
|
||||
@@ -44,7 +46,9 @@ class TestDomainFilters(unittest.TestCase):
|
||||
def test_canonical_with_dict(self):
|
||||
apps = {
|
||||
'web-app-app1': {
|
||||
'domains': {'canonical': {'one': 'one.com', 'two': 'two.com'}}
|
||||
'server':{
|
||||
'domains': {'canonical': {'one': 'one.com', 'two': 'two.com'}}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = self.filter_module.canonical_domains_map(apps, self.primary)
|
||||
@@ -55,8 +59,14 @@ class TestDomainFilters(unittest.TestCase):
|
||||
|
||||
def test_canonical_duplicate_raises(self):
|
||||
apps = {
|
||||
'web-app-app1': {'domains': {'canonical': ['dup.com']}},
|
||||
'web-app-app2': {'domains': {'canonical': ['dup.com']}},
|
||||
'web-app-app1':{
|
||||
'server':{'domains': {'canonical': ['dup.com']}},
|
||||
},
|
||||
'web-app-app2':{
|
||||
'server':{
|
||||
'domains': {'canonical': ['dup.com']}
|
||||
},
|
||||
},
|
||||
}
|
||||
with self.assertRaises(AnsibleFilterError) as cm:
|
||||
self.filter_module.canonical_domains_map(apps, self.primary)
|
||||
@@ -65,7 +75,7 @@ class TestDomainFilters(unittest.TestCase):
|
||||
|
||||
def test_invalid_canonical_type(self):
|
||||
apps = {
|
||||
'web-app-app1': {'domains': {'canonical': 123}}
|
||||
'web-app-app1': {'server':{'domains': {'canonical': 123}}}
|
||||
}
|
||||
with self.assertRaises(AnsibleFilterError):
|
||||
self.filter_module.canonical_domains_map(apps, self.primary)
|
||||
@@ -76,7 +86,7 @@ class TestDomainFilters(unittest.TestCase):
|
||||
resulting in an empty mapping when only non-web apps are provided.
|
||||
"""
|
||||
apps = {
|
||||
'db-app-app1': {'domains': {'canonical': ['db.example.com']}},
|
||||
'db-app-app1': {'server':{'domains': {'canonical': ['db.example.com']}}},
|
||||
'service-app-app2': {}
|
||||
}
|
||||
result = self.filter_module.canonical_domains_map(apps, self.primary)
|
||||
@@ -88,7 +98,7 @@ class TestDomainFilters(unittest.TestCase):
|
||||
non-web apps should be ignored alongside valid web apps.
|
||||
"""
|
||||
apps = {
|
||||
'db-app-app1': {'domains': {'canonical': ['db.example.com']}},
|
||||
'db-app-app1': {'server':{'domains': {'canonical': ['db.example.com']}}},
|
||||
'web-app-app1': {}
|
||||
}
|
||||
expected = {'web-app-app1': ['app1.example.com']}
|
||||
|
@@ -37,7 +37,9 @@ class TestDomainMappings(unittest.TestCase):
|
||||
def test_explicit_aliases(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {'aliases': ['alias.com']}
|
||||
'server':{
|
||||
'domains': {'aliases': ['alias.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
default = 'app1.example.com'
|
||||
@@ -51,7 +53,9 @@ class TestDomainMappings(unittest.TestCase):
|
||||
def test_canonical_not_default(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {'canonical': ['foo.com']}
|
||||
'server':{
|
||||
'domains': {'canonical': ['foo.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
expected = [
|
||||
@@ -63,8 +67,10 @@ class TestDomainMappings(unittest.TestCase):
|
||||
def test_canonical_dict(self):
|
||||
apps = {
|
||||
'app1': {
|
||||
'domains': {
|
||||
'canonical': {'one': 'one.com', 'two': 'two.com'}
|
||||
'server':{
|
||||
'domains': {
|
||||
'canonical': {'one': 'one.com', 'two': 'two.com'}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,8 +83,12 @@ class TestDomainMappings(unittest.TestCase):
|
||||
|
||||
def test_multiple_apps(self):
|
||||
apps = {
|
||||
'app1': {'domains': {'aliases': ['a1.com']}},
|
||||
'app2': {'domains': {'canonical': ['c2.com']}},
|
||||
'app1': {
|
||||
'server':{'domains': {'aliases': ['a1.com']}}
|
||||
},
|
||||
'app2': {
|
||||
'server':{'domains': {'canonical': ['c2.com']}}
|
||||
},
|
||||
}
|
||||
expected = [
|
||||
{'source': 'a1.com', 'target': 'app1.example.com'},
|
||||
@@ -89,7 +99,10 @@ class TestDomainMappings(unittest.TestCase):
|
||||
|
||||
def test_multiple_aliases(self):
|
||||
apps = {
|
||||
'app1': {'domains': {'aliases': ['a1.com','a2.com']}}
|
||||
'app1': {
|
||||
'server':{'domains': {'aliases': ['a1.com','a2.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
expected = [
|
||||
{'source': 'a1.com', 'target': 'app1.example.com'},
|
||||
@@ -100,7 +113,7 @@ class TestDomainMappings(unittest.TestCase):
|
||||
|
||||
def test_invalid_aliases_type(self):
|
||||
apps = {
|
||||
'app1': {'domains': {'aliases': 123}}
|
||||
'app1': {'server':{'domains': {'aliases': 123}}}
|
||||
}
|
||||
with self.assertRaises(AnsibleFilterError):
|
||||
self.filter.domain_mappings(apps, self.primary)
|
||||
|
@@ -19,12 +19,14 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
self.nested_cfg = {
|
||||
'html': {
|
||||
'features': {'matomo': True},
|
||||
'domains': {'canonical': ['html.example.com']}
|
||||
'server': {
|
||||
'domains':{'canonical': ['html.example.com']}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.flat_cfg = {
|
||||
'features': {'matomo': False},
|
||||
'domains': {'canonical': ['flat.example.com']}
|
||||
'server': {'domains':{'canonical': ['flat.example.com']}}
|
||||
}
|
||||
|
||||
def test_invalid_key(self):
|
||||
@@ -69,7 +71,7 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
self.assertIn(self.app, _cfg_cache)
|
||||
mock_yaml.reset_mock()
|
||||
# from cache
|
||||
self.assertEqual(self.f(self.app, 'domains.canonical'),
|
||||
self.assertEqual(self.f(self.app, 'server.domains.canonical'),
|
||||
['html.example.com'])
|
||||
mock_yaml.assert_not_called()
|
||||
|
||||
@@ -92,7 +94,7 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
mock_yaml.return_value = self.nested_cfg
|
||||
# nested fallback must work
|
||||
self.assertTrue(self.f(self.app, 'features.matomo'))
|
||||
self.assertEqual(self.f(self.app, 'domains.canonical'),
|
||||
self.assertEqual(self.f(self.app, 'server.domains.canonical'),
|
||||
['html.example.com'])
|
||||
|
||||
@patch('load_configuration.os.listdir', return_value=['r4'])
|
||||
@@ -105,13 +107,15 @@ class TestLoadConfigurationFilter(unittest.TestCase):
|
||||
mock_exists.side_effect = lambda p: p.endswith('config/main.yml')
|
||||
mock_yaml.return_value = {
|
||||
'file': {
|
||||
'domains': {
|
||||
'canonical': ['files.example.com', 'extra.example.com']
|
||||
'server': {
|
||||
'domains':{
|
||||
'canonical': ['files.example.com', 'extra.example.com']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# should get the first element of the canonical domains list
|
||||
self.assertEqual(self.f('file', 'domains.canonical[0]'),
|
||||
self.assertEqual(self.f('file', 'server.domains.canonical[0]'),
|
||||
'files.example.com')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@@ -33,23 +33,33 @@ class TestLogoutDomainsFilter(unittest.TestCase):
|
||||
def test_flatten_and_feature_flag(self):
|
||||
applications = {
|
||||
"app1": {
|
||||
"domains": {"canonical": "single.domain.com"},
|
||||
'server':{
|
||||
"domains": {"canonical": "single.domain.com"}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
},
|
||||
"app2": {
|
||||
"domains": {"canonical": ["list1.com", "list2.com"]},
|
||||
'server':{
|
||||
"domains": {"canonical": ["list1.com", "list2.com"]}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
},
|
||||
"app3": {
|
||||
"domains": {"canonical": {"k1": "dictA.com", "k2": "dictB.com"}},
|
||||
'server':{
|
||||
"domains": {"canonical": {"k1": "dictA.com", "k2": "dictB.com"}}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
},
|
||||
"app4": {
|
||||
"domains": {"canonical": "no-logout.com"},
|
||||
'server':{
|
||||
"domains": {"canonical": "no-logout.com"}
|
||||
},
|
||||
"features": {"logout": False},
|
||||
},
|
||||
"other": {
|
||||
"domains": {"canonical": "ignored.com"},
|
||||
'server':{
|
||||
"domains": {"canonical": "ignored.com"}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
},
|
||||
}
|
||||
@@ -67,7 +77,9 @@ class TestLogoutDomainsFilter(unittest.TestCase):
|
||||
def test_missing_canonical_defaults_empty(self):
|
||||
applications = {
|
||||
"app1": {
|
||||
"domains": {}, # no 'canonical' key
|
||||
'server':{
|
||||
"domains": {}
|
||||
}, # no 'canonical' key
|
||||
"features": {"logout": True},
|
||||
}
|
||||
}
|
||||
@@ -77,7 +89,9 @@ class TestLogoutDomainsFilter(unittest.TestCase):
|
||||
def test_app_not_in_group(self):
|
||||
applications = {
|
||||
"app1": {
|
||||
"domains": {"canonical": "domain.com"},
|
||||
'server':{
|
||||
"domains": {"canonical": "domain.com"}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
}
|
||||
}
|
||||
@@ -87,7 +101,9 @@ class TestLogoutDomainsFilter(unittest.TestCase):
|
||||
def test_invalid_domain_type(self):
|
||||
applications = {
|
||||
"app1": {
|
||||
"domains": {"canonical": 123},
|
||||
'server':{
|
||||
"domains": {"canonical": 123}
|
||||
},
|
||||
"features": {"logout": True},
|
||||
}
|
||||
}
|
||||
|
@@ -64,11 +64,13 @@ class TestDictRenderer(unittest.TestCase):
|
||||
# Combine quoted key, dot access and numeric index
|
||||
data = {
|
||||
"web-svc-file": {
|
||||
"domains": {
|
||||
"canonical": ["file.example.com"]
|
||||
'server':{
|
||||
"domains": {
|
||||
"canonical": ["file.example.com"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": '<<[\'web-svc-file\'].domains.canonical[0]>>'
|
||||
"url": '<<[\'web-svc-file\'].server.domains.canonical[0]>>'
|
||||
}
|
||||
rendered = self.renderer.render(data)
|
||||
self.assertEqual(rendered["url"], "file.example.com")
|
||||
|
Reference in New Issue
Block a user