Skip to content

Commit b4dc06f

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 9a446ec commit b4dc06f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
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">

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
* Update user email to be sent from the blackhole address (Graeme Porteous)
67
* Remove ability to publicly view authority contact email addresses to prevent
78
harvesting (Gareth Rees)

lib/configuration.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
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+
SENSITIVE_KEY_PATTERNS = /SECRET|PASSWORD|LICENSE_KEY/
22+
1623
unless const_defined?(:DEFAULTS)
1724

1825
# rubocop:disable Layout/LineLength
@@ -150,4 +157,12 @@ def self.method_missing(name)
150157
super
151158
end
152159
end
160+
161+
def self.to_sanitized_hash
162+
DEFAULTS.keys.each_with_object({}) do |key, memo|
163+
value = send(key)
164+
value = '[FILTERED]' if value.present? && key =~ SENSITIVE_KEY_PATTERNS
165+
memo[key] = value
166+
end
167+
end
153168
end

0 commit comments

Comments
 (0)