pushyd 0.21.0 → 0.22.0

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
  SHA1:
3
- metadata.gz: ba39e2325a7509e30286b4f11a82947c057cf292
4
- data.tar.gz: da884f2520bc928813fe9f040d4f655ece0d0837
3
+ metadata.gz: fd36ea01bb992654b0c3a791e49baa77b0e66140
4
+ data.tar.gz: 1ee9dd52f747456503f799bd98cee05f5f90e66a
5
5
  SHA512:
6
- metadata.gz: d1df640a0cf5b6a768f0af39d7e27f4ade48289f4a2ca3549e68744ebc3b05f7478d959d55b69aef56b7c8cda9fb80c3ef4b6d3bb796563c5d86150dc1027428
7
- data.tar.gz: 01db0c676f7d2a5f6c7f4299a1f6a2551fdf65603b24b8c1f8e11daeb110e955b1c98cba91d1c8ac949cafa25810c85b5faea7ed33de6986bb462e1edd390739
6
+ metadata.gz: fcd38ca1879c702300a43ff3c64568bb738419111b8fe10f4b4307dea965853bfd382616b2384f7730f1409e10694813d5242f851ed8a24cbf2aa266b9c71f11
7
+ data.tar.gz: e0924559663f6d9accde4e22cf7f09c0fedcc801b9b55546651c6e235d042325fc87791700c0546e37ce3d1d4f08736c462cb6405663cc7a5b938c6e44693a43
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pushyd (0.21.0)
4
+ pushyd (0.22.0)
5
5
  api-auth
6
6
  bmc-daemon-lib (~> 0.4.3)
7
7
  bunny (~> 2.3)
@@ -36,7 +36,7 @@ GEM
36
36
  http-cookie (~> 1.0)
37
37
  http-form_data (~> 1.0.1)
38
38
  http_parser.rb (~> 0.6.0)
39
- http-cookie (1.0.2)
39
+ http-cookie (1.0.3)
40
40
  domain_name (~> 0.5)
41
41
  http-form_data (1.0.1)
42
42
  http_parser.rb (0.6.0)
@@ -44,7 +44,7 @@ GEM
44
44
  mime-types (2.99.3)
45
45
  multi_json (1.12.1)
46
46
  netrc (0.11.0)
47
- newrelic_rpm (3.16.2.321)
47
+ newrelic_rpm (3.16.3.323)
48
48
  parser (2.3.1.4)
49
49
  ast (~> 2.2)
50
50
  powerpack (0.1.1)
@@ -54,13 +54,13 @@ GEM
54
54
  http-cookie (>= 1.0.2, < 2.0)
55
55
  mime-types (>= 1.16, < 3.0)
56
56
  netrc (~> 0.7)
57
- rollbar (2.13.1)
57
+ rollbar (2.13.3)
58
58
  multi_json
59
59
  rspec (3.5.0)
60
60
  rspec-core (~> 3.5.0)
61
61
  rspec-expectations (~> 3.5.0)
62
62
  rspec-mocks (~> 3.5.0)
63
- rspec-core (3.5.3)
63
+ rspec-core (3.5.4)
64
64
  rspec-support (~> 3.5.0)
65
65
  rspec-expectations (3.5.0)
66
66
  diff-lcs (>= 1.2.0, < 2.0)
data/bin/pushyd CHANGED
@@ -83,5 +83,12 @@ Daemons.run_proc(Conf.generate(:process_name), run_options) do
83
83
 
84
84
  # Start daemon
85
85
  Conf.log :launcher, "start daemon"
86
- PushyDaemon::Daemon.run
86
+
87
+ # Start the proxy
88
+ PushyDaemon::Proxy.new
89
+
90
+ # Backup infinite loop in case shout does nothing
91
+ loop do
92
+ sleep 1
93
+ end
87
94
  end
@@ -6,7 +6,7 @@ MSG_RLAY = "RLAY"
6
6
  # Constants: AMQP protocol
7
7
  AMQP_HEARTBEAT_INTERVAL = 30
8
8
  AMQP_RECOVERY_INTERVAL = 5
9
- AMQP_PREFETCH = 3
9
+ AMQP_PREFETCH = 5
10
10
  AMQP_MANUAL_ACK = false
11
11
 
12
12
  # Constants: shouter
@@ -17,9 +17,9 @@ LOGGER_FORMAT = {
17
17
  context: {
18
18
  caller: "%-17s",
19
19
  rule: "%-20s",
20
- }
21
- # array: "PA%s %s",
22
- # hash: "PH%s %-20s %s",
20
+ },
21
+ array: " - %s",
22
+ hash: " = %-20s %s",
23
23
  }
24
24
 
25
25
 
@@ -65,7 +65,7 @@ module PushyDaemon
65
65
 
66
66
  # Check if we need to relay anything
