adam.config_manager module¶
ADAM configuration manager
-
class
adam.config_manager.
ConfigManager
(file_name=None, raw_config=None)¶ Bases:
object
Configuration object for ADAM client
A dict-like object holding the loaded ADAM configuration file. Individual items can be get/set/deleted via the
[]
notation. The keys must be fully-qualified dot-separated names, such as:conf["envs.dev.workspace"] = " .... "
When a key does not refer to a leaf node, returns a nested dict of the key’s children, i.e.:
conf["envs.dev"] = " .... "
returns
dict(url=..., workspace=..., token=....)
.-
__init__
(file_name=None, raw_config=None)¶ Load the ADAM configuration
Loads ADAM configuration from
file_name
, or default config file iffile_name==None
. Ifraw_config
is given, uses its contents to load the configuration (file_name
is ignored in that case). The typical use is to instantiate this class w.file_name
andraw_config
set to None (i.e., read from the default config file).- Parameters
file_name (str) – Path to config file to load, or None to search default locations.
raw_config (dict) – dict() of values to interpret as configuration data.
-
get_config
(environment=None)¶ Get configuration of an ADAM environment
If
environment
is given, equivalent to calling:self[f"envs.{environment}"]
If
environment
is None, andself["default_env"]
is set, equivalent to calling:self[f”envs.{self[‘default_env’]}”]
If
environment
is None, andself["default_env"]
is not set, returns the first key in theself[envs]
dict.- Parameters
environment (str) – environment name (e.g.,
prod
ordev
)- Raises
KeyError – If the requested environment isn’t found.
-
get_default_env
()¶
-
set_config
(name, cfg)¶ Set configuration of an ADAM environment
Equivalent to calling:
self[f"envs.{name}"] = cfg
- Parameters
name (str) – environment name (e.g.,
prod
ordev
)cfg (dict) – environment data
-
set_default_env
(env_name)¶
-
to_file
(file_name=None)¶ Save configuration to
file_name
or the default locationSaves to location proscribed by XDG spec (typically
~/.config/adam/config
) or tofile_name
, if it’s not set toNone
.- Parameters
file_name (str) – Path to config file to save, or None to save to default location.
-