grpc_access_logging_interceptor 0.0.2 → 0.0.4

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: 07c146c49b0d0bc4d7dcdb896f2f42d1844cc5fce15ba7502353e31086c648eb
4
- data.tar.gz: bfcaec079594df0c5ca50b9ff2f157b96e101584cc4fa9d074247eb7a6147d47
3
+ metadata.gz: a2ac41e62dbedd2f938035e7a60fa98fd4a04a70fb3850ff3b5c9e8363b11518
4
+ data.tar.gz: 993cc5f03380eb3740150b2150c07f3ca59287b50b35088b5fca864153e5f706
5
5
  SHA512:
6
- metadata.gz: 35f7abbfeda2554344b7bbc5822dc8d2f9e5c97fdbfeaac019e5ee378f310cadd92441283f1693f17111222c16b928dc7aeb10611cc3477cb8fbac638365f630
7
- data.tar.gz: 1cf87b1a859d3a1bbffa268d364da2334e8222133ef1c3890ca963e2711d0a8f295cc66b32627204f64b5acc09d2c24330192d7488555028ae9dbfc49965033c
6
+ metadata.gz: 24960dc060169a1b8584ba2be8299ba509f65076619d1b253f50a883f99a20e54164ac165cf984c015de1bbb62860a7dca667b41b9cd0909f13fd03da23762e3
7
+ data.tar.gz: 5f8362c76c97e95f3361b634be72d225027288ca08cab488e7650819d9259f2a08083a2a8000ed3a0d1169d4ecfedda6f164476d6bf9c652027a5fbb559091db
data/.travis.yml CHANGED
@@ -4,4 +4,7 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.6.2
7
- before_install: gem install bundler -v 2.0.2
7
+ before_install:
8
+ - gem install bundler -v 2.0.2
9
+ script:
10
+ - bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grpc_access_logging_interceptor (0.0.2)
4
+ grpc_access_logging_interceptor (0.0.4)
5
5
  grpc
6
6
 
7
7
  GEM
@@ -9,10 +9,10 @@ GEM
9
9
  specs:
10
10
  coderay (1.1.2)
11
11
  diff-lcs (1.3)
12
- google-protobuf (3.10.0-universal-darwin)
12
+ google-protobuf (3.11.1)
13
13
  googleapis-common-protos-types (1.0.4)
14
14
  google-protobuf (~> 3.0)
15
- grpc (1.24.0)
15
+ grpc (1.25.0)
16
16
  google-protobuf (~> 3.8)
17
17
  googleapis-common-protos-types (~> 1.0)
18
18
  method_source (0.9.2)
@@ -1,3 +1,4 @@
1
+ require "base64"
1
2
  require "grpc"
2
3
  require "grpc_access_logging_interceptor/default_logger"
3
4
 
@@ -22,16 +23,18 @@ module GrpcAccessLoggingInterceptor
22
23
  # @param [Method] method
23
24
  #
24
25
  def request_response(request:, call:, method:)
26
+ data = {} # Initialize at first to avoid nil
27
+
25
28
  accessed_at = Time.now
26
29
 
27
- data = {
30
+ data.merge!({
28
31
  remote_addr: remote_addr(call.peer),
29
32
  accessed_at: accessed_at.utc.strftime('%Y-%m-%d %H:%M:%S.%6N'),
30
33
  params: filter(request.to_h).to_json,
31
34
  user_agent: call.metadata[USER_AGENT_KEY],
32
35
  grpc_method: grpc_method(method),
33
- grpc_metadata: call.metadata.to_json,
34
- }
36
+ grpc_metadata: jsonize(call.metadata),
37
+ })
35
38
  data.merge!(custom_data(request: request, call: call, method: method))
36
39
 
37
40
  yield
@@ -69,6 +72,25 @@ module GrpcAccessLoggingInterceptor
69
72
  "/#{method.owner.service_name}/#{camelize(method.name.to_s)}"
70
73
  end
71
74
 
75
+ # @param [Hash] metadata
76
+ # @return [String]
77
+ def jsonize(metadata)
78
+ h = {}
79
+ metadata.each do |k, v|
80
+ if v.is_a?(String) && v.encoding == Encoding::ASCII_8BIT
81
+ begin
82
+ h[k] = v.encode(Encoding::UTF_8)
83
+ rescue Encoding::UndefinedConversionError
84
+ # If the value is binary, encode with Base64
85
+ h[k] = Base64.strict_encode64(v)
86
+ end
87
+ else
88
+ h[k] = v
89
+ end
90
+ end
91
+ h.to_json
92
+ end
93
+
72
94
  # @param [String] term
73
95
  # @return [String]
74
96
  def camelize(term)
@@ -1,3 +1,3 @@
1
1
  module GrpcAccessLoggingInterceptor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_access_logging_interceptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-30 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler