Sha256: a2644c890844e8a84207d96e6dde4752fb81e0437a8c63566842d2336e859b4f

Contents?: true

Size: 1.37 KB

Versions: 30

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Datadog
  module AppSec
    module Contrib
      module Devise
        # Class to extract event information from the resource
        class Event
          UUID_REGEX = /^\h{8}-\h{4}-\h{4}-\h{4}-\h{12}$/.freeze

          SAFE_MODE = 'safe'
          EXTENDED_MODE = 'extended'

          attr_reader :user_id

          def initialize(resource, mode)
            @resource = resource
            @mode = mode
            @user_id = nil
            @email = nil
            @username = nil

            extract if @resource
          end

          def to_h
            return @event if defined?(@event)

            @event = {}
            @event[:email] = @email if @email
            @event[:username] = @username if @username
            @event
          end

          private

          def extract
            @user_id = @resource.id

            case @mode
            when EXTENDED_MODE
              @email = @resource.email
              @username = @resource.username
            when SAFE_MODE
              @user_id = nil unless @user_id && @user_id.to_s =~ UUID_REGEX
            else
              Datadog.logger.warn(
                "Invalid automated user evenst mode: `#{@mode}`. "\
                              'Supported modes are: `safe` and `extended`.'
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
datadog-2.9.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.8.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.7.1 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.7.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.6.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.5.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.4.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.3.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.2.0 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.23.3 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.23.2 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.1.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.0.0 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.23.1 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.0.0.beta2 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.22.0 lib/datadog/appsec/contrib/devise/event.rb
datadog-2.0.0.beta1 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.21.1 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.21.0 lib/datadog/appsec/contrib/devise/event.rb
ddtrace-1.20.0 lib/datadog/appsec/contrib/devise/event.rb