lib/sensu/api/http_handler.rb
def read_data(rules={})
        begin
          data = Sensu::JSON.load(@http_content)
          valid = data.is_a?(Hash) && rules.all? do |key, rule|
            value = data[key]
            (Array(rule[:type]).any? {|type| value.is_a?(type)} ||
              (rule[:nil_ok] && value.nil?)) && (value.nil? || rule[:regex].nil?) ||
              (rule[:regex] && (value =~ rule[:regex]) == 0)
          end
          if valid
            yield(data)
          else
            bad_request!
          end
        rescue Sensu::JSON::ParseError
          bad_request!
        end
      end
# Read JSON data from the HTTP request content and validate it
# with the provided rules. If the HTTP request content does not
# contain valid JSON or it does not pass validation, this method
# returns a `400` (Bad Request) HTTP response.
#
# @param rules [Hash] containing the validation rules.
# @yield [Object] the callback/block called with the data after successfully
#   parsing and validating the the HTTP request content.
Read JSON data from the HTTP request content and validate it
with the provided rules. If the HTTP request content does not
contain valid JSON or it does not pass validation, this method
returns a `400` (Bad Request) HTTP response.
Read JSON data from the HTTP request content and validate it with the provided rules . If the HTTP request content does not contain valid JSON or it does not pass validation this method returns a ` 400 ` ( Bad Request ) HTTP response .
def read_data(rules={})
        begin
          data = Sensu::JSON.load(@http_content)
          valid = data.is_a?(Hash) && rules.all? do |key, rule|
            value = data[key]
            (Array(rule[:type]).any? {|type| value.is_a?(type)} ||
              (rule[:nil_ok] && value.nil?)) && (value.nil? || rule[:regex].nil?) ||
              (rule[:regex] && (value =~ rule[:regex]) == 0)
          end
          if valid
            yield(data)
          else
            bad_request!
          end
        rescue Sensu::JSON::ParseError
          bad_request!
        end
      end
def read_data ( rules = { } ) begin data = Sensu :: JSON . load ( @http_content ) valid = data . is_a? ( Hash ) && rules . all? do | key , rule | value = data [ key ] ( Array ( rule [ :type ] ) . any? { | type | value . is_a? ( type ) } || ( rule [ :nil_ok ] && value . nil? ) ) && ( value . nil? || rule [ :regex ] . nil? ) || ( rule [ :regex ] && ( value =~ rule [ :regex ] ) == 0 ) end if valid yield ( data ) else bad_request! end rescue Sensu :: JSON :: ParseError bad_request! end end
Read JSON data from the HTTP request content and validate it
with the provided rules.
Read JSON data from the HTTP request content and validate it with the provided rules .
rules
containing the validation rules.
containing the validation rules .
]
the callback/block called with the data after successfully parsing and validating the the HTTP request content.
the callback / block called with the data after successfully parsing and validating the the HTTP request content .