diff --git a/docker-compose.demo.yml b/docker-compose.demo.yml index 4ddb4bb23979dfea8841cd77d3d91f812cebd9c6..130961efd01b2dfa83beaf6eff18fdb31f820282 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 aadea8662a4087213f484686c4f06deb940624fe..a80baa91cd13814325793ae28f5b4323f8d5138f 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 63eb416a7e7b0de338466eb525c7704034d3d0f1..0ac3a5596a85593f95e4fc436556cfe20a22a669 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 b224860ffccdda07de42d903cf509ae3bd808f6d..4ed5cdf00ec6223e5ac1769179ef5afa9d4e935b 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 0000000000000000000000000000000000000000..3502a006438bd6df468eb49ccb6423e2466cd9a8 --- /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