Add config for saving access creds between runs
parent
9745e16cf2
commit
e312fb6525
|
@ -0,0 +1,30 @@
|
||||||
|
"""
|
||||||
|
Broker configuration mgmt.
|
||||||
|
"""
|
||||||
|
from os import path
|
||||||
|
import configparser
|
||||||
|
from ..log import get_logger
|
||||||
|
|
||||||
|
log = get_logger('broker-config')
|
||||||
|
|
||||||
|
_broker_conf_path = path.join(path.dirname(__file__), 'brokers.ini')
|
||||||
|
|
||||||
|
|
||||||
|
def load() -> (configparser.ConfigParser, str):
|
||||||
|
"""Load broker config.
|
||||||
|
|
||||||
|
Create a ``broker.ini`` file if one dne.
|
||||||
|
"""
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
# mode = 'r' if path.exists(_broker_conf_path) else 'a'
|
||||||
|
read = config.read(_broker_conf_path)
|
||||||
|
log.debug(f"Read config file {_broker_conf_path}")
|
||||||
|
return config, _broker_conf_path
|
||||||
|
|
||||||
|
|
||||||
|
def write(config: configparser.ConfigParser) -> None:
|
||||||
|
"""Write broker config to disk.
|
||||||
|
"""
|
||||||
|
log.debug(f"Writing config file {_broker_conf_path}")
|
||||||
|
with open(_broker_conf_path, 'w') as cf:
|
||||||
|
return config.write(cf)
|
Loading…
Reference in New Issue