Sha256: 6cec2cf8012fe54a809947cef7dc8c6fb6fedbb57461f29c58ab89c6b339c761

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Mihari
  module Emitters
    class Webhook < Base
      # @return [Boolean]
      def valid?
        webhook_url?
      end

      def emit(title:, description:, artifacts:, source:, tags:)
        return if artifacts.empty?

        headers = { 'content-type': "application/x-www-form-urlencoded" }
        headers["content-type"] = "application/json" if use_json_body?

        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
        %w[webhook_url]
      end

      #
      # Webhook URL
      #
      # @return [String, nil]
      #
      def webhook_url
        @webhook_url ||= Mihari.config.webhook_url
      end

      #
      # Check whether a webhook URL is set or not
      #
      # @return [Boolean]
      #
      def webhook_url?
        !webhook_url.nil?
      end

      #
      # Check whether to use JSON body or not
      #
      # @return [Boolean]
      #
      def use_json_body?
        @use_json_body ||= Mihari.config.webhook_use_json_body
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mihari-4.5.3 lib/mihari/emitters/webhook.rb
mihari-4.5.2 lib/mihari/emitters/webhook.rb
mihari-4.5.1 lib/mihari/emitters/webhook.rb
mihari-4.5.0 lib/mihari/emitters/webhook.rb
mihari-4.4.1 lib/mihari/emitters/webhook.rb
mihari-4.4.0 lib/mihari/emitters/webhook.rb
mihari-4.3.0 lib/mihari/emitters/webhook.rb