Class: Mongo::Options::Redacted
- Inherits:
-
BSON::Document
- Object
- BSON::Document
- Mongo::Options::Redacted
- Includes:
- RedactedRepresentation
- Defined in:
- lib/mongo/options/redacted.rb
Overview
Class for wrapping options that could be sensitive.
Sensitive values are redacted in inspect, to_s, pretty printed, JSON, YAML and Marshal output. The stored values are unchanged. Deserializing a YAML or Marshal representation that contained sensitive values raises ArgumentError instead of creating an object with marker credentials.
Constant Summary collapse
- SENSITIVE_OPTIONS =
The options whose values will be redacted. The username is included because it is part of the userinfo segment, whose components the connection string specification treats as sensitive values.
The arguments of the sensitive URI options are redacted as a whole: authMechanismProperties may carry a credential in any of its properties (for example an AWS session token), and the driver cannot know which properties a future mechanism will treat as secret.
%i[user password pwd proxy_password proxy_username ssl_key_pass_phrase auth_mech_properties].freeze
- STRING_REPLACEMENT =
The replacement string used in place of the value for sensitive keys.
'<REDACTED>'
Constants included from RedactedRepresentation
Mongo::Options::RedactedRepresentation::LEGACY_SERIALIZATION_ERROR, Mongo::Options::RedactedRepresentation::REDACTED_SERIALIZATION_ERROR, Mongo::Options::RedactedRepresentation::SERIALIZATION_OPTIONS_KEY, Mongo::Options::RedactedRepresentation::SERIALIZATION_REDACTED_KEY
Instance Method Summary collapse
-
#has_key?(key) ⇒ true, false
(also: #key?)
Whether these options contain a given key.
-
#reject {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns false.
-
#reject! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns false.
-
#select {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns true.
-
#select! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns true.
Methods included from RedactedRepresentation
#as_extended_json, #as_json, #encode_with, #init_with, #inspect, #marshal_dump, #marshal_load, #pretty_print, #to_extended_json, #to_json, #to_s
Instance Method Details
#has_key?(key) ⇒ true, false Also known as: key?
Whether these options contain a given key.
262 263 264 |
# File 'lib/mongo/options/redacted.rb', line 262 def has_key?(key) super(convert_key(key)) end |
#reject {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns false.
277 278 279 280 |
# File 'lib/mongo/options/redacted.rb', line 277 def reject(&block) = dup .reject!(&block) || end |
#reject! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns false.
292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/mongo/options/redacted.rb', line 292 def reject! if block_given? n_keys = keys.size keys.each do |key| delete(key) if yield(key, self[key]) end (n_keys == keys.size) ? nil : self else to_enum end end |
#select {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns true.
314 315 316 317 |
# File 'lib/mongo/options/redacted.rb', line 314 def select(&block) = dup .select!(&block) || end |
#select! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns true.
329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/mongo/options/redacted.rb', line 329 def select! if block_given? n_keys = keys.size keys.each do |key| delete(key) unless yield(key, self[key]) end (n_keys == keys.size) ? nil : self else to_enum end end |