Class: Mongo::Server::AppMetadata Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/server/app_metadata.rb,
lib/mongo/server/app_metadata/platform.rb,
lib/mongo/server/app_metadata/truncator.rb,
lib/mongo/server/app_metadata/environment.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Application metadata that is sent to the server during a handshake,

when a new connection is established.

Since:

  • 2.0.0

Direct Known Subclasses

Monitor::AppMetadata

Defined Under Namespace

Classes: Environment, Platform, Truncator

Constant Summary collapse

MAX_APP_NAME_SIZE =

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.

The max application name byte size.

Since:

  • 2.0.0

128
DRIVER_NAME =

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.

The driver name.

Since:

  • 2.0.0

'mongo-ruby-driver'
AUTH_OPTION_KEYS =

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.

Option keys that affect auth mechanism negotiation.

Since:

  • 2.0.0

%i[ user auth_source auth_mech].freeze
PURPOSES =

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.

Possible connection purposes.

Since:

  • 2.0.0

%i[ application monitor push_monitor ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AppMetadata

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.

Instantiate the new AppMetadata object.

Examples:

Instantiate the app metadata.

Mongo::Server::AppMetadata.new(options)

Parameters:

  • options (Hash) (defaults to: {})

    Metadata options.

Options Hash (options):

  • :app_name (String, Symbol)

    Application name that is printed to the mongod logs upon establishing a connection in server versions >= 3.4.

  • :auth_mech (Symbol)

    The authentication mechanism to use. One of :mongodb_cr, :mongodb_x509, :plain, :scram, :scram256

  • :auth_source (String)

    The source to authenticate from.

  • :compressors (Array<String>)

    A list of potential compressors to use, in order of preference. The driver chooses the first compressor that is also supported by the server. Currently the driver only supports ‘zstd’, ‘snappy’ and ‘zlib’.

  • :platform (String)

    Platform information to include in the metadata printed to the mongod logs upon establishing a connection in server versions >= 3.4.

  • :purpose (Symbol)

    The purpose of this connection.

  • :server_api (Hash)

    The requested server API version. This hash can have the following items:

    • :version – string

    • :strict – boolean

    • :deprecation_errors – boolean

  • :user (String)

    The user name.

  • :wrapping_libraries (Array<Hash>)

    Information about libraries such as ODMs that are wrapping the driver. Specify the lower level libraries first. Allowed hash keys: :name, :version, :platform.

Since:

  • 2.4.0



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mongo/server/app_metadata.rb', line 74

def initialize(options = {})
  @app_name = options[:app_name].to_s if options[:app_name]
  @platform = options[:platform]

  @purpose = check_purpose!(options[:purpose])

  @compressors = options[:compressors] || []
  @wrapping_libraries = options[:wrapping_libraries]
  @server_api = options[:server_api]

  return unless options[:user] && !options[:auth_mech]

  auth_db = options[:auth_source] || 'admin'
  @request_auth_mech = "#{auth_db}.#{options[:user]}"
end

Instance Attribute Details

#platformString (readonly)

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.

Returns The platform information given when the object was instantiated.

Returns:

  • (String)

    The platform information given when the object was instantiated.

Since:

  • 2.0.0



96
97
98
# File 'lib/mongo/server/app_metadata.rb', line 96

def platform
  @platform
end

#purposeSymbol (readonly)

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.

Returns The purpose of the connection for which this app metadata is created.

Returns:

  • (Symbol)

    The purpose of the connection for which this app metadata is created.

Since:

  • 2.0.0



92
93
94
# File 'lib/mongo/server/app_metadata.rb', line 92

def purpose
  @purpose
end

#server_apiHash | nil (readonly)

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.

Returns The requested server API version.

Thes hash can have the following items:

  • :version – string

  • :strict – boolean

  • :deprecation_errors – boolean.

Returns:

  • (Hash | nil)

    The requested server API version.

    Thes hash can have the following items:

    • :version – string

    • :strict – boolean

    • :deprecation_errors – boolean

Since:

  • 2.0.0



104
105
106
# File 'lib/mongo/server/app_metadata.rb', line 104

def server_api
  @server_api
end

#wrapping_librariesArray<Hash> | nil (readonly)

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.

Returns Information about libraries wrapping the driver.

Returns:

  • (Array<Hash> | nil)

    Information about libraries wrapping the driver.

Since:

  • 2.0.0



108
109
110
# File 'lib/mongo/server/app_metadata.rb', line 108

def wrapping_libraries
  @wrapping_libraries
end

Instance Method Details

#client_documentBSON::Document

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 BSON::Document to be used as value for ‘client` key in handshake document.

Returns:

  • (BSON::Document)

    Document describing client for handshake.

Since:

  • 2.0.0



128
129
130
131
132
133
134
135
136
137
# 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

#validated_documentBSON::Document

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 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.

Returns:

  • (BSON::Document)

    Valid document for connection’s handshake.

Raises:

Since:

  • 2.0.0



119
120
121
122
# File 'lib/mongo/server/app_metadata.rb', line 119

def validated_document
  validate!
  document
end