From e960dfb7dfb7b910d1800adb562d138349cae5d0 Mon Sep 17 00:00:00 2001 From: TheJoeCoder <joe@radialbog9.uk> Date: Fri, 5 Jul 2024 18:00:03 +0100 Subject: [PATCH] Update demo --- docker-compose.demo.yml | 22 ++++++++++++++++++---- heyheyLibrary/settings.py | 4 ++-- librarian/views.py | 4 ++-- local_settings_prod.py | 1 + nginx_demo_googleapis.conf | 24 ++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 nginx_demo_googleapis.conf diff --git a/docker-compose.demo.yml b/docker-compose.demo.yml index 4ddb4bb..130961e 100644 --- a/docker-compose.demo.yml +++ b/docker-compose.demo.yml @@ -7,6 +7,7 @@ services: - OPENSEARCH_USERNAME=admin - OPENSEARCH_PASSWORD=VeryInsecurePassword1! - SECRET_KEY=VeryInsecureSecretKey + - GOOGLEAPIS_BASE_URL=http://www.googleapis.com # Downgrade the base URL to HTTP, so we can proxy it volumes: - demo_static:/home/app/web/staticfiles - ./demo_media:/home/app/web/mediafiles @@ -16,7 +17,9 @@ services: depends_on: - opensearch networks: - - librarydemo + - librarydemo-internal + links: + - nginx-googleapisproxy:www.googleapis.com opensearch: image: opensearchproject/opensearch:latest @@ -37,7 +40,15 @@ services: - 9200 - 9600 networks: - - librarydemo + - librarydemo-internal + + nginx-googleapisproxy: + image: nginx:1.27 + volumes: + - ./nginx_demo_googleapis.conf:/etc/nginx/nginx.conf:ro + networks: + - librarydemo-internal + - librarydemo-external nginx: image: nginx:1.27 @@ -50,11 +61,14 @@ services: depends_on: - web networks: - - librarydemo + - librarydemo-internal volumes: demo_static: demo_opensearch: networks: - librarydemo: \ No newline at end of file + librarydemo-internal: + # Block all external traffic to the network + internal: true + librarydemo-external: {} \ No newline at end of file diff --git a/heyheyLibrary/settings.py b/heyheyLibrary/settings.py index aadea86..a80baa9 100644 --- a/heyheyLibrary/settings.py +++ b/heyheyLibrary/settings.py @@ -162,17 +162,17 @@ SPECTACULAR_SETTINGS = { 'REDOC_DIST': 'SIDECAR', } - # Library settings LIBRARY_SETTINGS = { 'MAX_ACTIVE_LOANS_PER_USER': 5, 'DEFAULT_LOAN_DURATION': 7, } - # Opensearch Settings OPENSEARCH_DSL = { 'default': { 'hosts': 'localhost:9200' } } + +GOOGLEAPIS_BASE_URL = "https://www.googleapis.com" diff --git a/librarian/views.py b/librarian/views.py index 63eb416..0ac3a55 100644 --- a/librarian/views.py +++ b/librarian/views.py @@ -37,7 +37,7 @@ def load_gbooks_query_pagination(query): "startIndex": len(items), "maxResults": 40 } - res = requests.get("https://www.googleapis.com/books/v1/volumes?" + urlencode(qry)) + res = requests.get(settings.GOOGLEAPIS_BASE_URL + "/books/v1/volumes?" + urlencode(qry)) if not res.ok: return None data = res.json() @@ -259,7 +259,7 @@ def book_add_flow_3(request, **kwargs): form = BookAddForm() if typ == "gbooks" and tid is not None: # Query Google Books API for book details - res = requests.get("https://www.googleapis.com/books/v1/volumes/" + tid) + res = requests.get(settings.GOOGLEAPIS_BASE_URL + "/books/v1/volumes/" + tid) if not res.ok: other_errors.append("Google Books API request failed") else: diff --git a/local_settings_prod.py b/local_settings_prod.py index b224860..4ed5cdf 100644 --- a/local_settings_prod.py +++ b/local_settings_prod.py @@ -49,3 +49,4 @@ OPENSEARCH_DSL = { } } +GOOGLEAPIS_BASE_URL = os.environ.get("GOOGLEAPIS_URL_OVERRIDE", GOOGLEAPIS_BASE_URL) diff --git a/nginx_demo_googleapis.conf b/nginx_demo_googleapis.conf new file mode 100644 index 0000000..3502a00 --- /dev/null +++ b/nginx_demo_googleapis.conf @@ -0,0 +1,24 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + limit_req_zone all zone=one:1m rate=10r/m; + limit_req zone=one burst=1 nodelay; + server { + listen 80; + location / { + proxy_pass https://www.googleapis.com; + proxy_set_header Host www.googleapis.com; + proxy_redirect off; + } + } +} \ No newline at end of file -- GitLab