Sha256: 42ccdcbfb942eddd8e76cc80840fcbaceed26cc321e7f69b72e23a8e920cd37c

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative '../patcher'
require_relative 'patcher/authenticatable_patch'
require_relative 'patcher/rememberable_patch'
require_relative 'patcher/registration_controller_patch'

module Datadog
  module AppSec
    module Contrib
      module Devise
        # Patcher for AppSec on Devise
        module Patcher
          include Datadog::AppSec::Contrib::Patcher

          module_function

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

          def target_version
            Integration.version
          end

          def patch
            patch_authenticatable_strategy
            patch_rememberable_strategy
            patch_registration_controller

            Patcher.instance_variable_set(:@patched, true)
          end

          def patch_authenticatable_strategy
            ::Devise::Strategies::Authenticatable.prepend(AuthenticatablePatch)
          end

          def patch_rememberable_strategy
            return unless ::Devise::STRATEGIES.include?(:rememberable)

            # Rememberable strategy is required in autoloaded Rememberable model
            ::Devise::Models::Rememberable # rubocop:disable Lint/Void
            ::Devise::Strategies::Rememberable.prepend(RememberablePatch)
          end

          def patch_registration_controller
            ::ActiveSupport.on_load(:after_initialize) do
              ::Devise::RegistrationsController.prepend(RegistrationControllerPatch)
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datadog-2.9.0 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.8.0 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.7.1 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.7.0 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.6.0 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.5.0 lib/datadog/appsec/contrib/devise/patcher.rb
datadog-2.4.0 lib/datadog/appsec/contrib/devise/patcher.rb