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 +4 -4
- data/lib/tshield/grpc.rb +4 -5
- data/lib/tshield/grpc/vcr.rb +34 -20
- data/lib/tshield/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36efe1ccd1ea061d66f046d338b76fcb0b9b6f30c740ecadabe6c774939dcd5b
|
4
|
+
data.tar.gz: 38559f053d082a577260aa94a115a66937ffb9ce45c52fee3a60339ade9ea32d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba74b2c25265ef74b62b297db19795b387c1bfe4821dce609d17cf99b00d663d58f3f889e134d58a22b679b9f1781bf00c64117fdd1e097111c7fc2cfaab5069
|
7
|
+
data.tar.gz: ce7f58cb6bf00a942b56464235cd8fa002c6489aa6643c057f9d201eeebafe3e57be70724f8bca03f8068a5468caf3d62caea846869305d145edca2ed4d19322
|
data/lib/tshield/grpc.rb
CHANGED
@@ -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,
|
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
|
data/lib/tshield/grpc/vcr.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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(
|
20
|
-
|
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(
|
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(
|
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(
|
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(
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
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)
|
data/lib/tshield/version.rb
CHANGED