Merge ~hloeung/content-cache-charm:master into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 03773df540b72c74b5a64c858dea6b579ca50827
Merged at revision: 4b43be183bfb3670d2ea4ad4acd0ad13b37e274e
Proposed branch: ~hloeung/content-cache-charm:master
Merge into: content-cache-charm:master
Diff against target: 91 lines (+24/-3)
6 files modified
lib/utils.py (+10/-0)
reactive/content_cache.py (+2/-1)
tests/unit/files/config_test_config.txt (+1/-0)
tests/unit/files/nginx_config_rendered_test_output-site5.txt (+1/-1)
tests/unit/test_nginx.py (+3/-1)
tests/unit/test_utils.py (+7/-0)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Review via email: mp+366153@code.launchpad.net

Commit message

Allow overriding backend/proxy path

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM, see comments inline.

review: Approve (+1)
Revision history for this message
Haw Loeung (hloeung) :
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Merge proposal is approved, but source revision has changed, setting status to needs review.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 4b43be183bfb3670d2ea4ad4acd0ad13b37e274e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/utils.py b/lib/utils.py
index e1288e4..cff2405 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -57,3 +57,13 @@ def generate_token(signing_secret, url_path, expiry_time):
57 digest = hmac.new(signing_secret.encode(), string_to_sign.encode(),57 digest = hmac.new(signing_secret.encode(), string_to_sign.encode(),
58 hashlib.sha1)58 hashlib.sha1)
59 return "{0}_{1}".format(expiration, digest.hexdigest())59 return "{0}_{1}".format(expiration, digest.hexdigest())
60
61
62def generate_uri(host, port=80, path=None, scheme='http'):
63 if not path:
64 path = ''
65 # XXX: Fix to handle if host is an IPv6 literal
66 if path and not path.startswith('/'):
67 path = '/{}'.format(path)
68 uri = '{scheme}://{host}:{port}{path}'.format(scheme=scheme, host=host, port=port, path=path)
69 return uri
diff --git a/reactive/content_cache.py b/reactive/content_cache.py
index 7f4f3a3..6ab5eb3 100644
--- a/reactive/content_cache.py
+++ b/reactive/content_cache.py
@@ -103,7 +103,8 @@ def configure_nginx(conf_path=None):
103103
104 backend_port = loc_conf.get('backend_port')104 backend_port = loc_conf.get('backend_port')
105 if backend_port:105 if backend_port:
106 lc['backend'] = 'http://localhost:{}'.format(backend_port)106 backend_path = loc_conf.get('backend-path')
107 lc['backend'] = utils.generate_uri('localhost', backend_port, backend_path)
107108
108 # Per site secret HMAC key, if it exists. We pass this through to109 # Per site secret HMAC key, if it exists. We pass this through to
109 # the caching layer to activate the bit to restrict access.110 # the caching layer to activate the bit to restrict access.
diff --git a/tests/unit/files/config_test_config.txt b/tests/unit/files/config_test_config.txt
index e074496..9b29970 100644
--- a/tests/unit/files/config_test_config.txt
+++ b/tests/unit/files/config_test_config.txt
@@ -66,3 +66,4 @@ site5:
66 modifier: '='66 modifier: '='
67 backends:67 backends:
68 - 127.0.1.11:8068 - 127.0.1.11:80
69 backend-path: /auth-check/
diff --git a/tests/unit/files/nginx_config_rendered_test_output-site5.txt b/tests/unit/files/nginx_config_rendered_test_output-site5.txt
index 9425247..8827016 100644
--- a/tests/unit/files/nginx_config_rendered_test_output-site5.txt
+++ b/tests/unit/files/nginx_config_rendered_test_output-site5.txt
@@ -18,7 +18,7 @@ server {
1818
1919
20 location = /auth {20 location = /auth {
21 proxy_pass http://localhost:8084;21 proxy_pass http://localhost:8084/auth-check/;
22 proxy_set_header Host "site5.local";22 proxy_set_header Host "site5.local";
23 proxy_cache site5-cache;23 proxy_cache site5-cache;
24 proxy_cache_background_update on;24 proxy_cache_background_update on;
diff --git a/tests/unit/test_nginx.py b/tests/unit/test_nginx.py
index a58ef7e..31d6a9e 100644
--- a/tests/unit/test_nginx.py
+++ b/tests/unit/test_nginx.py
@@ -7,6 +7,7 @@ import yaml
77
8sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))8sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
9from lib import nginx # NOQA: E4029from lib import nginx # NOQA: E402
10from lib import utils # NOQA: E402
1011
11BASE_LISTEN_PORT = 608012BASE_LISTEN_PORT = 6080
12BASE_BACKEND_PORT = 808013BASE_BACKEND_PORT = 8080
@@ -59,7 +60,8 @@ class TestLibNginx(unittest.TestCase):
5960
60 if loc_conf.get('backends'):61 if loc_conf.get('backends'):
61 backend_port += 162 backend_port += 1
62 lc['backend'] = 'http://localhost:{}'.format(backend_port)63 backend_path = loc_conf.get('backend-path')
64 lc['backend'] = utils.generate_uri('localhost', backend_port, backend_path)
6365
64 lc['signed-url-hmac-key'] = loc_conf.get('signed-url-hmac-key')66 lc['signed-url-hmac-key'] = loc_conf.get('signed-url-hmac-key')
65 lc['origin-headers'] = loc_conf.get('origin-headers')67 lc['origin-headers'] = loc_conf.get('origin-headers')
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index 89604c8..8a0fd9c 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -68,3 +68,10 @@ class TestLibUtils(unittest.TestCase):
68 expiry_time = datetime.datetime.now() + datetime.timedelta(days=1)68 expiry_time = datetime.datetime.now() + datetime.timedelta(days=1)
69 want = '1553299200_d5257bb9f1e5e27065f2e7c986ca8c95f4cc3680'69 want = '1553299200_d5257bb9f1e5e27065f2e7c986ca8c95f4cc3680'
70 self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), want)70 self.assertEqual(utils.generate_token(signing_key, '/', expiry_time), want)
71
72 def test_generate_uri(self):
73 self.assertEqual(utils.generate_uri('localhost'), 'http://localhost:80')
74 self.assertEqual(utils.generate_uri('localhost', 8080), 'http://localhost:8080')
75 self.assertEqual(utils.generate_uri('localhost', path='mypath'), 'http://localhost:80/mypath')
76 self.assertEqual(utils.generate_uri('localhost', path='/mypath'), 'http://localhost:80/mypath')
77 self.assertEqual(utils.generate_uri('10.0.0.1', path='/mypath'), 'http://10.0.0.1:80/mypath')

Subscribers

People subscribed via source and target branches