Skip to content

Commit

Permalink
#103 secret_token.rb methodology changed
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdilek committed Nov 8, 2013
1 parent 59de9e1 commit c00cb14
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ def setup_recipes
generate 'recipes_matic:install'
end

def update_secret_token
remove_file 'config/initializers/secret_token.rb'
template 'config/initializers/secret_token.erb', 'config/initializers/secret_token.rb'
end

private

def action_mailer_host(rails_env, host)
Expand Down
4 changes: 3 additions & 1 deletion lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ def setup_recipes
build :setup_recipes
end


def setup_secret_token
build :update_secret_token
end

protected

Expand Down
25 changes: 25 additions & 0 deletions templates/config/initializers/secret_token.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
def find_secure_token
token_file = Rails.root.join('.secret')
if File.exist? token_file
# Use the existing token.
File.read(token_file).chomp
else
# Generate a new token of 64 random hexadecimal characters and store it in token_file.
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end

<%= app_name.classify %>::Application.config.secret_key_base = find_secure_token
4 changes: 1 addition & 3 deletions templates/cybele_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ vendor/bundler_gems
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

# Ignore secret token
config/initializers/secret_token.rb
.secret

1 comment on commit c00cb14

@tayfunoziserikan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.