67
67
  unless @rule[:relay]
68
- log_debug "handle_relay: no [relay] URL"
68
+ # log_debug "handle_relay: no [relay] URL"
69
69
  return
70
70
  end
71
71
 
@@ -95,7 +95,7 @@ module PushyDaemon
95
95
 
96
96
  # Compute: payload MD5, HMAC signature
97
97
  headers_md5 headers, request_body
98
- headers_sign headers, @rule[:sign], [:date]
98
+ headers_sign headers, @rule[:sign]
99
99
 
100
100
  # Build final request
101
101
  request = RestClient::Request.new url: relay_url,
@@ -109,7 +109,7 @@ module PushyDaemon
109
109
 
110
110
  # Handle exceptions
111
111
  rescue RestClient::ExceptionWithResponse, URI::InvalidURIError, RestClient::InternalServerError => e
112
- log_error "#{request_prefix} rest-client exception: #{e.message}"
112
+ log_error "#{request_prefix} rest-client: #{e.message}"
113
113
  rescue ApiAuth::ApiAuthError, ApiAuth::UnknownHTTPRequest => e
114
114
  log_error "#{request_prefix} api-auth: #{e.message}"
115
115
  rescue Errno::ECONNREFUSED => e
data/lib/pushyd/proxy.rb CHANGED
@@ -37,9 +37,14 @@ module PushyDaemon
37
37
  # Send config table to logs
38
38
  log_info "Proxy initialized", @table.to_s.lines
39
39
 
40
+ rescue BmcDaemonLib::MqConsumerException, EndpointConnectionError, ShouterInterrupted, Errno::EACCES => e
41
+ log_error "Proxy: #{e.message}"
42
+ abort "EXITING #{e.class}: #{e.message}"
43
+
40
44
  rescue StandardError => e
41
- puts "Proxy.initialize: exception: #{e.inspect}"
42
- log_error "Proxy.initialize: exception: #{e.inspect}"
45
+ log_error "Proxy: #{e.message}", e.backtrace
46
+ abort "EXITING #{e.class}: #{e.message} \n #{e.backtrace.to_yaml}"
47
+
43
48
  raise MqConsumerException, e.message
44
49
 
45
50
  end
data/lib/pushyd.rb CHANGED
@@ -15,7 +15,6 @@ require_relative "pushyd/constants"
15
15
  require_relative "pushyd/proxy"
16
16
  require_relative "pushyd/consumer"
17
17
  require_relative "pushyd/shouter"
18
- require_relative "pushyd/daemon"
19
18
 
20
19
  # Init
21
20
  require_relative "pushyd/initialize"
@@ -4,95 +4,89 @@ require 'base64'
4
4
  module Shared
5
5
  module HmacSignature
6
6
 
7
- def headers_sign headers, config, names = ['date']
7
+ def headers_md5 headers, payload
8
+ headers['Content-MD5'] = Digest::MD5.hexdigest(payload.to_s)
9
+ end
10
+
11
+ def headers_sign headers, config
8
12
  # Extract and check
9
13
  return unless config.is_a? Hash
10
- hmac_method = config[:method]
11
- hmac_user = config[:user]
12
- hmac_secret = config[:secret]
13
- #log_debug "headers_sign config", config
14
+ hmac_method = config[:method]
15
+ hmac_user = config[:user]
16
+ hmac_secret = config[:secret]
17
+ log_debug "headers_sign config", config
14
18
 
15
19
  # Check params
16
- unless config[:method] && config[:user] && config[:secret]
20
+ unless hmac_method && hmac_user && hmac_secret
17
21
  log_error "headers_sign: missing method/user/secret"
18
22
  return
19
23
  end
20
24
 
21
- # Check params
22
- unless config[:method] == 'hmac-kong'
23
- log_error "headers_sign: only [hmac-kong] method is supported"
25
+ # Check headers, and translate names to strings
26
+ unless config[:headers].is_a? Array
27
+ log_error "headers_sign: [headers] should be an array of headers to be signed"
24
28
  return
25
29
  end
30
+ hmac_headers = config[:headers].map(&:to_s)
26
31
 
27
- # OK, lets go
28
- hmac_sign_kong headers, config[:user], config[:secret], names
29
- # log_info "headers_sign: after signing", headers
30
- end
32
+ # Update date
33
+ headers['Date'] = Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
31
34
 
32
- def headers_md5 headers, payload
33
- headers['Content-MD5'] = Digest::MD5.hexdigest(payload.to_s)
35
+ # Let's apply the requested method
36
+ case hmac_method
37
+ when 'hmac-kong'
38
+ hmac_sign_kong headers, hmac_user, hmac_secret, hmac_headers
39
+ else
40
+ log_error "headers_sign: only [hmac-kong] method is supported"
41
+ return
42
+ end
34
43
  end
