Permalink
Browse files

Encrypted delayed job

  • Loading branch information...
1 parent b303622 commit fb252e35b2a6706311e8afdbb4b4aea5f64bb756 @latentflip committed Sep 9, 2011
Showing with 17 additions and 2 deletions.
  1. +1 −0 delayed_job.gemspec
  2. +16 −2 lib/delayed/backend/base.rb
View
@@ -18,6 +18,7 @@ This gem is collectiveidea's fork (http://github.com/collectiveidea/delayed_job)
s.test_files = Dir.glob('spec/**/*')
s.add_runtime_dependency 'daemons'
+ s.add_runtime_dependency 'encryptor'
s.add_runtime_dependency 'activesupport'
s.add_development_dependency 'activesupport', '~> 3.0'
@@ -1,6 +1,10 @@
+require 'encryptor'
+require 'base64'
+
module Delayed
module Backend
module Base
+ SECRET_KEY = "A SECRET KEY"
def self.included(base)
base.extend ClassMethods
end
@@ -77,11 +81,11 @@ def name
def payload_object=(object)
@payload_object = object
- self.handler = object.to_yaml
+ self.handler = encrypt(object.to_yaml)
end
def payload_object
- @payload_object ||= YAML.load(self.handler)
+ @payload_object ||= YAML.load(decrypt(self.handler))
rescue TypeError, LoadError, NameError, ArgumentError => e
raise DeserializationError,
"Job failed to load: #{e.message}. Handler: #{handler.inspect}"
@@ -133,6 +137,16 @@ def fail!
protected
+ def key
+ @key ||= Digest::SHA256.hexdigest(SECRET_KEY)
+ end
+ def encrypt(payload)
+ Base64.encode64(Encryptor.encrypt(string), :key => key)
+ end
+ def decrypt(string)
+ Encryptor.decrypt(Base64.decode64(string), :key => key)
+ end
+
def set_default_run_at
self.run_at ||= self.class.db_time_now
end

0 comments on commit fb252e3

Please sign in to comment.