Sha256: c1b0d2e665704f011cbee53d29da53220e6b799a410c432ec81f49dcf7ec2b60

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

# typed: ignore

require 'pathname'

module Datadog
  module AppSec
    # Helper methods to get vendored assets
    module Assets
      module_function

      def waf_rules(kind = :recommended)
        read("waf_rules/#{kind}.json")
      end

      def blocked(format: :html)
        (@blocked ||= {})[format] ||= read("blocked.#{format}")
      end

      def path
        Pathname.new(dir).join('assets')
      end

      def filepath(filename)
        path.join(filename)
      end

      def read(filename, mode = 'rb')
        File.open(filepath(filename), mode) { |f| f.read || raise('Unexpected nil IO object') }
      end

      def dir
        # Happens only if this file is evaluated standalone, which should not happen
        # Necessary to make type-checker happy with a non-nilable return value
        __dir__ || raise('Unexpected file eval')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ddtrace-1.9.0 lib/datadog/appsec/assets.rb