Sha256: e92f1ec313f50316415ce2552ee2e9c1ed8aca47f92799c364bf2a541d41b327

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

# typed: true

require_relative 'configuration/settings'

module Datadog
  module AppSec
    # Configuration for AppSec
    # TODO: this is a trivial implementation, check with shareable code with
    # tracer and other products
    module Configuration
      def self.included(base)
        base.extend(ClassMethods)
      end

      # Configuration DSL implementation
      class DSL
        Instrument = Struct.new(:name, :options)
        def initialize
          @instruments = []
          @options = {}
        end

        attr_reader :instruments, :options

        def instrument(name, options = {})
          @instruments << Instrument.new(name, options)
        end

        def enabled=(value)
          options[:enabled] = value
        end

        def ruleset=(value)
          options[:ruleset] = value
        end

        def ip_denylist=(value)
          options[:ip_denylist] = value
        end

        # in microseconds
        def waf_timeout=(value)
          options[:waf_timeout] = value
        end

        def waf_debug=(value)
          options[:waf_debug] = value
        end

        def trace_rate_limit=(value)
          options[:trace_rate_limit] = value
        end

        def obfuscator_key_regex=(value)
          options[:obfuscator_key_regex] = value
        end

        def obfuscator_value_regex=(value)
          options[:obfuscator_value_regex] = value
        end

        def [](key)
          found = @instruments.find { |e| e.name == key }

          found.options if found
        end
      end

      # class-level methods for Configuration
      module ClassMethods
        def configure
          dsl = DSL.new
          yield dsl
          settings.merge(dsl)
          settings
        end

        def settings
          @settings ||= Settings.new
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-1.8.0 lib/datadog/appsec/configuration.rb
ddtrace-1.7.0 lib/datadog/appsec/configuration.rb