File tree Expand file tree Collapse file tree 4 files changed +41
-3
lines changed Expand file tree Collapse file tree 4 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -292,14 +292,14 @@ def list_databases
292
292
private
293
293
294
294
def create_from_addresses ( addresses , opts = { } )
295
- @options = Database ::DEFAULT_OPTIONS . merge ( opts ) . freeze
295
+ @options = Options :: SensitiveOptions . new . merge ( Database ::DEFAULT_OPTIONS . merge ( opts ) ) . freeze
296
296
@cluster = Cluster . new ( addresses , @monitoring , options )
297
297
@database = Database . new ( self , options [ :database ] , options )
298
298
end
299
299
300
300
def create_from_uri ( connection_string , opts = { } )
301
301
uri = URI . new ( connection_string , opts )
302
- @options = Database ::DEFAULT_OPTIONS . merge ( uri . client_options . merge ( opts ) ) . freeze
302
+ @options = Options :: SensitiveOptions . new . merge ( Database ::DEFAULT_OPTIONS . merge ( uri . client_options . merge ( opts ) ) ) . freeze
303
303
@cluster = Cluster . new ( uri . servers , @monitoring , options )
304
304
@database = Database . new ( self , options [ :database ] , options )
305
305
end
Original file line number Diff line number Diff line change 13
13
# limitations under the License.
14
14
15
15
require 'mongo/options/mapper'
16
+ require 'mongo/options/sensitive_options'
Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2015 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Mongo
16
+ module Options
17
+
18
+ SENSITIVE_OPTIONS = [ :password , :pwd ]
19
+ REDACTED_STRING = '<REDACTED>'
20
+
21
+ class SensitiveOptions < BSON ::Document
22
+
23
+ def inspect
24
+ '{' + reduce ( '' ) do |string , ( k , v ) |
25
+ string << "#{ k } =>#{ redact ( k , v ) } "
26
+ end + '}'
27
+ end
28
+
29
+ private
30
+
31
+ def redact ( k , v )
32
+ return REDACTED_STRING if SENSITIVE_OPTIONS . include? ( k . to_sym )
33
+ v . inspect
34
+ end
35
+ end
36
+ end
37
+ end
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ def deliver(messages)
183
183
def setup_authentication!
184
184
if options [ :user ]
185
185
default_mechanism = @server . features . scram_sha_1_enabled? ? :scram : :mongodb_cr
186
- user = Auth ::User . new ( { : auth_mech => default_mechanism } . merge ( options ) )
186
+ user = Auth ::User . new ( Options :: SensitiveOptions . new ( : auth_mech => default_mechanism ) . merge ( options ) )
187
187
@authenticator = Auth . get ( user )
188
188
end
189
189
end
You can’t perform that action at this time.
0 commit comments