class Sidekiq::EncryptedArgs::ClientMiddleware

Sidekiq client middleware for encrypting arguments on jobs for workers with `encrypted_args` set in the `sidekiq_options`.

Public Instance Methods

call(worker_class, job, queue, redis_pool = nil) { || ... } click to toggle source

Encrypt specified arguments before they're sent off to the queue

# File lib/sidekiq/encrypted_args/client_middleware.rb, line 9
def call(worker_class, job, queue, redis_pool = nil)
  if job.include?("encrypted_args")
    encrypted_args = EncryptedArgs.encrypted_args_option(worker_class, job)
    encrypt_job_arguments!(job, encrypted_args)
  end

  yield
end

Private Instance Methods

encrypt_job_arguments!(job, encrypted_args) click to toggle source

Encrypt the arguments on job

Additionally, set `job` to the canonicalized version (i.e. `Array<Integer>`)

@param [Hash] @param [Array<Integer>] encrypted_args array of indexes in job to encrypt @return [void]

# File lib/sidekiq/encrypted_args/client_middleware.rb, line 27
def encrypt_job_arguments!(job, encrypted_args)
  if encrypted_args
    job_args = job["args"]
    job_args.each_with_index do |value, position|
      if encrypted_args.include?(position)
        job_args[position] = EncryptedArgs.encrypt(value)
      end
    end
    job["encrypted_args"] = encrypted_args
  else
    job.delete("encrypted_args")
  end
end