foreman_webhooks 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9463b5bd544237c5746c80546263831614867cd514146ec019332759618e2b8
4
- data.tar.gz: ee3c69e62926cd35b9ed665b5dc09199052fb7d72556040851d571cdbd0a01de
3
+ metadata.gz: ca37dd6a9541d2de7fd5bcf755c36b04f225023917c6068d83ff0b81a50ff8a9
4
+ data.tar.gz: 8f34d322989908647a9ce14e3d6801341ed80633387d98f7fdc43c88719d92b8
5
5
  SHA512:
6
- metadata.gz: 8b3580cd4a8987e5ad9e3410bf87be6b9c84c299f0e38bcc68db14dfe97c7458f4976621f19d614d39b56380be8a7ba8cefbf7a42d358bbe91a417b05603d153
7
- data.tar.gz: ef59e908b1f0c9cad872b73bd86922064f01552a8f8287b720d040f0a9b4f44fbf066d752492637aff633752db5453b35e07cf376f7e86838d756cb4d8fd1dcb
6
+ metadata.gz: b234299b2ca09dbae3b95174d451f77609cddbaa823f137c48233684866279db4128b48d130e5d879007cd35343cdcc8e503cc9f2bb4e05e63df548253882e9b
7
+ data.tar.gz: 54546c3269a713b86a120edc2ea496862301067393bcc437d3c399585ea8215844a83ac9e340be450f312f85c125a262aa9e2bcaba306a1482973f071d1a1f3c
@@ -34,6 +34,7 @@ module Api
34
34
  param :user, String
35
35
  param :password, String
36
36
  param :http_headers, String
37
+ param :proxy_authorization, :boolean, N_('Authorize with Foreman client certificate and validate smart-proxy CA from Settings')
37
38
  end
38
39
  end
39
40
 
@@ -20,7 +20,8 @@ module ForemanWebhooks
20
20
  :ssl_ca_certs,
21
21
  :user,
22
22
  :password,
23
- :http_headers
23
+ :http_headers,
24
+ :proxy_authorization
24
25
  end
25
26
  end
26
27
  end
@@ -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: webhook.verify_ssl?,
36
- ca_string: webhook.ca_certs_store,
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 |key, value|
73
- request[key.to_s] = value.to_s
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,
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddProxyAuthorizationToWebhook < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :webhooks, :proxy_authorization, :boolean, null: false, default: false
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanWebhooks
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -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.2
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-08 00:00:00.000000000 Z
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/timogoebel/foreman_webhooks
159
+ homepage: https://github.com/theforeman/foreman_webhooks
159
160
  licenses:
160
161
  - GPL-3.0
161
162
  metadata: {}