class Mihari::Emitters::Webhook

Public Instance Methods

emit(title:, description:, artifacts:, source:, tags:) click to toggle source
# File lib/mihari/emitters/webhook.rb, line 15
def emit(title:, description:, artifacts:, source:, tags:)
  return if artifacts.empty?

  uri = URI(Mihari.config.webhook_url)
  data = {
    title: title,
    description: description,
    artifacts: artifacts.map(&:data),
    source: source,
    tags: tags
  }

  if use_json_body?
    Net::HTTP.post(uri, data.to_json, "Content-Type" => "application/json")
  else
    Net::HTTP.post_form(uri, data)
  end
end
valid?() click to toggle source

@return [Boolean]

# File lib/mihari/emitters/webhook.rb, line 11
def valid?
  webhook_url?
end

Private Instance Methods

configuration_keys() click to toggle source
# File lib/mihari/emitters/webhook.rb, line 36
def configuration_keys
  %w[webhook_url]
end
use_json_body?() click to toggle source

Check whether to use JSON body or NOT

@return [<Type>] <description>

# File lib/mihari/emitters/webhook.rb, line 63
def use_json_body?
  @use_json_body ||= Mihari.config.webhook_use_json_body
end
webhook_url() click to toggle source

Webhook URL

@return [String, nil]

# File lib/mihari/emitters/webhook.rb, line 45
def webhook_url
  @webhook_url ||= Mihari.config.webhook_url
end
webhook_url?() click to toggle source

Check whether a webhook URL is set or not

@return [<Type>] <description>

# File lib/mihari/emitters/webhook.rb, line 54
def webhook_url?
  !webhook_url.nil?
end