From 666394de25be36d049b2db575e11170f3898844c Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Thu, 22 Feb 2024 13:07:43 -0800 Subject: [PATCH] Refactor Impress 2020 config I've moved the support secret into the encrypted credentials file, and moved the origin into a top-level custom config value in the environment files, with different defaults per environment but still the ability to override it. (I don't use this, but it feels polite to not actually *demand* that people use port 4000, y'know?) --- app/helpers/application_helper.rb | 12 +++++++----- app/models/outfit.rb | 2 +- config/credentials.yml.enc | 2 +- config/environments/development.rb | 5 +++++ config/environments/production.rb | 5 +++++ config/environments/test.rb | 5 +++++ config/initializers/impress_2020.rb | 5 ----- config/routes.rb | 2 +- 8 files changed, 25 insertions(+), 13 deletions(-) delete mode 100644 config/initializers/impress_2020.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index db796063..746c19ea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -93,13 +93,15 @@ module ApplicationHelper end def impress_2020_meta_tags - impress_2020 = Rails.configuration.x.impress_2020 + origin = Rails.configuration.impress_2020_origin + support_secret = Rails.application.credentials.impress_2020.support_secret + capture do - concat tag("meta", name: "impress-2020-origin", - content: impress_2020.origin) - if support_staff? && impress_2020.support_secret.present? + concat tag("meta", name: "impress-2020-origin", content: origin) + + if support_staff? && support_secret.present? concat tag("meta", name: "impress-2020-support-secret", - content: impress_2020.support_secret) + content: support_secret) end end end diff --git a/app/models/outfit.rb b/app/models/outfit.rb index 478adbd6..3581fe1a 100644 --- a/app/models/outfit.rb +++ b/app/models/outfit.rb @@ -62,7 +62,7 @@ class Outfit < ApplicationRecord end IMAGE_URL_TEMPLATE = Addressable::Template.new( - Rails.configuration.x.impress_2020.origin + + Rails.configuration.impress_2020_origin + "/api/outfitImage{?id,size,updatedAt}" ) def image_versions diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 0d635830..6874e54c 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -c2Us7svFW8MtlkzQwd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BT2lkTHdqnMIiYSEqBlvc/yAuDyxyXqndMvYhDsdetNdnIxATRkpA+mU4CHlgcv30J5l3obLN8UA0oHPL9lTMWU63E4JyQTwVEHGLy+J8TMZgJX1imCCzCzWL7ytdDy7HdZFXrVPxj+z95/PH//2NcvuAdwbnKX7Pk0ujEBwSnkmiw1UZgl5VT5G2yLwYqFY1VgyINBN42ynFFRfiNjk9Q9bIHk3i2bQnDAw9EtAuKbpdJ9IXboTAOHOIZpanW6RiIfIGk+MM5GLKOSthv6XCzhLue7P//tprHT85yE1vnhLNeCGg1EtgDlM9y--xXvKjFS/mwn+dHoa--u457xDa2Q8CLtVbYkL6pig== \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index b4843922..d57dad98 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -102,4 +102,9 @@ Rails.application.configure do # Allow connections on Vagrant's private network. config.web_console.permissions = '10.0.2.2' + + # Use a local copy of Impress 2020, presumably running on port 4000. (Can + # override this with the IMPRESS_2020_ORIGIN environment variable!) + config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN", + "http://localhost:4000") end diff --git a/config/environments/production.rb b/config/environments/production.rb index b8307b59..37c5cfb3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -121,4 +121,9 @@ Rails.application.configure do # ] # Skip DNS rebinding protection for the default health check endpoint. # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + + # Use the live copy of Impress 2020. (Can override this with the + # IMPRESS_2020_ORIGIN environment variable!) + config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN", + "https://impress-2020.openneo.net") end diff --git a/config/environments/test.rb b/config/environments/test.rb index 91b9caf8..d7dee4e8 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -61,4 +61,9 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true + + # Use a local copy of Impress 2020, presumably running on port 4000. (Can + # override this with the IMPRESS_2020_ORIGIN environment variable!) + config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN", + "http://localhost:4000") end diff --git a/config/initializers/impress_2020.rb b/config/initializers/impress_2020.rb deleted file mode 100644 index cbe2b352..00000000 --- a/config/initializers/impress_2020.rb +++ /dev/null @@ -1,5 +0,0 @@ -Rails.configuration.x.impress_2020.origin = - ENV.fetch("IMPRESS_2020_ORIGIN", "https://impress-2020.openneo.net") - -Rails.configuration.x.impress_2020.support_secret = - ENV.fetch("IMPRESS_2020_SUPPORT_SECRET", nil) diff --git a/config/routes.rb b/config/routes.rb index 33dbbd0c..9edf4575 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -91,7 +91,7 @@ OpenneoImpressItems::Application.routes.draw do # Static pages! get '/terms', as: :terms, - to: redirect(Rails.configuration.x.impress_2020.origin + "/terms") + to: redirect(Rails.configuration.impress_2020_origin + "/terms") # Other useful lil things! get '/sitemap.xml' => 'sitemap#index', :as => :sitemap, :format => :xml