lib/mihari/emitters/webhook.rb in mihari-4.2.0 vs lib/mihari/emitters/webhook.rb in mihari-4.3.0
- old
+ new
@@ -9,24 +9,15 @@
end
def emit(title:, description:, artifacts:, source:, tags:)
return if artifacts.empty?
- uri = Addressable::URI.parse(Mihari.config.webhook_url)
- data = {
- title: title,
- description: description,
- artifacts: artifacts.map(&:data),
- source: source,
- tags: tags
- }
+ headers = { 'content-type': "application/x-www-form-urlencoded" }
+ headers["content-type"] = "application/json" if use_json_body?
- if use_json_body?
- Net::HTTP.post(uri, data.to_json, "Content-Type" => "application/json")
- else
- Net::HTTP.post_form(uri, data)
- end
+ emitter = Emitters::HTTP.new(uri: Mihari.config.webhook_url)
+ emitter.emit(title: title, description: description, artifacts: artifacts, source: source, tags: tags)
end
private
def configuration_keys
@@ -43,19 +34,19 @@
end
#
# Check whether a webhook URL is set or not
#
- # @return [<Type>] <description>
+ # @return [Boolean]
#
def webhook_url?
!webhook_url.nil?
end
#
- # Check whether to use JSON body or NOT
+ # Check whether to use JSON body or not
#
- # @return [<Type>] <description>
+ # @return [Boolean]
#
def use_json_body?
@use_json_body ||= Mihari.config.webhook_use_json_body
end
end