rservicebus2 0.2.19 → 0.2.20

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: 40740ce5d75540b3c751035c3b36e9829c14cae0decfaafeaca9ea02d59c775d
4
- data.tar.gz: 52ad2edd143b3b5248a44510412265d86fd64c16cd1777a69d970203ba5be239
3
+ metadata.gz: f586d7a257549f1a8bbac85940e7740bc6927928b75e3254254cf1a945aefa38
4
+ data.tar.gz: 3e2352c5ddebf9cb4583a67106e4286a54f0b75f67c0fa1f485b56bd70c1dd94
5
5
  SHA512:
6
- metadata.gz: af23a4c627e06a151acee10fc4a1be2582195d0df9f7d38bd127c446802a79dbdbb0e82cf9a22a9d2df2ffd572b6e1654bb42706eb5a2bf4a6c1f4b66d336b26
7
- data.tar.gz: 27003eec5f598361137ee0d187a4432fd91e1f1a2c19aebd724ae727adb47cc8018ec25ecd2e0d339d5acefe52fd4035646c52992374a7bf15cd3ffa1cf8643c
6
+ metadata.gz: efbdcb52173f9caff80c659e2aae973deeaef5d9cc5adf31d9d251f8c88ef6cf1b212514ed07a88ab36efb7e5e84b83d1938710e5b50ae50049b0b04907df325
7
+ data.tar.gz: 5aeed54b1b619ba5f6b6a2c9221e868770575f88c18f3426ff23ee46abfc7ff62424c5a3a1609e5487bb36e0b0f1b5edfa09ac8cf920b64a4d5a385f3c26434f
@@ -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"
@@ -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,19 @@ module RServiceBus2
140
140
  next if file_path.end_with?('.')
141
141
 
142
142
  msg_name = get_msg_name(file_path)
143
+ RServiceBus2.add_to_permitted_classes(
144
+ msg_name.gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
145
+ )
146
+
143
147
  if File.directory?(file_path)
144
148
  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)
149
+ next
150
150
  end
151
+
152
+ # Classify
153
+ handler_name = "message_handler_#{msg_name}"
154
+ .gsub(/(?<=_|^)(\w)/) { Regexp.last_match(1).upcase }.gsub(/(?:_)(\w)/, '\1')
155
+ load_handler(msg_name, file_path, handler_name)
151
156
  end
152
157
 
153
158
  self
@@ -1,7 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'csv'
4
+
3
5
  # Helper functions
4
6
  module RServiceBus2
7
+ DEFAULT_PERMITTED_CLASSES = 'RServiceBus2::Message,Time,UUIDTools::UUID'
8
+
9
+ def self.permitted_classes
10
+ permitted_classes_string = get_value('PERMITTED_CLASSES', DEFAULT_PERMITTED_CLASSES)
11
+ CSV.parse(permitted_classes_string)[0]
12
+ end
13
+
14
+ def self.add_to_permitted_classes(string)
15
+ ENV['PERMITTED_CLASSES'] = permitted_classes
16
+ .push(string)
17
+ .uniq
18
+ .to_csv
19
+ end
20
+
21
+ def self.safe_load(body)
22
+ YAML.safe_load(body, permitted_classes: permitted_classes)
23
+ end
24
+
5
25
  def self.convert_dto_to_hash(obj)
6
26
  hash = {}
7
27
  obj.instance_variables.each do |var|
@@ -162,7 +162,7 @@ module RServiceBus2
162
162
  body = @mq.pop
163
163
  begin
164
164
  @stats.inc_total_processed
165
- @msg = YAML.load(body)
165
+ @msg = RServiceBus2.safe_load(body)
166
166
  case @msg.msg.class.name
167
167
  when 'RServiceBus2::MessageSubscription'
168
168
  @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
 
@@ -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
 
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.20
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-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: beanstalk-client