require 'securerandom' require 'stringio' def generate_token(n) SecureRandom.hex(n) end namespace :token do desc 'Generate random token' task :generate do on fetch(:token_servers) do info generate_token(fetch(:token_length)) end end desc 'Upload random token as a file on remote server' task :upload do on fetch(:token_servers) do token = generate_token(fetch(:token_length)) io = StringIO.new(token) upload! io, fetch(:token_target) end end end namespace :load do task :defaults do set :token_length, 64 set :token_target, -> { shared_path.join('.token') } set :token_roles, :app set :token_servers, -> { release_roles(fetch(:token_roles)) } end end