strangeworks.core.config package

Submodules

strangeworks.core.config.base module

base.py.

class strangeworks.core.config.base.ConfigSource(active_profile: str = 'default', **kwargs)

Bases: ABC

Base class for configuration source classes.

get(key: str, profile: str | None)

retrieves the value for the given configuration parameter. If profile is specified, it overrides active profile.

set(profile: str, overwrite: bool, \*\*params)

updates existing configuration with the key-value pairs from **params. If profile is specified, it overrides active profile.

set_active_profile(active_profile: str)

set active profile name

get_active_profile() str:

retrieve the active profile name.

abstract get(key: str, profile: str | None) str | None
get_active_profile(**kwargs) str

Retrieve active profile value.

abstract set(profile: str, overwrite: bool = False, **params)
set_active_profile(active_profile: str)

Set active profile value.

Calling this method with active profile set to a None value or empty string or spaces is a no-op.

strangeworks.core.config.config module

config.py.

class strangeworks.core.config.config.Config(**kwargs)

Bases: ConfigSource

Main configuration for the SDK.

Uses multiple sources to retrieve and save values. The hierarchy of the sources is specified by the _CFG_SOURCE_ORDER list.

get(key: str, profile: str | None = None) str | None

Get configuration value.

Checks sources in the order specified by _CFG_SOURCE_ORDER for requested item and returns as soon as a value is found.

Parameters:
  • key (str) – Name of the configuration variable

  • profile (Optional[str]) – Name of the profile to use to retrieve value. Overrides active profile.

Returns:

A string value corresponding to the key or None.

Return type:

Optional[str]

set(profile: str | None = None, overwrite: bool = False, **params)

Set configuration variables.

If a file configuration is missing, it will create one. Note that this method will not update the current active_profile to the profile provided for this call. In order to switch the active_profile, the set_active_profile method must be called explicitly.

set_active_profile(active_profile: str)

Update active profile.

Update active profile for self and all ConfigSource objects contained in this object.That active profile for ConfigSource objects contained in this object will be updated only if its different than its current value.

Parameters:

active_profile (str) – The profile to use as default profile.

Return type:

None

strangeworks.core.config.defaults module

defaults.py.

class strangeworks.core.config.defaults.DefaultConfig(active_profile: str = 'default', **kwargs)

Bases: ConfigSource

Configuration Source for default values.

cfg = {'url': 'https://api.strangeworks.com'}
get(key: str, profile: str = 'default') str | None

Strangeworks SDK Default Configurations.

Serves as a source of default config values. Any request for a profile other than default will return None.

set(profile: str = 'default', overwrite: bool = False, **params)

Set (no-op) for default profile.

strangeworks.core.config.env module

env.py.

class strangeworks.core.config.env.EnvConfig(active_profile: str = 'default', **kwargs)

Bases: ConfigSource

Obtain configuration from environment variables.

Environment variables are expected to be in the following format:

STRANGEWORKS_CONFIG_{profile}_{key}

where profile and key are non-empty strings in uppercase letters.

get(key: str, profile: str = 'default') str | None

Retrieve the values from environment variables.

The method will convert all lowercase key or profile values to uppercase.

set(profile: str = 'default', overwrite: bool = False, **params)

Set method for environment variables.

Existing environment variables will be updated only if overwrite is set to True.

strangeworks.core.config.file module

file.py.

class strangeworks.core.config.file.ConfigFile(file_path: str | None = None)

Bases: ConfigSource

Read/Write configuration to a file.

Provides functionality to store and retrieve key-value pairs from a file. The file contents should be in TOML format. All table and key names are expected to be in lowercase letters. Each table represents a separate configuration profile.

ConfigFile will retrieve the latest values in the file even if the file was modified externally after the object was initialized.

_file_path

Path to the file. Can use Using (~) or (~user) as shorthand for user’s home directory.

Type:

Optional[str]

_cfg

object that contains configuration values.

Type:

TOMLDocument

_stat

object that contains information about the config file. Set each time configuration is read in.

Type:

stat_result

static create_file(profile: str, active_profile: str | None = None, file_path: str | None = None, overwrite: bool = False, **params)

Create configuration file.

get(key: str, profile: str | None = None) str | None

Retrieve value of given key.

If the source configuration file has a modification timestamp that is more recent than when configuration was read in, configuration will be reloaded from the file before it is retrieved.

Parameters:
  • key (str) – Name of the configuration variable

  • profile (Optional[str]) – Name of the profile to use for the value.

Return type:

Value of the requested configuration or None

set(profile: str, overwrite: bool = False, **params)

Set configuration values and save to file.

If a key already exists, its value will be overwritten only if overwrite is set to True.

Parameters:
  • profile (str) – Name of the profile to use for the setting values. Must be a non-empty string.

  • overwrite (bool) – Indicates whether a value that already exists should be overwritten

  • **params – key-value pairs denoting configuration values.

Module contents