Skip to content

Commit

Permalink
Rename CKAN_REDIRECTION_URL to CKAN_DOMAIN
Browse files Browse the repository at this point in the history
The CKAN_REDIRECTION_URL is no longer a full URL, it's just the domain
which CKAN is running on. The code that does the redirect adds the other
parts of the URL (the protocol and the path).

As well as this, I want to add the CKAN Domain to the content security
policy on some pages. It wouldn't make sense to add a redirection URL to
the CSP, so it feels important that this is named accurately.

I also found that config.ckan_redirection_url wasn't used anywhere, so
I've removed it.
  • Loading branch information
richardTowers committed Aug 6, 2021
1 parent f5a00b4 commit 9e5e48b
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/setup-docker-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# source this script before running tests in docker ckan to set the correct env vars
export RAILS_ENV=test
export ES_INDEX=datasets-test
export CKAN_REDIRECTION_URL=testdomain
export CKAN_DOMAIN=testdomain

# install chrome for tests
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Expand Down
2 changes: 0 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,4 @@
# config.action_cable.disable_request_forgery_protection = true

config.zendesk = nil

config.ckan_redirection_url = ENV["CKAN_REDIRECTION_URL"]
end
2 changes: 0 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,4 @@
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

config.ckan_redirection_url = ENV["CKAN_REDIRECTION_URL"]
end
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

get "/sites/default/files/*organogram_path", to: redirect("https://s3-eu-west-1.amazonaws.com/datagovuk-#{Rails.env}-ckan-organogram/legacy/%{organogram_path}"), format: false

if ENV["CKAN_REDIRECTION_URL"].present?
get "dataset/edit/:legacy_name", to: redirect(domain: ENV["CKAN_REDIRECTION_URL"], subdomain: "", path: "/dataset/edit/%{legacy_name}")
if ENV["CKAN_DOMAIN"].present?
get "dataset/edit/:legacy_name", to: redirect(domain: ENV["CKAN_DOMAIN"], subdomain: "", path: "/dataset/edit/%{legacy_name}")
end

get "dataset/:uuid", to: "datasets#show", uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
Expand Down Expand Up @@ -55,9 +55,9 @@
get "acknowledge", to: "messages#acknowledge"

# Route everything else to CKAN
if ENV["CKAN_REDIRECTION_URL"].present?
if ENV["CKAN_DOMAIN"].present?
match "*path",
to: redirect(domain: ENV["CKAN_REDIRECTION_URL"], subdomain: "", path: "/%{path}"),
to: redirect(domain: ENV["CKAN_DOMAIN"], subdomain: "", path: "/%{path}"),
via: :all,
constraints: { path: /(?!#{Regexp.quote(Rails.application.config.assets.prefix[1..-1])}).+/ }
end
Expand Down
2 changes: 1 addition & 1 deletion production-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ applications:
env:
RAILS_ENV: production
RACK_ENV: production
CKAN_REDIRECTION_URL: ckan.publishing.service.gov.uk
CKAN_DOMAIN: ckan.publishing.service.gov.uk
GOVUK_APP_DOMAIN: www.gov.uk
GOVUK_WEBSITE_ROOT: https://www.gov.uk
services:
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require "spec_helper"
ENV["RAILS_ENV"] ||= "test"
ENV["CKAN_REDIRECTION_URL"] ||= "testdomain"
ENV["CKAN_DOMAIN"] ||= "testdomain"
require File.expand_path("../config/environment", __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
Expand Down
2 changes: 1 addition & 1 deletion staging-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ applications:
env:
RAILS_ENV: staging
RACK_ENV: staging
CKAN_REDIRECTION_URL: ckan.staging.publishing.service.gov.uk
CKAN_DOMAIN: ckan.staging.publishing.service.gov.uk
GOVUK_APP_DOMAIN: www.gov.uk
GOVUK_WEBSITE_ROOT: https://www.gov.uk
services:
Expand Down

0 comments on commit 9e5e48b

Please sign in to comment.