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
292292 private
293293
294294 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
296296 @cluster = Cluster . new ( addresses , @monitoring , options )
297297 @database = Database . new ( self , options [ :database ] , options )
298298 end
299299
300300 def create_from_uri ( connection_string , opts = { } )
301301 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
303303 @cluster = Cluster . new ( uri . servers , @monitoring , options )
304304 @database = Database . new ( self , options [ :database ] , options )
305305 end
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515require '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)
183183 def setup_authentication!
184184 if options [ :user ]
185185 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 ) )
187187 @authenticator = Auth . get ( user )
188188 end
189189 end
You can’t perform that action at this time.
0 commit comments