Sha256: 41aacb36ba50fdbb40c0cfdad70442e68b505fcd04cf9f13a6b27ff75eb636f3

Contents?: true

Size: 1.18 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
mihari-4.12.0 lib/mihari/emitters/webhook.rb
mihari-4.11.0 lib/mihari/emitters/webhook.rb
mihari-4.10.0 lib/mihari/emitters/webhook.rb
mihari-4.9.0 lib/mihari/emitters/webhook.rb
mihari-4.8.0 lib/mihari/emitters/webhook.rb
mihari-4.7.4 lib/mihari/emitters/webhook.rb
mihari-4.7.3 lib/mihari/emitters/webhook.rb
mihari-4.7.2 lib/mihari/emitters/webhook.rb
mihari-4.7.1 lib/mihari/emitters/webhook.rb
mihari-4.7.0 lib/mihari/emitters/webhook.rb
mihari-4.6.1 lib/mihari/emitters/webhook.rb
mihari-4.6.0 lib/mihari/emitters/webhook.rb