35
44
 
36
45
  private
37
46
 
38
- def hmac_sign_kong headers, client_id, client_secret, names
39
- # Update date
40
- headers['Date'] = Time.now.strftime('%a, %d %b %Y %H:%M:%S GMT')
41
- # headers['Content-MD5'] = Date.now.strftime('%a, %d %b %Y %H:%M:%S GMT')
42
- # log_debug "hmac_sign_kong: headers", headers
43
-
44
- # Filter headers we're going to hash
45
- myheaders = hmac_headers_filter headers, names
47
+ def hmac_sign_kong headers, client_id, client_secret, selection
48
+ # Ensure we have :date in headers and no dup
49
+ selected = selection.push("date").uniq
46
50
 
47
51
  # Signe string of headers
48
- signature = hmac_headers_hash myheaders, client_secret
49
- log_debug "hmac_sign_kong signed [#{signature}] from headers #{myheaders.keys.inspect}"
52
+ signature = hmac_headers_hash headers, selected, client_secret
53
+ log_debug "hmac_sign_kong: signed [#{signature}] from #{selected.inspect}"
50
54
 
51
55
  # Add auth header
52
- headers['Authorization'] = hmac_build_header(client_id, myheaders, signature)
56
+ headers['Authorization'] = hmac_build_header(client_id, selection, signature)
53
57
  #headers['test'] = "testing123"
54
58
 
55
59
  # That's OK
56
60
  return headers
57
61
  end
58
62
 
59
- def hmac_build_header client_id, myheaders, signature
63
+ def hmac_build_header client_id, selection, signature
60
64
  sprintf 'hmac username="%s", algorithm="hmac-sha1", headers="%s", signature="%s"',
61
65
  client_id,
62
- myheaders.keys.map(&:downcase).join(' '),
66
+ selection.map(&:downcase).join(' '),
63
67
  signature
64
68
  end
65
69
 
66
- def hmac_headers_filter headers, selection
67
- out = {}
70
+ def hmac_headers_hash headers, selection, client_secret
71
+ # Init
72
+ selected = []
68
73
 
69
- # Build array of keys as strings, downcase
70
- selection_names = selection.map{|h| h.to_s.downcase}
74
+ # For each selected header
75
+ selection.each do |sel|
76
+ this = sel.downcase
71
77
 
72
- # For each header, stack it or not
73
- headers.each do |name, value|
74
- name_down = name.downcase
75
- next unless selection_names.include? name_down
76
- out[name_down] = value
78
+ # For each header, stack it or not
79
+ headers.each do |header_name, header_value|
80
+ next unless this == header_name.downcase
81
+ selected << sprintf("%s: %s", this, header_value)
82
+ end
77
83
  end
78
84
 
79
- # We're done
80
- return out
81
- end
82
-
83
- def hmac_headers_hash myheaders, client_secret
84
- # Build headers string
85
- data = myheaders.map do |name, value|
86
- sprintf("%s: %s", name, value)
87
- end.join("\n")
88
-
89
- # Hash this
85
+ # Build headers string and hash it
86
+ data = selected.join("\n")
90
87
  digest = OpenSSL::Digest.new('sha1')
91
88
  Base64.encode64(OpenSSL::HMAC.digest(digest, client_secret, data)).strip
92
89
  end
93
90
 
94
- def hmac_sign_data client_secret, data
95
- end
96
-
97
91
  end
98
92
  end
data/pushyd.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  # Project version
4
- spec.version = "0.21.0"
4
+ spec.version = "0.22.0"
5
5
 
6
6
  # Project description
7
7
  spec.name = "pushyd"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushyd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno MEDICI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -225,7 +225,6 @@ files:
225
225
  - lib/pushyd.rb
226
226
  - lib/pushyd/constants.rb
227
227
  - lib/pushyd/consumer.rb
228
- - lib/pushyd/daemon.rb
229
228
  - lib/pushyd/initialize.rb
230
229
  - lib/pushyd/proxy.rb
231
230
  - lib/pushyd/shouter.rb
data/lib/pushyd/daemon.rb DELETED
@@ -1,20 +0,0 @@
1
- module PushyDaemon
2
- class Daemon
3
-
4
- def self.run
5
- # Create a new proxy, and dump its configuration
6
- Proxy.new
7
-
8
- # Backup infinite loop in case shout does nothing
9
- loop do
10
- sleep 1
11
- end
12
-
13
- rescue BmcDaemonLib::MqConsumerException, EndpointConnectionError, ShouterInterrupted => e
14
- abort "EXITING #{e.class}: #{e.message}"
15
- rescue Errno::EACCES, StandardError => e
16
- abort "EXITING #{e.class}: #{e.message} \n #{e.backtrace.to_yaml}"
17
- end
18
-
19
- end
20
- end