rservicebus2 0.2.18 → 0.2.23

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: 70e06273be45dd1c4fb2c5611962b1b2f0bd13f8bbf1dd6f19e1f0efaac3d26f
4
- data.tar.gz: d9efd6d11e1162a8f6d17a214d4d7e2c4d2cd9f1501a14f160ac0e9e79477b09
3
+ metadata.gz: 71f2b7544eaabb8ac574d01767ff0649ac84cd5d3be3e08978f7e81a66a55fbe
4
+ data.tar.gz: abb04b187ab3c1bdc2b798df1172305f03e527b932e8a84079de203b03ac938c
5
5
  SHA512:
6
- metadata.gz: a8b7715cf19a079210e4a8d07eba4046d3742012b271c2642c4c116309fec30cf32031058dba3788081295857a51adff0fac18eb72b24df49266fed1261cce4e
7
- data.tar.gz: a063b4320249df6cfa2ed2fad0b9bccf33581920db0b44434c5ad4de499b34d074cb535c043ed3d3cde459482fa6f78aa09084c5b241220a46f9e2ee9079f63a
6
+ metadata.gz: f4e0fadea46712cb6d027936620eb2cbdd78b25dbbfc38c912f16eedb1a2793ccdbc71535ee34c68764b0433ba6c01c0e7d951fe0ed93c8b034d0e3153fc8958
7
+ data.tar.gz: 433bf092c220e1eafe3b3ae365fe9633bcabec7330c940445a983bbce2da65db835d54026fa95848ed72b163bf3fbd17cf6dc6eacbe1aa950fb1608a42667b73
@@ -13,7 +13,8 @@ def return_msg(beanstalk, job, request_nbr)
13
13
 
14
14
  msg_name = payload.match('(\w*)', start_index)[1]
15
15
 
16
- msg = YAML.load(payload)
16
+ msg = RServiceBus2.safe_load(payload)
17
+
17
18
  if msg.last_error_string.nil?
18
19
  puts "*** Requested msg, #{request_nbr}, does not have a sourceQueue to
19
20
  which it can be returned"
data/lib/rservicebus2.rb CHANGED
@@ -23,6 +23,7 @@ require 'rservicebus2/config'
23
23
  require 'rservicebus2/endpointmapping'
24
24
  require 'rservicebus2/statistic_manager'
25
25
  require 'rservicebus2/audit'
26
+ require 'rservicebus2/yaml_safe_loader'
26
27
 
27
28
  require 'rservicebus2/message'
28
29
  require 'rservicebus2/message/subscription'
@@ -50,7 +50,7 @@ module RServiceBus2
50
50
  def check_for_reply(queue_name)
51
51
  @mq.subscribe(queue_name)
52
52
  body = @mq.pop
53
- @msg = YAML.load(body)
53
+ @msg = RServiceBus2.safe_load(body)
54
54
  @mq.ack
55
55
  @msg.msg
56
56
  end
@@ -140,14 +140,17 @@ module RServiceBus2
140
140
  next if file_path.end_with?('.')
141
141
 
142
142
  msg_name = get_msg_name(file_path)
