Class: Mongo::Server::AppMetadata::Environment Private
- Inherits:
-
Object
- Object
- Mongo::Server::AppMetadata::Environment
- Defined in:
- build/ruby-driver-v2.19/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.
Implements the logic from the handshake spec, for deducing and reporting the current FaaS environment in which the program is executing.
Defined Under Namespace
Classes: MissingVariable, TooManyEnvironments, TypeMismatch, ValueTooLong
Constant Summary collapse
- MAXIMUM_VALUE_LENGTH =
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.
This value is not explicitly specified in the spec, only implied to be less than 512.
500
- DISCRIMINATORS =
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 mapping that determines which FaaS environment is active, based on which environment variable(s) are present.
{ 'AWS_EXECUTION_ENV' => { pattern: /^AWS_Lambda_/, name: 'aws.lambda' }, 'AWS_LAMBDA_RUNTIME_API' => { name: 'aws.lambda' }, 'FUNCTIONS_WORKER_RUNTIME' => { name: 'azure.func' }, 'K_SERVICE' => { name: 'gcp.func' }, 'FUNCTION_NAME' => { name: 'gcp.func' }, 'VERCEL' => { name: 'vercel' }, }.freeze
- COERCIONS =
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.
Describes how to coerce values of the specified type.
{ string: ->(v) { String(v) }, integer: ->(v) { Integer(v) } }.freeze
- FIELDS =
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.
Describes which fields are required for each FaaS environment, along with their expected types, and how they should be named in the handshake document.
{ 'aws.lambda' => { 'AWS_REGION' => { field: :region, type: :string }, 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE' => { field: :memory_mb, type: :integer }, }, 'azure.func' => {}, 'gcp.func' => { 'FUNCTION_MEMORY_MB' => { field: :memory_mb, type: :integer }, 'FUNCTION_TIMEOUT_SEC' => { field: :timeout_sec, type: :integer }, 'FUNCTION_REGION' => { field: :region, type: :string }, }, 'vercel' => { 'VERCEL_REGION' => { field: :region, type: :string }, }, }.freeze
Instance Attribute Summary collapse
-
#error ⇒ String | nil
readonly
private
The error message explaining why a valid FaaS environment was not detected, or nil if no error occurred.
-
#fields ⇒ Hash | nil
readonly
private
The fields describing the detected FaaS environment.
-
#name ⇒ String | nil
readonly
private
The name of the FaaS environment that was detected, or nil if no valid FaaS environment was detected.
Instance Method Summary collapse
-
#aws? ⇒ true | false
private
Queries whether the current environment is a valid AWS Lambda environment.
-
#azure? ⇒ true | false
private
Queries whether the current environment is a valid Azure environment.
-
#faas? ⇒ true | false
private
Queries whether the current environment is a valid FaaS environment.
-
#gcp? ⇒ true | false
private
Queries whether the current environment is a valid GCP environment.
-
#initialize ⇒ Environment
constructor
private
Create a new AppMetadata::Environment object, initializing it from the current ENV variables.
-
#to_h ⇒ Hash
private
Compiles the detected environment information into a Hash.
-
#vercel? ⇒ true | false
private
Queries whether the current environment is a valid Vercel environment.
Constructor Details
#initialize ⇒ Environment
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.
Create a new AppMetadata::Environment object, initializing it from the current ENV variables. If no FaaS environment is detected, or if the environment contains invalid or contradictory state, it will be initialized with {name} set to {nil}.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 104 def initialize @error = nil @name = detect_environment populate_fields rescue TooManyEnvironments => e self.error = "too many environments detected: #{e.}" rescue MissingVariable => e self.error = "missing environment variable: #{e.}" rescue TypeMismatch => e self.error = e. rescue ValueTooLong => e self.error = "value for #{e.} is too long" end |
Instance Attribute Details
#error ⇒ String | nil
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.
These error messagess are not to be propogated to the user; they are intended only for troubleshooting and debugging.)
Returns the error message explaining why a valid FaaS environment was not detected, or nil if no error occurred.
98 99 100 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 98 def error @error end |
#fields ⇒ 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 the fields describing the detected FaaS environment.
91 92 93 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 91 def fields @fields end |
#name ⇒ String | 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 name of the FaaS environment that was detected, or nil if no valid FaaS environment was detected.
87 88 89 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 87 def name @name end |
Instance Method Details
#aws? ⇒ true | false
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.
Queries whether the current environment is a valid AWS Lambda environment.
131 132 133 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 131 def aws? @name == 'aws.lambda' end |
#azure? ⇒ true | false
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.
Queries whether the current environment is a valid Azure environment.
140 141 142 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 140 def azure? @name == 'azure.func' end |
#faas? ⇒ true | false
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.
Queries whether the current environment is a valid FaaS environment.
122 123 124 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 122 def faas? @name != nil end |
#gcp? ⇒ true | false
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.
Queries whether the current environment is a valid GCP environment.
149 150 151 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 149 def gcp? @name == 'gcp.func' end |
#to_h ⇒ 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.
Compiles the detected environment information into a Hash. It will always include a {name} key, but may include other keys as well, depending on the detected FaaS environment. (See the handshake spec for details.)
168 169 170 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 168 def to_h fields.merge(name: name) end |
#vercel? ⇒ true | false
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.
Queries whether the current environment is a valid Vercel environment.
158 159 160 |
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/environment.rb', line 158 def vercel? @name == 'vercel' end |