Class: Temporalio::EnvConfig::ClientConfig

Inherits:
Data
  • Object
show all
Defined in:
lib/temporalio/env_config.rb,
lib/temporalio/env_config.rb

Overview

Container for multiple client configuration profiles.

This class holds a collection of named client profiles loaded from configuration sources and provides methods for profile management and client connection configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profiles: {}) ⇒ ClientConfig

Create a ClientConfig instance with defaults



386
387
388
# File 'lib/temporalio/env_config.rb', line 386

def initialize(profiles: {})
  super
end

Instance Attribute Details

#profiles ⇒ Hash<String, ClientConfigProfile> (readonly)

Returns Map of profile name to its corresponding ClientConfigProfile.

Returns:

  • (Hash<String, ClientConfigProfile>) —

    Map of profile name to its corresponding ClientConfigProfile



279
# File 'lib/temporalio/env_config.rb', line 279

ClientConfig = Data.define(:profiles)

Class Method Details

.from_h(hash) ⇒ ClientConfig

Create a ClientConfig from a hash

Parameters:

  • hash (Hash) —

    Hash representation

Returns:



290
291
292
293
294
295
# File 'lib/temporalio/env_config.rb', line 290

def self.from_h(hash)
  profiles = hash.transform_values do |profile_hash|
    ClientConfigProfile.from_h(profile_hash)
  end
  new(profiles: profiles)
end

.load(config_source: nil, config_file_strict: false, override_env_vars: nil) ⇒ ClientConfig

Load all client profiles from given sources.

This does not apply environment variable overrides to the profiles, it only uses an environment variable to find the default config file path (TEMPORAL_CONFIG_FILE).

Parameters:

  • config_source (Pathname, String, nil) (defaults to: nil) —

    Configuration source

  • config_file_strict (Boolean) (defaults to: false) —

    If true, will error on unrecognized keys

  • override_env_vars (Hash, nil) (defaults to: nil) —

    Environment variables to use

Returns:



307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/temporalio/env_config.rb', line 307

def self.load(
  config_source: nil,
  config_file_strict: false,
  override_env_vars: nil
)
  path, data = EnvConfig._source_to_path_and_data(config_source)

  loaded_profiles = Internal::Bridge::EnvConfig.load_client_config(
    path, data, config_file_strict, override_env_vars
  )

  from_h(loaded_profiles)
end

.load_client_connect_options(profile: nil, config_source: nil, disable_file: false, disable_env: false, config_file_strict: false, override_env_vars: nil, extensions: []) ⇒ Array

Load a single client profile and convert to connect config

This is a convenience function that combines loading a profile and converting it to a connect config hash, plus applying extensions.

Parameters:

  • profile (String, nil) (defaults to: nil) —

    The profile to load from the config

  • config_source (Pathname, String, nil) (defaults to: nil) —

    Configuration source

  • disable_file (Boolean) (defaults to: false) —

    If true, file loading is disabled

  • disable_env (Boolean) (defaults to: false) —

    If true, environment variable loading and overriding is disabled

  • config_file_strict (Boolean) (defaults to: false) —

    If true, will error on unrecognized keys

  • override_env_vars (Hash, nil) (defaults to: nil) —

    Environment variables to use for loading and overrides

  • extensions (Array<ClientConfigExtension>) (defaults to: []) —

    Extensions to call, in order, with the loaded profile. Plugins they return are included as plugins in the keyword args. WARNING: Extensions are experimental.

Returns:

  • (Array) —

    Tuple of [positional_args, keyword_args] that can be splatted to Client.connect



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/temporalio/env_config.rb', line 335

def self.load_client_connect_options(
  profile: nil,
  config_source: nil,
  disable_file: false,
  disable_env: false,
  config_file_strict: false,
  override_env_vars: nil,
  extensions: []
)
  _validate_extensions!(extensions)
  prof = ClientConfigProfile.load(
    profile: profile,
    config_source: config_source,
    disable_file: disable_file,
    disable_env: disable_env,
    config_file_strict: config_file_strict,
    override_env_vars: override_env_vars
  )
  positional_args, keyword_args = prof.to_client_connect_options
  return [positional_args, keyword_args] if extensions.empty?

  request = ClientConfigExtensionRequest.new(
    profile: prof,
    env: disable_env ? nil : override_env_vars || ENV.to_h
  )
  plugins = extensions.filter_map do |extension|
    extension.client_plugin(request)
  rescue StandardError => e
    raise Error, "client config extension \"#{extension.name}\": #{e.message}"
  end
  keyword_args[:plugins] = plugins unless plugins.empty?
  [positional_args, keyword_args]
end

Instance Method Details

#to_h ⇒ Hash

Convert to a hash that can be used for TOML serialization

Returns:

  • (Hash) —

    Dictionary representation



392
393
394
# File 'lib/temporalio/env_config.rb', line 392

def to_h
  profiles.transform_values(&:to_h)
end