Permalink
Browse files

add roswell_key and make setup task to generate it

  • Loading branch information...
1 parent 7404dc9 commit 5ceccc44585fd176ea080492c44f81e5b2751f2a @blahed committed Nov 15, 2012
Showing with 31 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 app/models/generic_account.rb
  3. +1 −1 app/models/note.rb
  4. +1 −1 app/models/software_license.rb
  5. +1 −1 app/models/web_account.rb
  6. +26 −1 lib/tasks/setup.rake
View
1 .gitignore
@@ -8,6 +8,7 @@
/.bundle
/config/mongoid.yml
+/config/initializers/roswell_key.rb
# Ignore all logfiles and tempfiles.
/log/*.log
View
2 app/models/generic_account.rb
@@ -3,7 +3,7 @@ class GenericAccount < BaseItem
field :username, :type => String
field :comments, :type => String
- encrypted_field :password, :key => Roswell::Application.config.secret_token
+ encrypted_field :password, :key => Roswell::Application.config.roswell_key
validates_presence_of :username
View
2 app/models/note.rb
@@ -2,6 +2,6 @@ class Note < BaseItem
field :body, :type => String
- encrypted_field :body, :key => Roswell::Application.config.secret_token
+ encrypted_field :body, :key => Roswell::Application.config.roswell_key
end
View
2 app/models/software_license.rb
@@ -3,6 +3,6 @@ class SoftwareLicense < BaseItem
field :licensed_to, :type => String
field :comments, :type => String
- encrypted_field :license_key, :key => Roswell::Application.config.secret_token
+ encrypted_field :license_key, :key => Roswell::Application.config.roswell_key
end
View
2 app/models/web_account.rb
@@ -4,7 +4,7 @@ class WebAccount < BaseItem
field :username, :type => String
field :comments, :type => String
- encrypted_field :password, :key => Roswell::Application.config.secret_token
+ encrypted_field :password, :key => Roswell::Application.config.roswell_key
validates_presence_of :username
View
27 lib/tasks/setup.rake
@@ -1,7 +1,22 @@
namespace :roswell do
+ task :create_roswell_key do
+ create_roswell_key
+ end
+
desc 'Do initial setup to get roswell up and running'
- task :setup => :environment do
+ task :setup => [:create_roswell_key, :environment] do
+ create_admin_user
+ end
+
+end
+
+def create_admin_user
+ admin_user = User.where(:admin => true).first
+
+ if admin_user
+ puts "You already have an admin user, looks like roswell is already setup..."
+ else
puts "You'll need to make an admin user to get started..."
print "Username: "
username = STDIN.gets.chomp
@@ -12,5 +27,15 @@ namespace :roswell do
puts "Admin user was created, you may now login and add users & groups"
end
+end
+def create_roswell_key
+ key_path = File.join(Rails.root, 'config/initializers/roswell_key.rb')
+
+ if File.exist? key_path
+ puts "config/roswell_key.rb already exists"
+ else
+ puts "Creating config/roswell_key.rb"
+ File.open(key_path, 'w') { |file| file.write("Roswell::Application.config.roswell_key = '#{SecureRandom.hex(64)}'") }
+ end
end

0 comments on commit 5ceccc4

Please sign in to comment.