rservicebus2 0.2.19 → 0.2.24

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
2
  SHA256:
3
- metadata.gz: 40740ce5d75540b3c751035c3b36e9829c14cae0decfaafeaca9ea02d59c775d
4
- data.tar.gz: 52ad2edd143b3b5248a44510412265d86fd64c16cd1777a69d970203ba5be239
3
+ metadata.gz: bda60d28cc7f2488863f583c78cd7d93f5f10e9b1108e555ace21bc4c9a1e5c0
4
+ data.tar.gz: 0a6909f90328adb8dd96f3dc7f2aee10ba7e930d7a55a9de7db3dc9c7a3d8bd8
5
5
  SHA512:
6
- metadata.gz: af23a4c627e06a151acee10fc4a1be2582195d0df9f7d38bd127c446802a79dbdbb0e82cf9a22a9d2df2ffd572b6e1654bb42706eb5a2bf4a6c1f4b66d336b26
7
- data.tar.gz: 27003eec5f598361137ee0d187a4432fd91e1f1a2c19aebd724ae727adb47cc8018ec25ecd2e0d339d5acefe52fd4035646c52992374a7bf15cd3ffa1cf8643c
6
+ metadata.gz: d52251deafca3c285f9f263f2ef94b38c702855f12dcd5d1425dd1c118d92774db86cecbe0a6ba87ee1e5e5e9fd9c6971a9f75a057c389618c0e6f38c0590d98
7
+ data.tar.gz: 1959b69ce7b511dd8f09b4a19dbbda9967671f369ff714aeb129c88054fafe1542cf220ba5757cfdf6030800327ec1e6ee07739ac4b4d0d56f9d42d4cf9c5e59
@@ -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|
@@ -32,6 +39,7 @@ module RServiceBus2
32
39
  end
33
40
 
34
41
  def self.create_anonymous_class(name_for_class)
42
+ # TODO do some reflection thing to create a class
35
43
  new_anonymous_class = Class.new(Object)
36
44
  Object.const_set(name_for_class, new_anonymous_class)
37
45
  Object.const_get(name_for_class).new
@@ -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
 
@@ -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
 
@@ -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,RServiceBus2::ErrorMessage,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.19
4
+ version: 0.2.24
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-28 00:00:00.000000000 Z
11
+ date: 2021-06-04 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