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
Instance Method Summary
collapse
Methods inherited from Base
inherited, #run
#retry_on_error
#configuration_keys, #configuration_values, #configured?
Constructor Details
#initialize(*args, **kwargs) ⇒ Webhook
Returns a new instance of Webhook.
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/mihari/emitters/webhook.rb', line 58
def initialize(*args, **kwargs)
super(*args, **kwargs)
url = kwargs[:url]
= kwargs[:headers] || {}
method = kwargs[:method] || "POST"
template = kwargs[:template]
@url = Addressable::URI.parse(url)
@headers =
@method = method
@template = 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(artifacts:, rule:) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/mihari/emitters/webhook.rb', line 72
def emit(artifacts:, rule:)
return if artifacts.empty?
res = nil
payload_ = payload_as_string(artifacts: artifacts, rule: rule)
payload = JSON.parse(payload_)
client = Mihari::HTTP.new(url, headers: , payload: payload)
case method
when "GET"
res = client.get
when "POST"
res = client.post
end
res
end
|
#valid? ⇒ Boolean
92
93
94
95
96
|
# File 'lib/mihari/emitters/webhook.rb', line 92
def valid?
return false if url.nil?
%w[http https].include? url.scheme.downcase
end
|