Sha256: 5cb91dba21e4fcccfd419705d0d5dcbf996ab4fe7c79e3f5594222bf093e8111

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module ActionHook
  module Core

    class Configuration

      DEFAULT_OPEN_TIMEOUT_IN_SECONDS = 5
      DEFAULT_READ_TIMEOUT_IN_SECONDS = 15
      DEFAULT_HASH_HEADER_NAME = 'SHA256-FINGERPRINT'
      attr_accessor :open_timeout, :read_timeout, :hash_header_name,
        :allow_private_ips

      attr_writer :blocked_custom_ip_ranges

      def initialize(open_timeout: DEFAULT_OPEN_TIMEOUT_IN_SECONDS,
        read_timeout: DEFAULT_READ_TIMEOUT_IN_SECONDS,
        hash_header_name: DEFAULT_HASH_HEADER_NAME,
        allow_private_ips: false,
        blocked_custom_ip_ranges: []
      )
        @open_timeout = open_timeout
        @read_timeout = read_timeout
        @hash_header_name = hash_header_name
        @allow_private_ips = allow_private_ips
        @blocked_custom_ip_ranges = blocked_custom_ip_ranges || []
      end

      def net_http_options
        {
          open_timeout: @open_timeout,
          read_timeout: @read_timeout
        }
      end

      def blocked_custom_ip_ranges
        @memoized_blocked_custom_ip_ranges ||= @blocked_custom_ip_ranges&.map{|ip| IPAddr.new(ip)} || []
      end

      def allow_all?
        allow_private_ips && blocked_custom_ip_ranges.empty?
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
actionhook-1.0.1 lib/actionhook/core/configuration.rb
actionhook-1.0.0 lib/actionhook/core/configuration.rb