Class: Mongo::Server::AppMetadata Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
build/ruby-driver-master/lib/mongo/server/app_metadata.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.4.0

Direct Known Subclasses

Monitor::AppMetadata

Constant Summary collapse

MAX_DOCUMENT_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 metadata document byte size.

Since:

  • 2.4.0

512.freeze
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.4.0

128.freeze
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.4.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.4.0

[: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.4.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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'build/ruby-driver-master/lib/mongo/server/app_metadata.rb', line 88

def initialize(options = {})
  @app_name = options[:app_name].to_s if options[:app_name]
  @platform = options[:platform]
  if @purpose = options[:purpose]
    unless PURPOSES.include?(@purpose)
      raise ArgumentError, "Invalid purpose: #{@purpose}"
    end
  end
  @compressors = options[:compressors] || []
  @wrapping_libraries = options[:wrapping_libraries]
  @server_api = options[:server_api]

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

Instance Attribute Details

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



110
111
112
# File 'build/ruby-driver-master/lib/mongo/server/app_metadata.rb', line 110

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



120
121
122
# File 'build/ruby-driver-master/lib/mongo/server/app_metadata.rb', line 120

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



124
125
126
# File 'build/ruby-driver-master/lib/mongo/server/app_metadata.rb', line 124

def wrapping_libraries
  @wrapping_libraries
end

Instance Method Details

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



137
138
139
140
# File 'build/ruby-driver-master/lib/mongo/server/app_metadata.rb', line 137

def validated_document
  validate!
  document
end