Skip to content

Commit

Permalink
Use GOVUK_ENVIRONMENT instead of GOVUK_ENVIRONMENT_NAME
Browse files Browse the repository at this point in the history
Both environment variables are set to the same value. GOVUK_ENVIRONMENT
is used more frequently, renaming for consistency.
  • Loading branch information
theseanything committed Jun 5, 2024
1 parent 1221307 commit 47d840f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ FROM --platform=$TARGETPLATFORM $builder_image AS builder

ENV DEVISE_PEPPER=unused \
DEVISE_SECRET_KEY=unused \
GOVUK_ENVIRONMENT_NAME=unused
GOVUK_ENVIRONMENT=unused

WORKDIR $APP_HOME
COPY Gemfile* .ruby-version ./
Expand Down
2 changes: 1 addition & 1 deletion app/models/govuk_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def self.name
if Rails.env.development? || Rails.env.test?
"development"
else
ENV.fetch("GOVUK_ENVIRONMENT_NAME")
ENV.fetch("GOVUK_ENVIRONMENT")
end
end

Expand Down
2 changes: 1 addition & 1 deletion docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ Used to configure Google Analytics in the new `app/views/layouts/admin_layout.ht

Used to configure `GovukAdminTemplate` and in `Healthcheck::ApiTokens#expiring_tokens`.

* `GOVUK_ENVIRONMENT_NAME`
* `GOVUK_ENVIRONMENT`
2 changes: 1 addition & 1 deletion lib/healthcheck/api_tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ApiTokens
) tokens
INNER JOIN users ON users.id = tokens.resource_owner_id
WHERE tokens.revoked_at IS NULL
AND users.email NOT LIKE '%@#{ENV['GOVUK_ENVIRONMENT_NAME']}.publishing.service.gov.uk'
AND users.email NOT LIKE '%@#{ENV['GOVUK_ENVIRONMENT']}.publishing.service.gov.uk'
AND users.name NOT LIKE '%[EKS]'
AND users.api_user = TRUE
AND tokens.expires_in < #{WARNING_THRESHOLD}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/healthcheck/api_tokens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PermissionUpdaterTest < ActiveSupport::TestCase
end

should "return 'OK' when tokens for @<env>.publishing.service.gov.uk are expiring" do
user = create(:api_user, email: "#{random_str}@#{ENV['GOVUK_ENVIRONMENT_NAME']}.publishing.service.gov.uk")
user = create(:api_user, email: "#{random_str}@#{ENV['GOVUK_ENVIRONMENT']}.publishing.service.gov.uk")

make_api_user_token(
expires_in: Healthcheck::ApiTokens::WARNING_THRESHOLD,
Expand Down
8 changes: 4 additions & 4 deletions test/models/govuk_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class GovukEnvironmentTest < ActionMailer::TestCase
Rails.env.stubs(:test?).returns(false)
end

should "return value of GOVUK_ENVIRONMENT_NAME if it is set" do
ClimateControl.modify(GOVUK_ENVIRONMENT_NAME: "govuk-environment-name") do
should "return value of GOVUK_ENVIRONMENT if it is set" do
ClimateControl.modify(GOVUK_ENVIRONMENT: "govuk-environment-name") do
assert_equal "govuk-environment-name", GovukEnvironment.name
end
end

should "fail fast if GOVUK_ENVIRONMENT_NAME is not set" do
ClimateControl.modify(GOVUK_ENVIRONMENT_NAME: nil) do
should "fail fast if GOVUK_ENVIRONMENT is not set" do
ClimateControl.modify(GOVUK_ENVIRONMENT: nil) do
assert_raises(KeyError) { GovukEnvironment.name }
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ENV["RAILS_ENV"] = "test"
ENV["GOVUK_ENVIRONMENT_NAME"] = "test"
ENV["GOVUK_ENVIRONMENT"] = "test"

require "simplecov"
SimpleCov.start "rails"
Expand Down

0 comments on commit 47d840f

Please sign in to comment.