This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
evoresa/lib/tasks/evoresa.rake

26 lines
715 B
Ruby

env_file = File.expand_path('../../../config/environment', __FILE__)
require env_file
namespace :evoresa do
desc "Show the current admin key"
task :show_key do
puts "Current key is: " + ADMIN_SECRET_KEY
puts "Change with rake evoresa:set_key [KEY=<key>]"
end
desc "Set the current admin key"
task :set_key do
require 'digest/md5'
file = env_file + '.rb'
config = File.read(file)
random_key = Digest::MD5.hexdigest(Array.new(32) { rand(128).chr }.join)
new_key = ENV['KEY'] || random_key
config.sub!(/(ADMIN_SECRET_KEY) = '[^']+'/, '\1 = \'' + new_key + "'")
File.open(file, 'w+') {|f| f.write(config) }
puts "The new key is: " + new_key
end
end