gruf 1.2.2 → 1.2.3

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
  SHA1:
3
- metadata.gz: defce64f3e996f49960608b16a3fe150b05b35d1
4
- data.tar.gz: 55d6938b28ee5b33da930464b1ae63435c3b464e
3
+ metadata.gz: 6c3c699dd26122a8e6fb4d74ea2c86b3c4d52900
4
+ data.tar.gz: 41f9f4833353086c36421a155dd66076416d9e00
5
5
  SHA512:
6
- metadata.gz: 7dbc5c72f2176307f162f9236d21895a280ecb1179254ff5e962884defe4eb3cacf44ebb7cd0972f050f4e06d6eba86e80a6742440341e0b6c86873a1e1b4a7a
7
- data.tar.gz: 4de77df215be0635943e407e78a984ede342e825c2ba31c28a6f0adc660a7f5a8919473c95a69c4dc1b7d11baebcd52b7742a5174899113dbca3d7f80fd261ef
6
+ metadata.gz: ce500f6213a21560ff8a7dc0b2e8f8e5b64d0f93ebf29b5474c9ad1ba557994504d6fc67100eef18f1feac0a4aa422e7a7ba795bf25d49f88be05af175bbc019
7
+ data.tar.gz: 548b0fff743db41630cc4aae899a1886a5be5a591bac0f8a4170a35205cead1db0ff9daef2c2c944b907a4c535071b5a4c9f08ff49cf43080bdc72fd8411dd19
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@ Changelog for the gruf gem. This includes internal history before the gem was ma
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 1.2.3
6
+
7
+ - Support nested blacklist parameters in path.to.key format
8
+
5
9
  ### 1.2.2
6
10
 
7
11
  - Pin Google Protobuf to 3.3.x due to failures in protobuf in Ruby at 3.4.x
data/README.md CHANGED
@@ -320,7 +320,7 @@ It comes with a few more options as well:
320
320
  | ------ | ----------- | ------- |
321
321
  | formatter | The formatter to use. By default `:plain` and `:logstash` are supported. | `:plain` |
322
322
  | log_parameters | If set to true, will log parameters in the response | `false` |
323
- | blacklist | An array of parameter key names to redact from logging | `[]` |
323
+ | blacklist | An array of parameter key names to redact from logging, in path.to.key format | `[]` |
324
324
  | redacted_string | The string to use for redacted parameters. | `REDACTED` |
325
325
 
326
326
  It's important to maintain a safe blacklist should you decide to log parameters; gruf does no
@@ -124,11 +124,13 @@ module Gruf
124
124
  # @return [Hash] The sanitized params in hash form
125
125
  #
126
126
  def sanitize(params = {})
127
- blacklist = options.fetch(:blacklist, []).map(&:to_s)
127
+ blacklists = options.fetch(:blacklist, []).map(&:to_s)
128
128
  redacted_string = options.fetch(:redacted_string, 'REDACTED')
129
- params.each do |param, _value|
130
- params[param] = redacted_string if blacklist.include?(param.to_s)
129
+ blacklists.each do |blacklist|
130
+ parts = blacklist.split('.').map(&:to_sym)
131
+ redact!(parts, 0, params, redacted_string)
131
132
  end
133
+ params
132
134
  end
133
135
 
134
136
  ##
@@ -139,6 +141,45 @@ module Gruf
139
141
  def options
140
142
  super().fetch(:request_logging, {})
141
143
  end
144
+
145
+ ##
146
+ # Helper method to recursively redact based on the black list
147
+ #
148
+ # @param [Array] The blacklist. ex. 'data.schema' -> [:data, :schema]
149
+ # @param [Integer] The current index of the blacklist
150
+ # @param [Hash] The hash of parameters to sanitize
151
+ # @param [String] The custom redact string
152
+ # @return [Nil]
153
+ #
154
+ def redact!(parts, i, params, redacted_string)
155
+ return if i >= parts.size || !params.key?(parts[i])
156
+ if i == parts.size - 1
157
+ if params[parts[i]].is_a? Hash
158
+ hash_deep_redact!(params[parts[i]], redacted_string)
159
+ else
160
+ params[parts[i]] = redacted_string
161
+ end
162
+ return
163
+ end
164
+ redact!(parts, i + 1, params[parts[i]], redacted_string)
165
+ end
166
+
167
+ ##
168
+ # Helper method to recursively redact the value of all hash keys
169
+ #
170
+ # @param [Hash] Part of the hash of parameters to sanitize
171
+ # @param [String] The custom redact string
172
+ # @return [Nil]
173
+ #
174
+ def hash_deep_redact!(hash, redacted_string)
175
+ hash.keys.each do |key|
176
+ if hash[key].is_a? Hash
177
+ hash_deep_redact!(hash[key], redacted_string)
178
+ else
179
+ hash[key] = redacted_string
180
+ end
181
+ end
182
+ end
142
183
  end
143
184
  end
144
185
  end
data/lib/gruf/version.rb CHANGED
@@ -15,5 +15,5 @@
15
15
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
16
  #
17
17
  module Gruf
18
- VERSION = '1.2.2'.freeze
18
+ VERSION = '1.2.3'.freeze
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-17 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler