Skip to content

Commit

Permalink
Use a special env variable to indicate real site
Browse files Browse the repository at this point in the history
We're transitioning to a new web address.
It would be much easier to move if we didn't use the domain
name to determine if we're the "real" site.

Signed-off-by: David A. Wheeler <[email protected]>
  • Loading branch information
david-a-wheeler committed Jul 31, 2023
1 parent 43e0628 commit 7ee0ab5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
module SessionsHelper
SESSION_TTL = 48.hours # Automatically log off session if inactive this long
RESET_SESSION_TIMER = 1.hour # Active sessions older than this reset timer
PRODUCTION_HOSTNAME = 'bestpractices.coreinfrastructure.org'
GITHUB_PATTERN = %r{
\Ahttps://github.com/([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)/?\Z
}x.freeze
Expand Down Expand Up @@ -190,10 +189,8 @@ def can_current_user_edit_on_github?(url)
# Returns true iff this is not the REAL final production system,
# including the master/main and staging systems.
# It only returns false if we are "truly in production"
def in_development?(hostname = ENV.fetch('PUBLIC_HOSTNAME', nil))
return true if hostname.nil?

hostname != PRODUCTION_HOSTNAME
def in_development?(is_real = ENV.fetch('BADGEAPP_REAL_PRODUCTION', nil))
return is_real.nil?
end

# Redirects to stored location (or to the default)
Expand Down
7 changes: 6 additions & 1 deletion docs/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ The application is configured by various environment variables:
project was last sent a reminder
* RAILS_ENV (default 'development'): Rails environment, one of
'test', 'development', 'fake_production', and 'production'.
The main/master, staging, and production systems set this to 'production'.
The main/master, staging, and production systems set this to 'production',
because we want our final test systems to be as
"most like the real production system as practical".
See the discussion below about fake_production.
* BADGEAPP_REAL_PRODUCTION: Has a non-empty value (conventionally "true") if
this is the *true* production system. If not present, we show the user a
warning that this isn't the production system.
* BADGEAPP_DAY_FOR_MONTHLY: Day of the month to monthly activities, e.g.,
send out monthly reminders. Default 5. Set to 0 to disable monthly acts.
* FASTLY_CLIENT_IP_REQUIRED: If present, download the Fastly list of
Expand Down
4 changes: 2 additions & 2 deletions test/unit/not_in_development_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class NotInDevelopmentTest < ActiveSupport::TestCase
test 'The production system will say it is NOT in development' do
ac = ApplicationController.new
assert ac.in_development?('staging.coreinfrastructure.org')
assert_not ac.in_development?('bestpractices.coreinfrastructure.org')
assert ac.in_development?
assert_not ac.in_development?('true')
end
end

0 comments on commit 7ee0ab5

Please sign in to comment.