tshield 0.11.17.0 → 0.11.18.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
  SHA256:
3
- metadata.gz: dda6e0a319ccae57965e4fdf2e51445327dbc9ee74a0b7545b10304d28405051
4
- data.tar.gz: 91a7ba920f3ccfecb2f1892fed014a196d2f53739a3e1dea592d5893b89aa6d6
3
+ metadata.gz: 36efe1ccd1ea061d66f046d338b76fcb0b9b6f30c740ecadabe6c774939dcd5b
4
+ data.tar.gz: 38559f053d082a577260aa94a115a66937ffb9ce45c52fee3a60339ade9ea32d
5
5
  SHA512:
6
- metadata.gz: d0fb66877992d29835ab23279d1364f1a468f3d547160d25ea1cd0f8451d5516eeeae414d5c75c0176aaf8faac3ad55b1230949bec2d3d0e38a9cb940cdb4c79
7
- data.tar.gz: ab7e413bf75bcf16edafa121c115e6457a794bdcdbb5c82bfe2b4678f976d97b01f245c4ca7bf7e88d62f329dd43d635d8d48a95c560d433f5c736e3b6f1dec4
6
+ metadata.gz: ba74b2c25265ef74b62b297db19795b387c1bfe4821dce609d17cf99b00d663d58f3f889e134d58a22b679b9f1781bf00c64117fdd1e097111c7fc2cfaab5069
7
+ data.tar.gz: ce7f58cb6bf00a942b56464235cd8fa002c6489aa6643c057f9d201eeebafe3e57be70724f8bca03f8068a5468caf3d62caea846869305d145edca2ed4d19322
@@ -3,16 +3,15 @@
3
3
  require 'grpc'
4
4
 
5
5
  require 'tshield/configuration'
6
- require 'tshield/sessions'
7
6
  require 'tshield/grpc/vcr'
8
7
 
9
8
  module TShield
10
9
  module Grpc
11
10
  module RequestHandler
12
11
  include TShield::Grpc::VCR
13
- def handler(method_name, request)
12
+ def handler(method_name, request, parameters)
14
13
  options = self.class.options
15
- handler_in_vcr_mode(method_name, request, options)
14
+ handler_in_vcr_mode(method_name, request, parameters, options)
16
15
  end
17
16
  end
18
17
  def self.run!
@@ -62,8 +61,8 @@ module TShield
62
61
  descriptions.each do |service_name, description|
63
62
  puts description
64
63
  method_name = service_name.to_s.underscore.to_sym
65
- define_method(method_name) do |request, _unused_call|
66
- handler(__method__, request)
64
+ define_method(method_name) do |request, parameters|
65
+ handler(__method__, request, parameters)
67
66
  end
68
67
  end
69
68
  end
@@ -1,65 +1,79 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tshield/sessions'
4
+
3
5
  module TShield
4
6
  module Grpc
5
7
  module VCR
6
- def handler_in_vcr_mode(method_name, request, options)
8
+ def handler_in_vcr_mode(method_name, request, parameters, options)
9
+ parameters.peer =~ /\[(.+?)\]/
10
+ @session = TShield::Sessions.current(Regexp.last_match(1))
11
+
12
+ TShield.logger.info("grpc using session #{@session || 'default'}")
7
13
  module_name = options['module']
8
14
 
9
- response = saved_response(module_name, method_name, request)
10
- return response if response
15
+ path = create_destiny(module_name, method_name, request)
16
+ response = saved_response(path)
17
+ if response
18
+ TShield.logger.info("returning saved response for request #{request.to_json} saved into #{hexdigest(request)}")
19
+ return response
20
+ end
11
21
 
22
+ TShield.logger.info("calling server to get response for #{request.to_json}")
12
23
  client_class = Object.const_get("#{module_name}::Stub")
13
24
  client_instance = client_class.new(options['hostname'], :this_channel_is_insecure)
14
25
  response = client_instance.send(method_name, request)
15
- save_request_and_response(request, response)
26
+ save_request_and_response(path, request, response)
16
27
  response
17
28
  end
18
29
 
19
- def saved_response(module_name, method_name, request)
20
- create_destiny(module_name, method_name, request)
21
- response_file = File.join(@complete_path, 'response')
30
+ def saved_response(path)
31
+ response_file = File.join(path, 'response')
22
32
  return false unless File.exist? response_file
23
33
 
24
34
  content = JSON.parse File.open(response_file).read
25
- response_class = File.open(File.join(@complete_path, 'response_class')).read.strip
35
+ response_class = File.open(File.join(path, 'response_class')).read.strip
26
36
  Kernel.const_get(response_class).new(content)
27
37
  end
28
38
 
29
- def save_request_and_response(request, response)
30
- save_request(request)
31
- save_response(response)
39
+ def save_request_and_response(path, request, response)
40
+ save_request(path, request)
41
+ save_response(path, response)
32
42
  end
33
43
 
34
- def save_request(request)
35
- file = File.open(File.join(@complete_path, 'original_request'), 'w')
44
+ def save_request(path, request)
45
+ file = File.open(File.join(path, 'original_request'), 'w')
36
46
  file.puts request.to_json
37
47
  file.close
38
48
  end
39
49
 
40
- def save_response(response)
41
- file = File.open(File.join(@complete_path, 'response'), 'w')
50
+ def save_response(path, response)
51
+ file = File.open(File.join(path, 'response'), 'w')
42
52
  file.puts response.to_json
43
53
  file.close
44
54
 
45
- response_class = File.open(File.join(@complete_path, 'response_class'), 'w')
55
+ response_class = File.open(File.join(path, 'response_class'), 'w')
46
56
  response_class.puts response.class.to_s
47
57
  response_class.close
48
58
  end
49
59
 
50
60
  def complete_path(module_name, method_name, request)
51
- return @complete_path if @complete_path
52
-
53
- @complete_path = ['requests', 'grpc', module_name, method_name.to_s, hexdigest(request)]
61
+ @session_name = (@session || {})[:name]
62
+ path = ['requests', 'grpc', @session_name, module_name, method_name.to_s, hexdigest(request)].compact
63
+ path
54
64
  end
55
65
 
56
66
  def create_destiny(module_name, method_name, request)
57
67
  current_path = []
58
- complete_path(module_name, method_name, request).each do |path|
68
+
69
+ path = complete_path(module_name, method_name, request)
70
+ TShield.logger.info("using path #{path}")
71
+ path.each do |path|
59
72
  current_path << path
60
73
  destiny = File.join current_path
61
74
  Dir.mkdir destiny unless File.exist? destiny
62
75
  end
76
+ path
63
77
  end
64
78
 
65
79
  def hexdigest(request)
@@ -5,7 +5,7 @@ module TShield
5
5
  class Version
6
6
  MAJOR = 0
7
7
  MINOR = 11
8
- PATCH = 17
8
+ PATCH = 18
9
9
  PRE = 0
10
10
 
11
11
  class << self
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tshield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.17.0
4
+ version: 0.11.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Rubin