[Closes #1170] Put tps-dev (staging) environement behind a BasicAuth
This commit is contained in:
parent
2336b0207e
commit
26b1de5883
2 changed files with 31 additions and 0 deletions
|
@ -7,6 +7,14 @@ class ApplicationController < ActionController::Base
|
||||||
before_action :set_raven_context
|
before_action :set_raven_context
|
||||||
before_action :authorize_request_for_profiler
|
before_action :authorize_request_for_profiler
|
||||||
|
|
||||||
|
before_action :staging_authenticate
|
||||||
|
|
||||||
|
def staging_authenticate
|
||||||
|
if StagingAuthService.enabled? && !authenticate_with_http_basic { |username, password| StagingAuthService.authenticate(username, password) }
|
||||||
|
request_http_basic_authentication
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def authorize_request_for_profiler
|
def authorize_request_for_profiler
|
||||||
if administration_signed_in?
|
if administration_signed_in?
|
||||||
Rack::MiniProfiler.authorize_request
|
Rack::MiniProfiler.authorize_request
|
||||||
|
|
23
app/services/staging_auth_service.rb
Normal file
23
app/services/staging_auth_service.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
class StagingAuthService
|
||||||
|
CONFIG_PATH = Rails.root.join("/config/basic_auth.yml")
|
||||||
|
|
||||||
|
def self.authenticate(username, password)
|
||||||
|
if enabled?
|
||||||
|
username == config[:username] && password == config[:password]
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
!!config[:enabled]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.config
|
||||||
|
if File.exists?(CONFIG_PATH)
|
||||||
|
YAML.safe_load(File.read(CONFIG_PATH)).symbolize_keys
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue