Class: RuboCop::Cop::SidekiqEnt::EncryptionWithoutSecretBag

Inherits:
Base
  • Object
show all
Includes:
Sidekiq::Language
Defined in:
lib/rubocop/cop/sidekiq_ent/encryption_without_secret_bag.rb

Overview

Checks that encrypted jobs have meaningful arguments to encrypt.

Sidekiq Enterprise encryption only encrypts the last argument. If the job only has a single ID-like argument, encryption may not provide much value.

Examples:

# questionable - only ID argument
class MyJob
  include Sidekiq::Job
  sidekiq_options encrypt: true

  def perform(user_id)
  end
end

# good - secret data in last argument
class MyJob
  include Sidekiq::Job
  sidekiq_options encrypt: true

  def perform(user_id, secret_data)
  end
end

Constant Summary collapse

MSG =
'Encrypted job has only one argument. ' \
'Consider if encryption is necessary or add a secret bag argument.'

Instance Method Summary collapse

Methods included from Sidekiq::Language

#active_job_class?, #perform_call?, #sidekiq_include?, #sidekiq_options_call?

Methods inherited from Base

#limiter_creation?, #unique_for_option?, #unique_until_option?

Instance Method Details

#encryption_enabled?(node) ⇒ Object



38
39
40
# File 'lib/rubocop/cop/sidekiq_ent/encryption_without_secret_bag.rb', line 38

def_node_matcher :encryption_enabled?, "(send nil? :sidekiq_options (hash <(pair (sym :encrypt) {(true) (sym :true)}) ...>))\n"

#on_send(node) ⇒ Object Also known as: on_csend



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubocop/cop/sidekiq_ent/encryption_without_secret_bag.rb', line 42

def on_send(node)
  return unless encryption_enabled?(node)

  class_node = node.each_ancestor(:class).first
  return unless class_node

  perform_method = find_perform_method(class_node)
  return unless perform_method

  add_offense(perform_method.loc.name) if single_id_like_argument?(perform_method)
end