lib/mihari/emitters/webhook.rb in mihari-5.4.7 vs lib/mihari/emitters/webhook.rb in mihari-5.4.8

- old
+ new

@@ -70,37 +70,37 @@ end def emit return if artifacts.empty? - client = Mihari::HTTP.new(url, headers: headers) - - res = nil + # returns body to prevent Parallel issue (Parallel fails to handle HTTP:Response object) case method when "GET" - res = client.get + http.get(url).body.to_s when "POST" - res = client.post(json: payload) + http.post(url, json: json).body.to_s end - - res end def valid? return false if url.nil? %w[http https].include? url.scheme.downcase end private + def http + HTTP::Factory.build headers: headers + end + # - # Convert payload into string + # Render template # # @return [String] # - def payload_as_string + def rendered_template [].tap do |out| options = {} options[:template] = File.read(template) unless template.nil? payload_template = PayloadTemplate.new( @@ -113,11 +113,11 @@ end # # @return [Hash] # - def payload - JSON.parse payload_as_string + def json + JSON.parse rendered_template end end end end