143
+ YamlSafeLoader.instance.add_permitted_class(msg_name
144
+ .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1'))
143
145
  if File.directory?(file_path)
144
146
  load_handlers_from_second_level_path(msg_name, file_path)
145
- else
146
- # Classify
147
- handler_name = "message_handler_#{msg_name}"
148
- .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
149
- load_handler(msg_name, file_path, handler_name)
147
+ next
150
148
  end
149
+
150
+ # Classify
151
+ handler_name = "message_handler_#{msg_name}"
152
+ .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
153
+ load_handler(msg_name, file_path, handler_name)
151
154
  end
152
155
 
153
156
  self
@@ -1,7 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'csv'
4
+
3
5
  # Helper functions
4
6
  module RServiceBus2
7
+ def self.safe_load(body)
8
+ # YAML.safe_load(body, permitted_classes: Module.constants)
9
+ YamlSafeLoader.instance.load(body)
10
+ end
11
+
5
12
  def self.convert_dto_to_hash(obj)
6
13
  hash = {}
7
14
  obj.instance_variables.each do |var|
@@ -99,6 +99,7 @@ module RServiceBus2
99
99
 
100
100
  def initialize
101
101
  RServiceBus2.rlog "Current directory: #{Dir.pwd}"
102
+ YamlSafeLoader.instance
102
103
  @config = ConfigFromEnv.new
103
104
  .load_host_section
104
105
  .load_contracts
@@ -162,7 +163,7 @@ module RServiceBus2
162
163
  body = @mq.pop
163
164
  begin
164
165
  @stats.inc_total_processed
165
- @msg = YAML.load(body)
166
+ @msg = RServiceBus2.safe_load(body)
166
167
  case @msg.msg.class.name
167
168
  when 'RServiceBus2::MessageSubscription'
168
169
  @subscription_manager.add(@msg.msg.event_name,
@@ -55,9 +55,9 @@ module RServiceBus2
55
55
 
56
56
  # @return [Object] The msg to be sent
57
57
  def msg
58
- return YAML.load(Zlib::Inflate.inflate(@_msg)) if @compressed == true
58
+ return RServiceBus2.safe_load(Zlib::Inflate.inflate(@_msg)) if @compressed == true
59
59
 
60
- YAML.load(@_msg)
60
+ RServiceBus2.safe_load(@_msg)
61
61
  rescue ArgumentError => e
62
62
  raise e if e.message.index('undefined class/module ').nil?
63
63
 
@@ -91,7 +91,7 @@ module RServiceBus2
91
91
  # rubocop:disable Metrics/MethodLength
92
92
  def read_content_from_file(file_path)
93
93
  content = ''
94
- if @input_filter.positive?
94
+ if @input_filter.length.positive?
95
95
  case @input_filter[0]
96
96
  when 'ZIP'
97
97
  content = read_content_from_zip_file(file_path)
@@ -146,7 +146,8 @@ module RServiceBus2
146
146
  process_path(file_path)
147
147
 
148
148
  file_processed += 1
149
- RServiceBus2.log "Processed #{file_processed} of #{file_list.length}.\nAllow system tick #{self.class.name}"
149
+ RServiceBus2.log "Processed #{file_processed} of #{file_list.length}."
150
+ RServiceBus2.log "Allow system tick #{self.class.name}"
150
151
 
151
152
  break if file_processed >= max_files_processed
152
153
  end
@@ -9,30 +9,46 @@ module RServiceBus2
9
9
  class MonitorDirNotifier < Monitor
10
10
  attr_reader :path, :processing_folder, :filter
11
11
 
12
+ def directory_not_writable(path, param_name)
13
+ "***** #{param_name} is not writable, #{path}.\n" \
14
+ "***** Make the directory, #{path}, writable and try again."
15
+ end
16
+
17
+ def directory_does_not_exist(path, param_name)
18
+ "***** #{param_name} does not exist, #{path}.\n" \
19
+ "***** Create the directory, #{path}, and try again.\n" \
20
+ "***** eg, mkdir #{path}"
21
+ end
22
+
23
+ def path_is_not_a_directory(path)
24
+ "***** The specified path does not point to a directory, #{path}.\n" \
25
+ "***** Either repoint path to a directory, or remove, #{path}, and create it as a directory.\n" \
26
+ "***** eg, rm #{path} && mkdir #{path}"
27
+ end
28
+
29
+ def processing_directory_not_specified(path)
30
+ '***** Processing Directory is not specified.' \
31
+ '***** Specify the Processing Directory as a query string in the Path URI' \
32
+ "***** eg, '/#{path}?processing=*ProcessingDir*'"
33
+ end
34
+
12
35
  def validate_directory(path, param_name)
13
36
  open_folder path
14
37
  return if File.writable?(path)
15
38
 
16
- puts "***** #{param_name} is not writable, #{path}.\n
17
- ***** Make the directory, #{path}, writable and try again."
39
+ puts directory_not_writable(path, param_name)
18
40
  abort
19
41
  rescue Errno::ENOENT
20
- puts "***** #{param_name} does not exist, #{path}.\n" \
21
- "***** Create the directory, #{path}, and try again.\n" \
22
- "***** eg, mkdir #{path}"
42
+ puts directory_does_not_exist(path, param_name)
23
43
  abort
24
44
  rescue Errno::ENOTDIR
25
- puts "***** The specified path does not point to a directory, #{path}.
26
- ***** Either repoint path to a directory, or remove, #{path}, and create it as a directory.
27
- ***** eg, rm #{path} && mkdir #{path}"
45
+ puts path_is_not_a_directory(path)
28
46
  abort
29
47
  end
30
48
 
31
49
  def validate_processing_directory(uri)
32
50
  if uri.query.nil?
33
- puts '***** Processing Directory is not specified.' \
34
- '***** Specify the Processing Directory as a query string in the Path URI' \
35
- "***** eg, '/#{uri.path}?processing=*ProcessingDir*'"
51
+ puts processing_directory_not_specified(uri.path)
36
52
  abort
37
53
  end
38
54
 
@@ -16,19 +16,17 @@ module RServiceBus2
16
16
  @beanstalk = Beanstalk::Pool.new([string])
17
17
  @max_job_size = @beanstalk.stats['max-job-size']
18
18
  if @max_job_size < 4_194_304
19
- puts "***WARNING: Lowest recommended.max-job-size is 4m, current
20
- max-job-size, #{@max_job_size.to_f / (1024 * 1024)}m"
21
- puts '***WARNING: Set the job size with the -z switch, eg
22
- /usr/local/bin/beanstalkd -z 4194304'
19
+ puts '***WARNING: Lowest recommended.max-job-size is 4m, current ' \
20
+ "max-job-size, #{@max_job_size.to_f / (1024 * 1024)}m"
21
+ puts '***WARNING: Set the job size with the -z switch, eg ' \
22
+ '/usr/local/bin/beanstalkd -z 4194304'
23
23
  end
24
24
  rescue StandardError => e
25
25
  puts 'Error connecting to Beanstalk'
26
26
  puts "Host string, #{string}"
27
27
  if e.message == 'Beanstalk::NotConnected'
28
- puts '***Most likely, beanstalk is not running. Start beanstalk,
29
- and try running this again.'
30
- puts "***If you still get this error, check beanstalk is running
31
- at, #{string}"
28
+ puts '***Most likely, beanstalk is not running. Start beanstalk, and try running this again.'
29
+ puts "***If you still get this error, check beanstalk is running at, #{string}"
32
30
  else
33
31
  puts e.message
34
32
  puts e.backtrace
@@ -81,7 +81,7 @@ module RServiceBus2
81
81
 
82
82
  return {} if content == ''
83
83
 
84
- YAML.load(content)
84
+ RServiceBus2.safe_load(content)
85
85
  end
86
86
  end
87
87
  end
@@ -16,7 +16,7 @@ module RServiceBus2
16
16
 
17
17
  return [] if content == ''
18
18
 
19
- YAML.load(content)
19
+ RServiceBus2.safe_load(content)
20
20
  end
21
21
 
22
22
  def add(msg)
@@ -61,7 +61,7 @@ module RServiceBus2
61
61
 
62
62
  return {} if content == ''
63
63
 
64
- YAML.load(content)
64
+ RServiceBus2.safe_load(content)
65
65
  end
66
66
  end
67
67
  end
@@ -7,11 +7,11 @@ module RServiceBus2
7
7
  RServiceBus2.log 'Load subscriptions'
8
8
  return {} unless File.exist?(@uri.path)
9
9
 
10
- YAML.load(File.open(@uri.path))
10
+ RServiceBus2.safe_load(File.open(@uri.path))
11
11
  end
12
12
 
13
13
  def add(event_name, queue_name)
14
- s = File.exist?(@uri.path) ? YAML.load(File.open(@uri.path)) : {}
14
+ s = File.exist?(@uri.path) ? RServiceBus2.safe_load(File.open(@uri.path)) : {}
15
15
  s[event_name] = [] if s[event_name].nil?
16
16
 
17
17
  s[event_name] << queue_name
@@ -114,7 +114,7 @@ module RServiceBus2
114
114
  def process
115
115
  # Get the next job from the source queue
116
116
  job = @source.reserve @timeout
117
- msg = YAML.load(job.body)
117
+ msg = RServiceBus2.safe_load(job.body)
118
118
 
119
119
  connect(msg.remote_host_name)
120
120
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'singleton'
5
+
6
+ # YamlSafeLoader
7
+ class YamlSafeLoader
8
+ include Singleton
9
+
10
+ DEFAULT_PERMITTED_CLASSES = 'RServiceBus2::Message,Time,UUIDTools::UUID,YamlSafeLoader,' \
11
+ 'URI::Generic,URI::RFC3986_Parser,Symbol,Regexp'
12
+
13
+ def initialize
14
+ string = "#{RServiceBus2.get_value('PERMITTED_CLASSES_BASE', DEFAULT_PERMITTED_CLASSES)}," \
15
+ "#{RServiceBus2.get_value('PERMITTED_CLASSES', '')}"
16
+ @permitted_classes = CSV.parse(string)[0].reject { |c| c.to_s.rstrip.empty? }
17
+ end
18
+
19
+ def add_permitted_class(string)
20
+ @permitted_classes << string
21
+ @permitted_classes.uniq!
22
+ end
23
+
24
+ def load(body)
25
+ YAML.safe_load(body, permitted_classes: @permitted_classes)
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rservicebus2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Irvine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: beanstalk-client
@@ -165,6 +165,7 @@ files:
165
165
  - lib/rservicebus2/test/bus.rb
166
166
  - lib/rservicebus2/transporter.rb
167
167
  - lib/rservicebus2/usermessage/withpayload.rb
168
+ - lib/rservicebus2/yaml_safe_loader.rb
168
169
  homepage: http://rubygems.org/gems/rservicebus2
169
170
  licenses:
170
171
  - LGPL-3.0