Skip to content

Commit abc3de7

Browse files
committed
Add new secrets.yml to installation generator
(and update the dummy app to have one)
1 parent e8a683c commit abc3de7

9 files changed

Lines changed: 104 additions & 7 deletions

File tree

lib/generators/open_conference_ware/install/install_generator.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'securerandom'
2+
13
class OpenConferenceWare::InstallGenerator < Rails::Generators::Base
24
source_root File.expand_path('../templates', __FILE__)
35

@@ -15,10 +17,18 @@ def copy_omniauth_initializer
1517
copy_file "omniauth_initializer.rb", "config/initializers/02_omniauth.rb"
1618
end
1719

20+
def generate_secrets_yml
21+
template "secrets.yml.erb", "config/secrets.yml"
22+
end
23+
1824
def mount_engine
1925
route %Q{mount OpenConferenceWare::Engine => "#{mount_point}"}
2026
end
2127

28+
def replace_secret_token_initializer
29+
template "secret_token.rb.erb", "config/initializers/secret_token.rb"
30+
end
31+
2232
def include_engine_seeds
2333
append_to_file "db/seeds.rb" do
2434
<<-SEED

lib/generators/open_conference_ware/install/templates/config_initializer.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
# TODO: Setting the current event here is a short-term hack and will be replaced shortly with a Site record that tracks the current event in the database and provides a way to set it through an admin web UI.
2828
# config.current_event_slug = '2012'
2929

30+
##[ Secrets ]##
31+
# Some are sensitive and should not be checked in to version control.
32+
# These are loaded from config/secrets.yml, which should be privately copied to your
33+
# server and linked by your deployment process.
34+
35+
secrets_file = Rails.root.join('config', 'secrets.yml')
36+
if File.exists?(secrets_file)
37+
secrets = YAML.load_file(secrets_file)
38+
config.administrator_email = secrets["administrator_email"]
39+
config.comments_secret = secrets["comments_secret"]
40+
config.secret_key_base = secrets["secret_key_base"]
41+
else
42+
raise "Oops, config/secrets.yml could not be found."
43+
end
44+
3045
##[ OCW Features ]##
3146
# Many features of OpenConferenceWare can be toggled via these settings
3247

@@ -114,5 +129,4 @@
114129
# NOTE: The current default theme never displays any breadcrumbs, but infrastructure exists to support them.
115130
#
116131
# config.breadcrumbs = [['Home', 'http://openconferenceware.org']]
117-
118132
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Be sure to restart your server when you modify this file.
2+
3+
# Your secret key is used for verifying the integrity of signed cookies.
4+
# If you change this key, all old signed cookies will become invalid!
5+
6+
# Make sure the secret is at least 30 characters and all random,
7+
# no regular words or you'll be exposed to dictionary attacks.
8+
# You can use `rake secret` to generate a secure secret key.
9+
10+
# Make sure your secret_key_base is kept private
11+
# if you're sharing your code publicly.
12+
<%= Rails.application.class.to_s %>.config.secret_key_base = OpenConferenceWare.secret_key_base
13+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#===[ Secrets ]=========================================================
2+
#
3+
# This file is meant for storing secret information that is never
4+
# published or committed to a revision control system.
5+
#
6+
#---[ Values ]----------------------------------------------------------
7+
8+
# Email address of administrator that will get requests for assistance from users:
9+
administrator_email: 'your@email.addr'
10+
11+
# Secret key for getting an ATOM feed of private comments:
12+
comments_secret: <%= SecureRandom.hex(64) %>
13+
14+
# The Rails secret_key_base
15+
# Used by config/initializers/secret_token.rb
16+
secret_key_base: <%= SecureRandom.hex(64) %>
17+
18+
#===[ fin ]=============================================================

lib/open_conference_ware.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def self.mounted_path(path)
2222
# Email address of administrator that will get exception notifications
2323
# and requests for assistance from users:
2424
mattr_accessor :administrator_email
25-
self.administrator_email ||= 'your@email.addr'
2625

2726
# Secret key for getting an ATOM feed of private comments:
2827
mattr_accessor :comments_secret
29-
self.comments_secret ||= '1234'
28+
29+
# The secret_key_base, which we'll pass on to Rails
30+
mattr_accessor :secret_key_base
3031

3132
# Email
3233

spec/dummy/config/initializers/01_open_conference_ware.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
# in some cases with a string like "/open_conference_ware"
77
config.mount_point = '/open_conference_ware'
88

