summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaw Loeung <[email protected]>2024-03-16 06:14:55 +0000
committerCanonical IS Mergebot <[email protected]>2024-03-16 06:14:55 +0000
commitbad538f03a268d584d4e23b880ac5ab762cc1845 (patch)
treee6d013ebc30fe96da54645628c2fed460aff0c65
parent45cde590308c42c9448663fd3a64943ebdbf8ad3 (diff)
parenta0a454edcae98a6fd5a0bd692e42b2c0e4c3a915 (diff)
Add option to specify additional site names
Reviewed-on: https://code.launchpad.net/~hloeung/content-cache-charm/+git/content-cache-charm/+merge/462541 Reviewed-by: James Simpson <[email protected]>
-rw-r--r--lib/haproxy.py21
-rw-r--r--tests/unit/files/config_test_config.txt6
-rw-r--r--tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt3
-rw-r--r--tests/unit/files/haproxy_config_rendered_test_output.txt3
-rw-r--r--tests/unit/files/haproxy_config_rendered_test_output2.txt3
-rw-r--r--tests/unit/files/haproxy_config_rendered_test_output_with_extra_configs.txt3
6 files changed, 30 insertions, 9 deletions
diff --git a/lib/haproxy.py b/lib/haproxy.py
index 1f35061..845854d 100644
--- a/lib/haproxy.py
+++ b/lib/haproxy.py
@@ -148,6 +148,7 @@ listen {name}
redirect_http_to_https = False
for site, site_conf in config[address_port].items():
site_name = site_conf.get('site-name', site)
+ additional_site_names = site_conf.get('additional-site-names', [])
default_site = site_conf.get('default', False)
redirect_http_to_https = site_conf.get('enable-redirect-http-to-https', False)
@@ -174,15 +175,19 @@ listen {name}
default_backend = "{indent}redirect prefix https://{site_name}\n".format(
site_name=site_name, indent=INDENT
)
- else:
- backend_name = self._generate_stanza_name(
- site_conf.get('locations', {}).get('backend-name') or site
+ continue
+
+ backend_name = self._generate_stanza_name(site_conf.get('locations', {}).get('backend-name') or site)
+ backend_config.append(backend_conf.format(backend=backend_name, site_name=site_name, indent=INDENT))
+ for additional_site in additional_site_names:
+ backend_config.append(
+ backend_conf.format(backend=backend_name, site_name=additional_site, indent=INDENT)
+ )
+
+ if default_site:
+ default_backend = "{indent}default_backend backend-{backend}\n".format(
+ backend=backend_name, indent=INDENT
)
- backend_config.append(backend_conf.format(backend=backend_name, site_name=site_name, indent=INDENT))
- if default_site:
- default_backend = "{indent}default_backend backend-{backend}\n".format(
- backend=backend_name, indent=INDENT
- )
tls_config = ''
if tls_cert_bundle_paths:
diff --git a/tests/unit/files/config_test_config.txt b/tests/unit/files/config_test_config.txt
index 6c591e0..eab890b 100644
--- a/tests/unit/files/config_test_config.txt
+++ b/tests/unit/files/config_test_config.txt
@@ -50,7 +50,7 @@ site3.local:
- forceclose
cache-maxconn: 4096
-# Test 4: No backends, a few local content
+# Test 4: No backends, a few local content, additional site names
site4.local:
locations:
/:
@@ -60,6 +60,10 @@ site4.local:
extra-configs:
- autoindex on
- auth_request /auth
+ additional-site-names:
+ - mysite.site4.local
+ - site4-alt.local
+ - -m end .site4.local
# Test 5: Multiple backends
site5:
diff --git a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt
index 8d3c694..bae2894 100644
--- a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt
+++ b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt
@@ -8,6 +8,9 @@ listen combined-80
use_backend backend-site1-local if { hdr(Host) -i site1.local }
use_backend backend-site3-local if { hdr(Host) -i site3.local }
use_backend backend-site4-local if { hdr(Host) -i site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i mysite.site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i site4-alt.local }
+ use_backend backend-site4-local if { hdr(Host) -i -m end .site4.local }
use_backend backend-site5 if { hdr(Host) -i site5.local }
use_backend backend-site6-local if { hdr(Host) -i site6.local }
use_backend backend-site9-local if { hdr(Host) -i site9.local }
diff --git a/tests/unit/files/haproxy_config_rendered_test_output.txt b/tests/unit/files/haproxy_config_rendered_test_output.txt
index d671065..4121b07 100644
--- a/tests/unit/files/haproxy_config_rendered_test_output.txt
+++ b/tests/unit/files/haproxy_config_rendered_test_output.txt
@@ -89,6 +89,9 @@ listen combined-80
use_backend backend-site1-local if { hdr(Host) -i site1.local }
use_backend backend-site3-local if { hdr(Host) -i site3.local }
use_backend backend-site4-local if { hdr(Host) -i site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i mysite.site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i site4-alt.local }
+ use_backend backend-site4-local if { hdr(Host) -i -m end .site4.local }
use_backend backend-site5 if { hdr(Host) -i site5.local }
use_backend backend-site6-local if { hdr(Host) -i site6.local }
use_backend backend-site9-local if { hdr(Host) -i site9.local }
diff --git a/tests/unit/files/haproxy_config_rendered_test_output2.txt b/tests/unit/files/haproxy_config_rendered_test_output2.txt
index b4dadf6..22c56ab 100644
--- a/tests/unit/files/haproxy_config_rendered_test_output2.txt
+++ b/tests/unit/files/haproxy_config_rendered_test_output2.txt
@@ -89,6 +89,9 @@ listen combined-80
use_backend backend-site1-local if { hdr(Host) -i site1.local }
use_backend backend-site3-local if { hdr(Host) -i site3.local }
use_backend backend-site4-local if { hdr(Host) -i site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i mysite.site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i site4-alt.local }
+ use_backend backend-site4-local if { hdr(Host) -i -m end .site4.local }
use_backend backend-site5 if { hdr(Host) -i site5.local }
use_backend backend-site6-local if { hdr(Host) -i site6.local }
use_backend backend-site9-local if { hdr(Host) -i site9.local }
diff --git a/tests/unit/files/haproxy_config_rendered_test_output_with_extra_configs.txt b/tests/unit/files/haproxy_config_rendered_test_output_with_extra_configs.txt
index 824234f..7166d28 100644
--- a/tests/unit/files/haproxy_config_rendered_test_output_with_extra_configs.txt
+++ b/tests/unit/files/haproxy_config_rendered_test_output_with_extra_configs.txt
@@ -89,6 +89,9 @@ listen combined-80
use_backend backend-site1-local if { hdr(Host) -i site1.local }
use_backend backend-site3-local if { hdr(Host) -i site3.local }
use_backend backend-site4-local if { hdr(Host) -i site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i mysite.site4.local }
+ use_backend backend-site4-local if { hdr(Host) -i site4-alt.local }
+ use_backend backend-site4-local if { hdr(Host) -i -m end .site4.local }
use_backend backend-site5 if { hdr(Host) -i site5.local }
use_backend backend-site6-local if { hdr(Host) -i site6.local }
use_backend backend-site9-local if { hdr(Host) -i site9.local }