Module: Mongo::Options::RedactedRepresentation Private
- Included in:
- Redacted, RedactedHash
- Defined in:
- lib/mongo/options/redacted.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared string, debug and serialization representations for option objects that may carry sensitive values.
Sensitive values are replaced by Mongo::Options::Redacted::STRING_REPLACEMENT in inspect, to_s, pretty printing, JSON, YAML, Extended JSON and Marshal output. The stored values are not changed.
BSON encoding is intentionally not overridden: these objects are BSON documents, and BSON is the wire representation used by the driver. The native BSON encoder writes nested hashes without dispatching to Ruby methods on them, so a Ruby-level to_bson override would be both incomplete and would change what is written to the wire.
Constant Summary collapse
- SERIALIZATION_REDACTED_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Envelope keys used by YAML and Marshal. They surround, rather than live inside, the user's options hash.
'redacted'- SERIALIZATION_OPTIONS_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'options'- REDACTED_SERIALIZATION_ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error raised when deserializing a representation whose sensitive values were redacted.
'Cannot deserialize options whose sensitive values were redacted: ' \ 'recreate the options from configuration instead.'
- LEGACY_SERIALIZATION_ERROR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Error raised for a payload that reaches the new object-tag YAML loader or the user-defined Marshal loader but does not contain the redaction envelope. Legacy Hash formats (for example YAML with a !ruby/hash tag, or standard Marshal data for a Hash subclass) can bypass those hooks and are not covered by this error.
'Cannot deserialize options without a redaction envelope: ' \ 'recreate the options from configuration instead.'
Instance Method Summary collapse
-
#as_extended_json(**options) ⇒ Hash
private
Convert the options to a Hash for BSON Extended JSON encoding.
-
#as_json(options = nil) ⇒ Hash
private
Convert the options to a Hash for ActiveSupport's JSON encoding.
-
#encode_with(coder) ⇒ Object
private
Serialize the options to YAML, redacting sensitive values.
-
#init_with(coder) ⇒ Object
private
Initialize options from YAML.
-
#inspect ⇒ String
private
Get a string representation of the options.
-
#marshal_dump ⇒ Hash
private
Dump the options for Marshal, redacting sensitive values.
-
#marshal_load(hash) ⇒ Object
private
Load the options from Marshal.
-
#pretty_print(q) ⇒ Object
private
Pretty print the options, redacting sensitive values.
-
#to_extended_json(**options) ⇒ String
private
Serialize the options to Extended JSON, redacting sensitive values.
-
#to_json(*args) ⇒ String
private
Serialize the options to JSON, redacting sensitive values.
-
#to_s ⇒ String
private
Get a string representation of the options.
Instance Method Details
#as_extended_json(**options) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the options to a Hash for BSON Extended JSON encoding.
126 127 128 |
# File 'lib/mongo/options/redacted.rb', line 126 def as_extended_json(**) redacted_serialization_hash.as_extended_json(**) end |
#as_json(options = nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the options to a Hash for ActiveSupport's JSON encoding.
135 136 137 138 139 140 141 142 |
# File 'lib/mongo/options/redacted.rb', line 135 def as_json( = nil) redacted = redacted_serialization_hash if redacted.respond_to?(:as_json) redacted.as_json() else redacted end end |
#encode_with(coder) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize the options to YAML, redacting sensitive values.
The user's options are nested under an envelope so that metadata cannot collide with option names. Deserialization raises when sensitive values were redacted.
94 95 96 97 98 99 |
# File 'lib/mongo/options/redacted.rb', line 94 def encode_with(coder) coder.tag = "!ruby/object:#{self.class.name}" serialization_envelope.each do |key, value| coder[key] = value end end |
#init_with(coder) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize options from YAML.
Raises if the serialized form contains redacted sensitive values or does not use the redaction envelope. It never creates an object with marker strings standing in for credentials.
108 109 110 |
# File 'lib/mongo/options/redacted.rb', line 108 def init_with(coder) load_serialization_envelope(coder.map) end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a string representation of the options.
60 61 62 |
# File 'lib/mongo/options/redacted.rb', line 60 def inspect redacted_string(:inspect) end |
#marshal_dump ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dump the options for Marshal, redacting sensitive values.
147 148 149 |
# File 'lib/mongo/options/redacted.rb', line 147 def marshal_dump serialization_envelope end |
#marshal_load(hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the options from Marshal.
Raises if the serialized form contains redacted sensitive values or does not use the redaction envelope. It never creates an object with marker strings standing in for credentials.
158 159 160 |
# File 'lib/mongo/options/redacted.rb', line 158 def marshal_load(hash) load_serialization_envelope(hash) end |
#pretty_print(q) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pretty print the options, redacting sensitive values.
74 75 76 |
# File 'lib/mongo/options/redacted.rb', line 74 def pretty_print(q) q.pp(redacted_serialization_hash) end |
#to_extended_json(**options) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize the options to Extended JSON, redacting sensitive values.
117 118 119 |
# File 'lib/mongo/options/redacted.rb', line 117 def to_extended_json(**) redacted_serialization_hash.to_extended_json(**) end |
#to_json(*args) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize the options to JSON, redacting sensitive values.
83 84 85 |
# File 'lib/mongo/options/redacted.rb', line 83 def to_json(*args) redacted_serialization_hash.to_json(*args) end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a string representation of the options.
67 68 69 |
# File 'lib/mongo/options/redacted.rb', line 67 def to_s redacted_string(:to_s) end |