foreman_webhooks 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/webhooks_controller.rb +1 -0
- data/app/controllers/concerns/foreman_webhooks/controller/parameters/webhook.rb +2 -1
- data/app/services/foreman_webhooks/webhook_service.rb +37 -4
- data/app/views/webhooks/_form.html.erb +1 -0
- data/db/migrate/20210322144728_add_proxy_authorization_to_webhook.rb +7 -0
- data/lib/foreman_webhooks/version.rb +1 -1
- data/lib/tasks/foreman_webhooks_tasks.rake +1 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca37dd6a9541d2de7fd5bcf755c36b04f225023917c6068d83ff0b81a50ff8a9
|
4
|
+
data.tar.gz: 8f34d322989908647a9ce14e3d6801341ed80633387d98f7fdc43c88719d92b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b234299b2ca09dbae3b95174d451f77609cddbaa823f137c48233684866279db4128b48d130e5d879007cd35343cdcc8e503cc9f2bb4e05e63df548253882e9b
|
7
|
+
data.tar.gz: 54546c3269a713b86a120edc2ea496862301067393bcc437d3c399585ea8215844a83ac9e340be450f312f85c125a262aa9e2bcaba306a1482973f071d1a1f3c
|
@@ -14,6 +14,22 @@ module ForemanWebhooks
|
|
14
14
|
@rendered_url = url
|
15
15
|
end
|
16
16
|
|
17
|
+
def foreman_ssl_auth_params
|
18
|
+
cert = Setting[:ssl_certificate]
|
19
|
+
ca_cert = Setting[:ssl_ca_file]
|
20
|
+
hostprivkey = Setting[:ssl_priv_key]
|
21
|
+
|
22
|
+
{
|
23
|
+
cert: OpenSSL::X509::Certificate.new(File.read(cert)),
|
24
|
+
key: OpenSSL::PKey::RSA.new(File.read(hostprivkey)),
|
25
|
+
ca_file: ca_cert
|
26
|
+
}
|
27
|
+
rescue StandardError => e
|
28
|
+
msg = 'Unable to read SSL proxy CA, cert or key'
|
29
|
+
Foreman::Logging.exception(msg, e)
|
30
|
+
raise Foreman::WrappedException.new(e, msg)
|
31
|
+
end
|
32
|
+
|
17
33
|
def execute
|
18
34
|
logger.info("Performing '#{webhook.name}' webhook request for event '#{event_name}'")
|
19
35
|
Foreman::Logging.blob("Payload for '#{event_name}'", payload)
|
@@ -25,6 +41,16 @@ module ForemanWebhooks
|
|
25
41
|
logger.debug("Headers: #{rendered_headers}")
|
26
42
|
end
|
27
43
|
|
44
|
+
verify = webhook.verify_ssl?
|
45
|
+
ca_string = webhook.ca_certs_store
|
46
|
+
if webhook.proxy_authorization
|
47
|
+
foreman_ssl = foreman_ssl_auth_params
|
48
|
+
verify = true
|
49
|
+
ca_file = foreman_ssl[:ca_file]
|
50
|
+
cert = foreman_ssl[:cert]
|
51
|
+
key = foreman_ssl[:key]
|
52
|
+
end
|
53
|
+
|
28
54
|
response = self.class.request(url: rendered_url,
|
29
55
|
payload: payload,
|
30
56
|
http_method: webhook.http_method,
|
@@ -32,8 +58,11 @@ module ForemanWebhooks
|
|
32
58
|
password: webhook.password,
|
33
59
|
content_type: webhook.http_content_type,
|
34
60
|
headers: headers,
|
35
|
-
ca_verify:
|
36
|
-
ca_string:
|
61
|
+
ca_verify: verify,
|
62
|
+
ca_string: ca_string,
|
63
|
+
ca_file: ca_file,
|
64
|
+
cert: cert,
|
65
|
+
key: key,
|
37
66
|
follow_redirects: true)
|
38
67
|
|
39
68
|
status = case response.code.to_i
|
@@ -61,6 +90,7 @@ module ForemanWebhooks
|
|
61
90
|
|
62
91
|
def self.request(url:, payload: '', http_method: :GET, user: nil, password: nil,
|
63
92
|
content_type: 'application/json', headers: {}, ca_string: nil,
|
93
|
+
ca_file: nil, cert: nil, key: nil,
|
64
94
|
ca_verify: false, follow_redirects: true, redirect_limit: 3)
|
65
95
|
uri = URI.parse(url)
|
66
96
|
|
@@ -69,8 +99,8 @@ module ForemanWebhooks
|
|
69
99
|
request['Content-Type'] = content_type
|
70
100
|
request['X-Request-Id'] = ::Logging.mdc['request'] || SecureRandom.uuid
|
71
101
|
request['X-Session-Id'] = ::Logging.mdc['session'] || SecureRandom.uuid
|
72
|
-
headers.each_pair do |
|
73
|
-
request[
|
102
|
+
headers.each_pair do |hkey, value|
|
103
|
+
request[hkey.to_s] = value.to_s
|
74
104
|
end
|
75
105
|
request.body = payload
|
76
106
|
|
@@ -86,6 +116,9 @@ module ForemanWebhooks
|
|
86
116
|
http.use_ssl = true
|
87
117
|
http.verify_mode = ca_verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
88
118
|
http.cert_store = ca_string if ca_string
|
119
|
+
http.ca_file = ca_file if ca_file
|
120
|
+
http.cert = cert if cert
|
121
|
+
http.key = key if key
|
89
122
|
end
|
90
123
|
http.request(request) do |response|
|
91
124
|
case response
|
@@ -28,6 +28,7 @@
|
|
28
28
|
<%= textarea_f f, :ssl_ca_certs, label: _('X509 Certification Authorities'),
|
29
29
|
size: 'col-md-8', rows: 10,
|
30
30
|
placeholder: _("Optional CAs in PEM format concatenated to verify the receiver's SSL certificate.") %>
|
31
|
+
<%= checkbox_f f, :proxy_authorization, help_inline: _("Authorize with Foreman client certificate and validate smart-proxy CA from Settings.") %>
|
31
32
|
|
32
33
|
<%= textarea_f f, :http_headers, label: _('Optional HTTP headers as JSON (ERB allowed)'),
|
33
34
|
size: 'col-md-8', rows: 6,
|
@@ -44,6 +44,4 @@ end
|
|
44
44
|
Rake::Task[:test].enhance ['test:foreman_webhooks']
|
45
45
|
|
46
46
|
load 'tasks/jenkins.rake'
|
47
|
-
if Rake::Task.task_defined?(:'jenkins:unit')
|
48
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_webhooks', 'foreman_webhooks:rubocop']
|
49
|
-
end
|
47
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_webhooks', 'foreman_webhooks:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_webhooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Goebel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- db/migrate/20200908004234_add_columns_to_webhooks.rb
|
95
95
|
- db/migrate/20201014115147_rename_ca_file_column.rb
|
96
96
|
- db/migrate/20201109135301_add_http_headers.rb
|
97
|
+
- db/migrate/20210322144728_add_proxy_authorization_to_webhook.rb
|
97
98
|
- db/seeds.d/62_shellhooks_proxy_feature.rb
|
98
99
|
- db/seeds.d/95_webhook_templates.rb
|
99
100
|
- lib/foreman_webhooks.rb
|
@@ -155,7 +156,7 @@ files:
|
|
155
156
|
- webpack/__mocks__/foremanReact/routes/common/PageLayout/PageLayout.js
|
156
157
|
- webpack/index.js
|
157
158
|
- webpack/routes_index.js
|
158
|
-
homepage: https://github.com/
|
159
|
+
homepage: https://github.com/theforeman/foreman_webhooks
|
159
160
|
licenses:
|
160
161
|
- GPL-3.0
|
161
162
|
metadata: {}
|