Skip to content

Commit

Permalink
Rework configs and add cookie domain
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Jun 12, 2024
1 parent db3bcbc commit 96d2dec
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In addition to the [base Docker image variables](https://github.com/nationalarch
| `DEBUG` | If true, allow debugging[^1] | `False` |
| `WAGTAIL_API_URL` | The base URL of the content API, including the `/api/v2` path | _none_ |
| `SEARCH_API_URL` | The base URL of the search API | _none_ |
| `DOMAIN` | The domain the site is hosted on | _none_ |
| `COOKIE_DOMAIN` | The domain to save cookie preferences against | _none_ |
| `CSP_IMG_SRC` | A comma separated list of CSP rules for `img-src` | `'self'` |
| `CSP_SCRIPT_SRC` | A comma separated list of CSP rules for `script-src` | `'self'` |
| `CSP_STYLE_SRC` | A comma separated list of CSP rules for `style-src` | `'self'` |
Expand Down
9 changes: 1 addition & 8 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,7 @@ def context_processor():
cookie_preference=cookie_preference,
now_iso_8601=now_iso_8601,
pretty_date_range=pretty_date_range,
config={
"DOMAIN": app.config["DOMAIN"],
"BASE_DISCOVERY_URL": app.config["BASE_DISCOVERY_URL"],
"SEARCH_DISCOVERY_URL": app.config["SEARCH_DISCOVERY_URL"],
"SEARCH_WEBSITE_URL": app.config["SEARCH_WEBSITE_URL"],
"ARCHIVE_RECORDS_URL": app.config["ARCHIVE_RECORDS_URL"],
"GA4_ID": app.config["GA4_ID"],
},
config=app.config,
)

from .about import bp as about_bp
Expand Down
3 changes: 2 additions & 1 deletion app/legal/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.legal import bp
from app.lib import cache, cache_key_prefix
from app.lib.util import strtobool
from flask import make_response, render_template, request
from flask import make_response, render_template, request, current_app


@bp.route("/")
Expand Down Expand Up @@ -41,6 +41,7 @@ def cookies():
response.set_cookie(
"cookies_policy",
quote(json.dumps(new_cookies_policy, separators=(",", ":"))),
domain=current_app.config["COOKIE_DOMAIN"]
)
return response
return render_template("legal/cookies.html")
Expand Down
3 changes: 2 additions & 1 deletion app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
{# {% if 'cookie_preferences_set' not in request.cookies or not request.cookies.get('cookie_preferences_set') %} #}
{{ tnaCookieBanner({
'serviceName': 'The National Archives',
'cookiesUrl': '/cookies'
'cookiesUrl': '/cookies',
'cookiesDomain': config.COOKIE_DOMAIN
}) }}
{# {% endif %} #}
{% endif %}
Expand Down
3 changes: 0 additions & 3 deletions app/templates/macros/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,4 @@
{%- if og_image_twitter %}
<meta property="twitter:image" content="{{ og_image_twitter.src }}">
{% endif %}
{% if config.DOMAIN %}
<meta property="twitter:domain" content="{{ config.DOMAIN }}">
{% endif %}
{% endmacro %}
5 changes: 1 addition & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Base(object):
WAGTAIL_API_URL = os.environ.get("WAGTAIL_API_URL", "").rstrip("/")
SEARCH_API_URL = os.environ.get("SEARCH_API_URL", "").rstrip("/")

DOMAIN = os.environ.get("DOMAIN", "")
COOKIE_DOMAIN = os.environ.get("COOKIE_DOMAIN", "")

CSP_IMG_SRC = os.environ.get("CSP_IMG_SRC", "'self'").split(",")
CSP_SCRIPT_SRC = os.environ.get("CSP_SCRIPT_SRC", "'self'").split(",")
Expand Down Expand Up @@ -80,9 +80,6 @@ class Test(Base):
WAGTAIL_API_URL = "http://wagtail.test/api/v2"
SEARCH_API_URL = "http://search.test/api/v1"

DOMAIN = "http://localhost"
MEDIA_DOMAIN = "http://media.test"

CACHE_TYPE = "SimpleCache"

FORCE_HTTPS = False
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- NPM_DEVELOP_COMMAND=dev
- WAGTAIL_API_URL=http://host.docker.internal:8000/api/v2
- SEARCH_API_URL=http://host.docker.internal:65534/api/v1
- DOMAIN=http://localhost:65535
- COOKIE_DOMAIN=localhost:65535
- CSP_IMG_SRC='self',localhost:65535,localhost:8000,*.google-analytics.com,*.googletagmanager.com,googletagmanager.com,*.gstatic.com,*.nationalarchives.gov.uk,*.platformsh.site
- CSP_SCRIPT_SRC='self',*.googletagmanager.com,googletagmanager.com,tagmanager.google.com
- CSP_STYLE_SRC='self',fonts.googleapis.com,p.typekit.net,use.typekit.net,googletagmanager.com,www.googletagmanager.com,tagmanager.google.com
Expand Down
4 changes: 2 additions & 2 deletions test/main/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class MainBlueprintTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app("config.Test").test_client()
self.domain = self.app.application.config["DOMAIN"]
self.media_domain = self.app.application.config["MEDIA_DOMAIN"]
self.domain = "TEST"
self.media_domain = "TEST_MEDIA"
self.mock_api_url = self.app.application.config["WAGTAIL_API_URL"]

def test_trailing_slash_redirects(self):
Expand Down

0 comments on commit 96d2dec

Please sign in to comment.