Class: Mongo::Server::AppMetadata Private
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
Mongo::Server::Monitor::AppMetadata
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | lib/mongo/server/app_metadata.rb, lib/mongo/server/app_metadata/environment.rb, lib/mongo/server/app_metadata/platform.rb, lib/mongo/server/app_metadata/truncator.rb |
Overview
Application metadata that is sent to the server during a handshake,
when a new connection is established.
Constant Summary
-
AUTH_OPTION_KEYS =
Option keys that affect auth mechanism negotiation.
%i[ user auth_source auth_mech].freeze
-
DRIVER_NAME =
The driver name.
'mongo-ruby-driver'
-
MAX_APP_NAME_SIZE =
The max application name byte size.
128
-
PURPOSES =
Possible connection purposes.
%i[ application monitor push_monitor ].freeze
Class Method Summary
-
.new(options = {}) ⇒ AppMetadata
constructor
Internal use only
Instantiate the new
AppMetadata
object.
Instance Attribute Summary
- #platform ⇒ String readonly Internal use only
- #purpose ⇒ Symbol readonly Internal use only
- #server_api ⇒ Hash | nil readonly Internal use only
- #wrapping_libraries ⇒ Array<Hash> | nil readonly Internal use only
Instance Method Summary
-
#client_document ⇒ BSON::Document
Internal use only
Get BSON::Document to be used as value for
client
key in handshake document. -
#validated_document ⇒ BSON::Document
Internal use only
Get the metadata as BSON::Document to be sent to as part of the handshake.
- #architecture private Internal use only
-
#check_purpose!(purpose) ⇒ String | nil
private
Internal use only
Verifies that the given purpose is either nil, or is one of the allowed purposes.
-
#document ⇒ BSON::Document
private
Internal use only
Get the metadata as BSON::Document to be sent to as part of the handshake.
- #driver_doc private Internal use only
-
#env_doc ⇒ Hash | nil
private
Internal use only
Returns the environment doc describing the current execution environment.
- #name private Internal use only
- #os_doc private Internal use only
- #platform_string private Internal use only
- #type private Internal use only
-
#validate!
private
Internal use only
Check whether it is possible to build a valid app metadata document with params provided on intialization.
Instance Attribute Details
#platform ⇒ String
(readonly)
# File 'lib/mongo/server/app_metadata.rb', line 96
attr_reader :platform
#purpose ⇒ Symbol (readonly)
# File 'lib/mongo/server/app_metadata.rb', line 92
attr_reader :purpose
#server_api ⇒ Hash
| nil
(readonly)
# File 'lib/mongo/server/app_metadata.rb', line 104
attr_reader :server_api
#wrapping_libraries ⇒ Array
<Hash
> | nil
(readonly)
# File 'lib/mongo/server/app_metadata.rb', line 108
attr_reader :wrapping_libraries
Instance Method Details
#architecture (private)
# File 'lib/mongo/server/app_metadata.rb', line 212
def architecture RbConfig::CONFIG['target_cpu'] end
#check_purpose!(purpose) ⇒ String
| nil
(private)
Verifies that the given purpose is either nil, or is one of the allowed purposes.
#client_document ⇒ BSON::Document
Get BSON::Document to be used as value for client
key in handshake document.
# File 'lib/mongo/server/app_metadata.rb', line 128
def client_document @client_document ||= BSON::Document.new.tap do |doc| doc[:application] = { name: @app_name } if @app_name doc[:driver] = driver_doc doc[:os] = os_doc doc[:platform] = platform_string env_doc.tap { |env| doc[:env] = env if env } end end
#document ⇒ BSON::Document
(private)
Get the metadata as BSON::Document to be sent to as part of the handshake. The document should be appended to a suitable handshake command.
# File 'lib/mongo/server/app_metadata.rb', line 158
def document @document ||= begin client = Truncator.new(client_document).document BSON::Document.new(compression: @compressors, client: client).tap do |doc| doc[:saslSupportedMechs] = @request_auth_mech if @request_auth_mech doc.update(Utils.transform_server_api(@server_api)) if @server_api end end end
#driver_doc (private)
# File 'lib/mongo/server/app_metadata.rb', line 168
def driver_doc names = [ DRIVER_NAME ] versions = [ Mongo::VERSION ] wrapping_libraries&.each do |library| names << (library[:name] || '') versions << (library[:version] || '') end { name: names.join('|'), version: versions.join('|'), } end
#env_doc ⇒ Hash
| nil
(private)
Returns the environment doc describing the current execution environment.
# File 'lib/mongo/server/app_metadata.rb', line 195
def env_doc env = Environment.new env.present? ? env.to_h : nil end
#name (private)
# File 'lib/mongo/server/app_metadata.rb', line 208
def name RbConfig::CONFIG['host_os'] end
#os_doc (private)
# File 'lib/mongo/server/app_metadata.rb', line 182
def os_doc { type: type, name: name, architecture: architecture, } end
#platform_string (private)
#type (private)
# File 'lib/mongo/server/app_metadata.rb', line 200
def type if RbConfig::CONFIG && RbConfig::CONFIG['host_os'] RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase else 'unknown' end end
#validate! (private)
Check whether it is possible to build a valid app metadata document with params provided on intialization.
# File 'lib/mongo/server/app_metadata.rb', line 145
def validate! if @app_name && @app_name.bytesize > MAX_APP_NAME_SIZE raise Error::InvalidApplicationName.new(@app_name, MAX_APP_NAME_SIZE) end true end
#validated_document ⇒ BSON::Document
Get the metadata as BSON::Document to be sent to as part of the handshake. The document should be appended to a suitable handshake command.
This method ensures that the metadata are valid.