Module: Datadog::AppSec::Contrib::Devise::Patcher

Defined in:
lib/datadog/appsec/contrib/devise/patcher.rb

Overview

Devise patcher

Constant Summary collapse

GUARD_ONCE_PER_APP =
Hash.new do |hash, key|
  hash[key] = Datadog::Core::Utils::OnlyOnce.new
end

Class Method Summary collapse

Class Method Details

.patchObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/appsec/contrib/devise/patcher.rb', line 30

def patch
  ::ActiveSupport.on_load(:before_initialize) do |app|
    GUARD_ONCE_PER_APP[app].run do
      begin
        app.middleware.insert_after(Warden::Manager, TrackingMiddleware)
      rescue RuntimeError
        AppSec.telemetry.error('AppSec: unable to insert Devise TrackingMiddleware')
      end
    end
  end

  ::ActiveSupport.on_load(:after_initialize) do
    if ::Devise::RegistrationsController.descendants.empty?
      ::Devise::RegistrationsController.prepend(Patches::SignupTrackingPatch)
    else
      ::Devise::RegistrationsController.descendants.each do |controller|
        controller.prepend(Patches::SignupTrackingPatch)
      end
    end
  end

  ::Devise::Strategies::Authenticatable.prepend(Patches::SigninTrackingPatch)

  if ::Devise::STRATEGIES.include?(:rememberable)
    # Rememberable strategy is required in autoloaded Rememberable model
    require 'devise/models/rememberable'
    ::Devise::Strategies::Rememberable.prepend(Patches::SkipSigninTrackingPatch)
  end

  Patcher.instance_variable_set(:@patched, true)
end

.patched?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/datadog/appsec/contrib/devise/patcher.rb', line 22

def patched?
  Patcher.instance_variable_get(:@patched)
end

.target_versionObject



26
27
28
# File 'lib/datadog/appsec/contrib/devise/patcher.rb', line 26

def target_version
  Integration.version
end