puppet_webhook 1.4.0 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 906dfa13bf22e727fd153eff673db49f0122e7fa5417ef213177f9bb5e210abc
4
- data.tar.gz: db34a880e6a705920606229f35f5f9e48eeec57b64f583335ac3253d1041f042
2
+ SHA1:
3
+ metadata.gz: 653632cd922c85c60f40066bea79580609626cc1
4
+ data.tar.gz: d2a72dae7db871ac46c8d1353e6ae43aaab761c5
5
5
  SHA512:
6
- metadata.gz: bd6610589cdd23e673ae70ad39cdea36c042bf64dc73c785bebfdc550b792be616f431a451f425c7a21e6acae7ebb2b6c6c9847d251dec6d7d7266a6922d6b17
7
- data.tar.gz: 79860c041ffe00bbca6b39e2a025a3818805b8fb960143e7a262dfe665feeaf2c0d0cfad42384f25c3111f0f9ea3e3202137b157bd3ce81ea0f2a6b241165b95
6
+ metadata.gz: d0214e6440b6ccb26e0bff3f28f0756f512e0f7235618a50d05e6859fe42095f8b42359ee358ec4cc1d39174ea2661dc9d8504a9b47b6f88fe80a20317dc02a5
7
+ data.tar.gz: c198a88fa0849cb8588e70b81d0c07be6d85955954a6a150ed5e972440e483e3f1ea1abdfa51c009918c7f8698fbb0dca4a46d2bc0f284193bcfcf5f26496c97
data/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
4
4
  Each new release typically also includes the latest modulesync defaults.
5
5
  These should not affect the functionality of the module.
6
6
 
