Add config account loader

fsp_feeds
Tyler Goodlet 2021-08-23 14:42:26 -04:00
parent b09d0d7129
commit 15fc66f0a9
1 changed files with 18 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Broker configuration mgmt.
import os
from os.path import dirname
import shutil
from typing import Optional
import toml
import click
@ -101,3 +102,20 @@ def write(
log.debug(f"Writing config file {path}")
with open(path, 'w') as cf:
return toml.dump(config, cf)
def load_accounts() -> dict[str, Optional[str]]:
# our default paper engine entry
accounts: dict[str, Optional[str]] = {'paper': None}
conf, path = load()
section = conf.get('accounts')
if section is None:
log.warning('No accounts config found?')
for brokername, account_labels in section.items():
for name, value in account_labels.items():
accounts[f'{brokername}.{name}'] = value
return accounts