Skip to content

Commit 59518c9

Browse files
committed
Render AlaveteliConfiguration on admin debug page
Makes it easier for less technical users to look up specific configuration values – or indeed, save technical users opening an ssh session. Fixes #1636
1 parent 23512b0 commit 59518c9

File tree

8 files changed

+58
-5
lines changed

8 files changed

+58
-5
lines changed

app/controllers/admin/debug_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ def index
77
repo = `git remote show origin -n | perl -ne 'print $1 if m{Fetch URL: .*github\\.com[:/](.*)\\.git}'`
88
@github_origin = "https://github.com/#{repo}/tree/"
99
@request_env = request.env
10+
@alaveteli_configuration = AlaveteliConfiguration.to_sanitized_hash
1011
end
1112
end

app/views/admin/debug/index.html.erb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545

4646
<h2>Configuration</h2>
4747

48+
<div class="help-block">
49+
<p>
50+
See the <a href="https://alaveteli.org/docs/customising/config/">
51+
documentation</a> for more information about configuring Alaveteli.
52+
</p>
53+
54+
<p>
55+
Sensitive values are replaced with <tt>[FILTERED]</tt>. Use the
56+
<tt>config/general.yml</tt> configuration file to view these.
57+
</p>
58+
</div>
59+
4860
<table class="table table-condensed table-debug">
4961
<tr>
5062
<td>Rails env:</td>
@@ -56,6 +68,15 @@
5668
</tr>
5769
</table>
5870

71+
<table class="table table-condensed table-debug">
72+
<% @alaveteli_configuration.each do |k,v| %>
73+
<tr>
74+
<td><%= k %></td>
75+
<td><%= v %></td>
76+
</tr>
77+
<% end %>
78+
</table>
79+
5980
<h2>Environment variables</h2>
6081

6182
<table class="table table-condensed table-debug">

app/views/admin_general/_admin_navbar.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<li><%= link_to 'Summary', admin_general_index_path %></li>
1919
<li><%= link_to 'Timeline', admin_timeline_path %></li>
2020
<li><%= link_to 'Stats', admin_stats_path %></li>
21-
<li><%= link_to 'Debug', admin_debug_path %></li>
21+
<li><%= link_to 'Debug', admin_debug_index_path %></li>
2222
</ul>
2323
</li>
2424

config/general.yml-example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# Default values for these settings can be found in
1313
# RAILS_ROOT/lib/configuration.rb
1414
#
15+
#
16+
# WARNING: AlaveteliConfiguration is rendered to admin users in
17+
# Admin::DebugController.
18+
#
19+
# Ensure any sensitive values are matched by
20+
# AlaveteliConfiguration.sensitive_key_patterns
21+
#
1522
# ==============================================================================
1623

1724
# Site name appears in various places throughout the site

config/routes.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,7 @@ def matches?(request)
528528

529529
#### Admin::Debug controller
530530
namespace :admin do
531-
# FIXME: For some reason the resources call is generating the route as
532-
# admin_debug_index_path rather than the standard admin_debug_path.
533-
# resources :debug, only: [:index]
534-
get 'debug', to: 'debug#index', as: :debug
531+
resources :debug, only: :index
535532
end
536533
####
537534

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Highlighted Features
44

5+
* Render Alaveteli configuration values on admin debug page (Gareth Rees)
56
* View user profile photos from admin list of users (Gareth Rees)
67
* Update user email to be sent from the blackhole address (Graeme Porteous)
78
* Remove ability to publicly view authority contact email addresses to prevent

lib/configuration.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
# TODO: Make this return different values depending on the current rails environment
1414

1515
module AlaveteliConfiguration
16+
# WARNING: AlaveteliConfiguration is rendered to admin users in
17+
# Admin::DebugController.
18+
#
19+
# Ensure any sensitive values match this pattern, or add to the pattern if
20+
# adding a new value that doesn't fit.
21+
mattr_accessor :sensitive_key_patterns,
22+
default: /SECRET|PASSWORD|LICENSE_KEY/
23+
1624
unless const_defined?(:DEFAULTS)
1725

1826
# rubocop:disable Layout/LineLength
@@ -150,4 +158,12 @@ def self.method_missing(name)
150158
super
151159
end
152160
end
161+
162+
def self.to_sanitized_hash
163+
DEFAULTS.keys.each_with_object({}) do |key, memo|
164+
value = send(key)
165+
value = '[FILTERED]' if value.present? && key =~ sensitive_key_patterns
166+
memo[key] = value
167+
end
168+
end
153169
end

spec/lib/configuration_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'spec_helper'
2+
3+
RSpec.describe AlaveteliConfiguration do
4+
include AlaveteliConfiguration
5+
6+
describe '#to_sanitized_hash' do
7+
subject { described_class.to_sanitized_hash }
8+
it { is_expected.to include(:INCOMING_EMAIL_SECRET => '[FILTERED]') }
9+
end
10+
end

0 commit comments

Comments
 (0)