9+
# Mailer host
10+
# The hostname to use when generating links in emails.
11+
# This shoud be the domain where OCW is hosted.
12+
config.mailer_host = 'ocw.local'
13+
914
# Event name, or organization running events:
1015
config.organization = 'Open Source Bridge'
1116

@@ -22,6 +27,21 @@
2227
# TODO: Setting the current event here is a short-term hack and will be replaced shortly with a Site record that tracks the current event in the database and provides a way to set it through an admin web UI.
2328
# config.current_event_slug = '2012'
2429

30+
##[ Secrets ]##
31+
# Some are sensitive and should not be checked in to version control.
32+
# These are loaded from config/secrets.yml, which should be privately copied to your
33+
# server and linked by your deployment process.
34+
35+
secrets_file = Rails.root.join('config', 'secrets.yml')
36+
if File.exists?(secrets_file)
37+
secrets = YAML.load_file(secrets_file)
38+
config.administrator_email = secrets["administrator_email"]
39+
config.comments_secret = secrets["comments_secret"]
40+
config.secret_key_base = secrets["secret_key_base"]
41+
else
42+
raise "Oops, config/secrets.yml could not be found."
43+
end
44+
2545
##[ OCW Features ]##
2646
# Many features of OpenConferenceWare can be toggled via these settings
2747

@@ -64,13 +84,16 @@
6484
# Can users add comments until a toggle is flipped on the event?
6585
config.have_event_proposal_comments_after_deadline = true
6686

87+
# Can users note their favorite sessions?
88+
config.have_user_favorites = true
89+
6790
# What audience experience levels can a proposal be classified as?
6891
# The list will be displayed on the form in the order defined below.
6992
# The "slug" is the unique key defining the particular audience level, while
7093
# the "label" is the human-readable value displayed.
7194
#
7295
# Set this to a blank array to disable audience levels
73-
config.proposal_audience_levels ||= [
96+
config.proposal_audience_levels = [
7497
{slug: 'a', label: 'Beginner'},
7598
{slug: 'b', label: 'Intermediate'},
7699
{slug: 'c', label: 'Advanced'}
@@ -106,5 +129,4 @@
106129
# NOTE: The current default theme never displays any breadcrumbs, but infrastructure exists to support them.
107130
#
108131
# config.breadcrumbs = [['Home', 'http://openconferenceware.org']]
109-
110132
end

spec/dummy/config/initializers/02_omniauth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
OmniAuth.config.path_prefix = OpenConferenceWare.mounted_path("/auth")
1+
OmniAuth.config.path_prefix = OpenConferenceWare.mounted_path("auth")
22

33
Rails.application.config.middleware.use OpenConferenceWare::OmniAuthBuilder do
44
provider :developer if %w[development preview].include?(Rails.env)

spec/dummy/config/initializers/secret_token.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99

1010
# Make sure your secret_key_base is kept private
1111
# if you're sharing your code publicly.
12-
Dummy::Application.config.secret_key_base = 'cb9562396c82c1de554ec36a5832641b772ff8e0fad846dbd7833f9ee97dd05715a914fe979bc651065a1f27ea9256ce1f786e610ddaf3e4fdf98794a7855b94'
12+
Dummy::Application.config.secret_key_base = OpenConferenceWare.secret_key_base
13+

spec/dummy/config/secrets.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#===[ Secrets ]=========================================================
2+
#
3+
# This file is meant for storing secret information that is never
4+
# published or committed to a revision control system.
5+
#
6+
#---[ Values ]----------------------------------------------------------
7+
8+
# Email address of administrator that will get requests for assistance from users:
9+
administrator_email: 'your@email.addr'
10+
11+
# Secret key for getting an ATOM feed of private comments:
12+
comments_secret: e7ed7cc63ae64f10fcb1dd9c7ba34656242dca9642222dcdaa8bd63a074913d9edbe300b0bef6bdc24e9a4cf7ad3f3177c6a762a8b62ad5ca482570d3969b19b
13+
14+
# The Rails secret_key_base
15+
# Used by config/initializers/secret_token.rb
16+
secret_key_base: 1f5085ba0fbf858fa957a9ea1406898266b8685a51da9b2127afcd8d2e54ba454a51cd59d39265e1819144da15594874dcb5a8bbfd2a5f3bcc7d30960619bb94
17+
18+
#===[ fin ]=============================================================

0 commit comments

Comments
 (0)