7
+ ## [v1.5.0](https://github.com/voxpupuli/puppet_webhook/tree/v1.5.0) (2018-11-01)
8
+ [Full Changelog](https://github.com/voxpupuli/puppet_webhook/compare/v1.4.0...v1.5.0)
9
+
10
+ **Implemented enhancements:**
11
+
12
+ - Add tests to validate posts to the module route [\#37](https://github.com/voxpupuli/puppet_webhook/pull/37) ([dhollinger](https://github.com/dhollinger))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - puppet\_webhook is not compatible with Ruby \< 2.2.2 [\#56](https://github.com/voxpupuli/puppet_webhook/issues/56)
17
+
18
+ **Merged pull requests:**
19
+
20
+ - Bitbucket Server \(stash\) detection / JSON updates [\#61](https://github.com/voxpupuli/puppet_webhook/pull/61) ([ChetHosey](https://github.com/ChetHosey))
21
+ - Stray payload reference [\#60](https://github.com/voxpupuli/puppet_webhook/pull/60) ([ChetHosey](https://github.com/ChetHosey))
22
+ - Changed minimum versions to Puppet 5/Ruby 2.2 [\#58](https://github.com/voxpupuli/puppet_webhook/pull/58) ([ChetHosey](https://github.com/ChetHosey))
23
+ - Add tests for the DataParsers helper module [\#55](https://github.com/voxpupuli/puppet_webhook/pull/55) ([dhollinger](https://github.com/dhollinger))
24
+
7
25
  ## [v1.4.0](https://github.com/voxpupuli/puppet_webhook/tree/v1.4.0) (2018-05-02)
8
26
  [Full Changelog](https://github.com/voxpupuli/puppet_webhook/compare/v1.3.0...v1.4.0)
9
27
 
@@ -98,4 +116,4 @@ These should not affect the functionality of the module.
98
116
 
99
117
 
100
118
 
101
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
119
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/README.md CHANGED
@@ -19,8 +19,8 @@ puppet_webhook is a Sinatra-based application receiving REST-based calls to trig
19
19
 
20
20
  ## Prerequisites
21
21
 
22
- * Ruby 2.1.9 or greater
23
- * Puppet 4.7.1 or greater
22
+ * Ruby 2.2.0 or greater
23
+ * Puppet 5.0.0 or greater
24
24
  * r10k gem
25
25
  * *Optional*: MCollective and MCollective-r10k (Provides one form of multi-master syncronization)
26
26
  * Currently Mcollective-r10k is only available from [puppet-r10k](https://github.com/voxpupuli/puppet-r10k)
@@ -7,16 +7,12 @@ module DataParsers # rubocop:disable Style/Documentation
7
7
  sanitized
8
8
  end
9
9
 
10
- def normalize(str)
11
- settings.allow_uppercase ? str : str.downcase
10
+ def normalize(allow_upper, str)
11
+ allow_upper ? str : str.downcase
12
12
  end
13
13
 
14
- def verify_signature(payload_body)
15
- signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), settings.github_secret, payload_body)
14
+ def verify_signature(secret, payload_body)
15
+ signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret, payload_body)
16
16
  throw(:halt, [500, "Signatures didn't match!\n"]) unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE'])
17
17
  end
18
-
19
- def payload
20
- env['parsed_body']
21
- end
22
18
  end
data/lib/helpers/tasks.rb CHANGED
@@ -67,6 +67,7 @@ module Tasks # rubocop:disable Style/Documentation
67
67
 
68
68
  def notification(message)
69
69
  return unless settings.chatops || settings.slack_webhook
70
+
70
71
  slack_settings if settings.chatops == false && settings.slack_webhook != false
71
72
  PuppetWebhook::Chatops.new(settings.chatops_service,
72
73
  settings.chatops_url,
@@ -100,8 +101,8 @@ module Tasks # rubocop:disable Style/Documentation
100
101
  def slack_proxy
101
102
  uri = URI(settings.slack_proxy_url)
102
103
  http_options = {
103
- proxy_address: uri.hostname,
104
- proxy_port: uri.port,
104
+ proxy_address: uri.hostname,
105
+ proxy_port: uri.port,
105
106
  proxy_from_env: false
106
107
  }
107
108
  http_options
@@ -110,6 +111,7 @@ module Tasks # rubocop:disable Style/Documentation
110
111
  def types?
111
112
  return false unless settings.respond_to?(:generate_types=)
112
113
  return false if settings.generate_types.nil?
114
+
113
115
  settings.generate_types
114
116
  end
115
117
 
@@ -10,8 +10,8 @@ module Sinatra
10
10
  @data = parse_data(body)
11
11
  @vcs = detect_vcs
12
12
  {
13
- branch: branch,
14
- deleted: deleted?,
13
+ branch: branch,
14
+ deleted: deleted?,
15
15
  module_name: repo_name.sub(%r{^.*-}, ''),
16
16
  repo_name: repo_name,
17
17
  repo_user: repo_user
@@ -24,6 +24,7 @@ module Sinatra
24
24
  return 'stash' if stash_webhook?
25
25
  return 'bitbucket' if bitbucket_webhook?
26
26
  return 'tfs' if tfs_webhook?
27
+
27
28
  raise StandardError, 'payload not recognised'
28
29
  end
29
30
 
@@ -39,19 +40,20 @@ module Sinatra
39
40
 
40
41
  # stash/bitbucket server
41
42
  def stash_webhook?
42
- # https://confluence.atlassian.com/bitbucketserver/post-service-webhook-for-bitbucket-server-776640367.html
43
- env.key?('HTTP_X_ATLASSIAN_TOKEN')
43
+ # https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html
44
+ env.key?('HTTP_X_EVENT_KEY') && env.key?('HTTP_X_REQUEST_ID')
44
45
  end
45
46
 
46
47
  def bitbucket_webhook?
47
48
  # https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html
48
- env.key?('HTTP_X_EVENT_KEY')
49
+ env.key?('HTTP_X_EVENT_KEY') && env.key?('HTTP_X_HOOK_UUID')
49
50
  end
50
51
 
51
52
  def tfs_webhook?
52
53
  # https://docs.microsoft.com/en-us/vsts/service-hooks/services/webhooks
53
54
  return false unless @data.key? 'resource'
54
55
  return false unless @data.key? 'eventType'
56
+
55
57
  true
56
58
  end
57
59
 
@@ -66,9 +68,10 @@ module Sinatra
66
68
  when 'gitlab'
67
69
  @data['ref'].sub('refs/heads/', '')
68
70
  when 'stash'
69
- @data['refChanges'][0]['refId'].sub('refs/heads/', '')
71
+ @data['changes'][0]['refId'].sub('refs/heads/', '')
70
72
  when 'bitbucket'
71
73
  return @data['push']['changes'][0]['new']['name'] unless deleted?
74
+
72
75
  @data['push']['changes'][0]['old']['name']
73
76
  when 'tfs'
74
77
  @data['resource']['refUpdates'][0]['name'].sub('refs/heads/', '')
@@ -82,7 +85,7 @@ module Sinatra
82
85
  when 'gitlab'
83
86
  @data['after'] == '0000000000000000000000000000000000000000'
84
87
  when 'stash'
85
- @data['refChanges'][0]['type'] == 'DELETE'
88
+ @data['changes'][0]['type'] == 'DELETE'
86
89
  when 'bitbucket'
87
90
  @data['push']['changes'][0]['closed']
88
91
  when 'tfs'
@@ -17,7 +17,7 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
17
17
  'application/json' => Sinatra::Parsers::WebhookJsonParser.new,
18
18
  'application/x-www-form-urlencoded' => Sinatra::Parsers::WebhookWWWFormURLEncodedParser.new
19
19
  },
20
- handlers: {
20
+ handlers: {
21
21
  'application/json' => proc { |e, type|
22
22
  [400, { 'Content-Type' => type }, [{ error: e.to_s }.to_json]]
23
23
  }
@@ -52,6 +52,8 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
52
52
  set :command_prefix, 'umask 0022;' unless settings.respond_to? :command_prefix=
53
53
  set :github_secret, nil unless settings.respond_to? :github_secret=
54
54
  set :repository_events, nil unless settings.respond_to? :respository_events=
55
+ set :user, 'puppet' unless settings.respond_to? :user=
56
+ set :pass, 'puppet' unless settings.respond_to? :pass=
55
57
 
56
58
  # Deprecated Settings
57
59
  set :slack_webhook, false unless settings.respond_to? :slack_webhook=
data/lib/routes/module.rb CHANGED
@@ -14,9 +14,9 @@ module Sinatra
14
14
 
15
15
  # TODO: Move these two lines of code into the parser
16
16
  decoded = request.body.read
17
- verify_signature(decoded) if verify_signature?
17
+ verify_signature(settings.github_secret, decoded) if verify_signature?
18
18
 
19
- module_name = payload[:module_name]
19
+ module_name = env['parsed_body'][:module_name]
20
20
 
21
21
  module_name = sanitize_input(module_name)
22
22
  LOGGER.info("Deploying module #{module_name}")
@@ -6,7 +6,6 @@ module Sinatra
6
6
  module Payload
7
7
  def self.registered(puppet_webhook)
8
8
  puppet_webhook.post '/payload' do # rubocop:disable Metrics/BlockLength
9
- LOGGER.info "parsed payload contained: #{payload}"
10
9
  protected! if settings.protected
11
10
  request.body.rewind # in case someone already read it
12
11
 
@@ -19,18 +18,18 @@ module Sinatra
19
18
  else
20
19
  request.body.read
21
20
  end
22
- verify_signature(decoded) if verify_signature?
21
+ verify_signature(settings.github_secret, decoded) if verify_signature?
23
22
  data = JSON.parse(decoded, quirks_mode: true)
24
23
 
25
24
  # Iterate the data structure to determine what's should be deployed
26
- branch = payload[:branch]
25
+ branch = env['parsed_body'][:branch]
27
26
 
28
27
  # If prefix is enabled in our config file, determine what the prefix should be
29
28
  prefix = case settings.prefix
30
29
  when :repo
31
- payload[:repo_name]
30
+ env['parsed_body'][:repo_name]
32
31
  when :user
33
- payload[:repo_user]
32
+ env['parsed_body'][:repo_user]
34
33
  when :command, TrueClass
35
34
  run_prefix_command(data.to_json)
36
35
  when String
@@ -39,7 +38,7 @@ module Sinatra
39
38
 
40
39
  # When a branch is being deleted, a deploy against it will result in a failure, as it no longer exists.
41
40
  # Instead, deploy the default branch, which will purge deleted branches per the user's configuration
42
- deleted = payload[:deleted]
41
+ deleted = env['parsed_body'][:deleted]
43
42
 
44
43
  branch = if deleted
45
44
  settings.default_branch
@@ -51,9 +50,9 @@ module Sinatra
51
50
  # The best we can do is just deploy all environments by passing nil to
52
51
  # deploy() if we don't know the correct branch.
53
52
  env = if prefix.nil? || prefix.empty? || branch.nil? || branch.empty?
54
- normalize(branch)
53
+ normalize(settings.allow_uppercase, branch)
55
54
  else
56
- normalize("#{prefix}_#{branch}")
55
+ normalize(settings.allow_uppercase, "#{prefix}_#{branch}")
57
56
  end
58
57
 
59
58
  if ignore_env?(env)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_webhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rack-test
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -274,7 +288,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
274
288
  requirements:
275
289
  - - ">="
276
290
  - !ruby/object:Gem::Version
277
- version: 2.1.9
291
+ version: 2.2.0
278
292
  required_rubygems_version: !ruby/object:Gem::Requirement
279
293
  requirements:
280
294
  - - ">="
@@ -282,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
296
  version: '0'
283
297
  requirements: []
284
298
  rubyforge_project:
285
- rubygems_version: 2.7.6
299
+ rubygems_version: 2.6.14
286
300
  signing_key:
287
301
  specification_version: 4
288
302
  summary: Sinatra Webhook Server for Puppet/R10K