Class: Mihari::Emitters::Webhook
- Inherits:
-
Base
- Object
- Base
- Mihari::Emitters::Webhook
show all
- Defined in:
- lib/mihari/emitters/webhook.rb
Constant Summary
Mixins::Retriable::DEFAULT_ON
Instance Attribute Summary collapse
Attributes inherited from Base
#artifacts, #rule
Instance Method Summary
collapse
Methods inherited from Base
inherited, #run
#retry_on_error
#configuration_keys, #configuration_keys?, #configuration_values, #configured?
Constructor Details
#initialize(artifacts:, rule:, **options) ⇒ Webhook
Returns a new instance of Webhook.
63
64
65
66
67
68
69
70
|
# File 'lib/mihari/emitters/webhook.rb', line 63
def initialize(artifacts:, rule:, **options)
super(artifacts: artifacts, rule: rule, **options)
@url = Addressable::URI.parse(options[:url])
@headers = options[:headers] || {}
@method = options[:method] || "POST"
@template = options[:template]
end
|
Instance Attribute Details
50
51
52
|
# File 'lib/mihari/emitters/webhook.rb', line 50
def
@headers
end
|
#method ⇒ String
53
54
55
|
# File 'lib/mihari/emitters/webhook.rb', line 53
def method
@method
end
|
#template ⇒ String?
56
57
58
|
# File 'lib/mihari/emitters/webhook.rb', line 56
def template
@template
end
|
#url ⇒ Addressable::URI?
47
48
49
|
# File 'lib/mihari/emitters/webhook.rb', line 47
def url
@url
end
|
Instance Method Details
#emit ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/mihari/emitters/webhook.rb', line 72
def emit
return if artifacts.empty?
client = Mihari::HTTP.new(url, headers: )
res = nil
case method
when "GET"
res = client.get
when "POST"
res = client.post(json: payload)
end
res
end
|
#valid? ⇒ Boolean
88
89
90
91
92
|
# File 'lib/mihari/emitters/webhook.rb', line 88
def valid?
return false if url.nil?
%w[http https].include? url.scheme.downcase
end
|