cic-cli/cic/keystore.py

32 lines
911 B
Python
Raw Permalink Normal View History

2021-10-10 11:33:30 +02:00
# standard imports
import os
import json
import logging
# external imports
from funga.error import (
DecryptError,
KeyfileError,
)
from funga.keystore import Keystore
logg = logging.getLogger(__name__)
2021-10-10 12:50:18 +02:00
2021-10-10 11:33:30 +02:00
class KeystoreDirectory(Keystore):
def process_dir(self, path, password_retriever=None, default_password=''):
for v in os.listdir(path):
fp = os.path.join(path, v)
try:
self.import_keystore_file(fp, password=default_password)
except IsADirectoryError:
pass
except KeyfileError as e:
logg.warning(f'file {fp} could not be parsed as keyfile: {e}')
2021-10-10 11:33:30 +02:00
except DecryptError as e:
if password_retriever is None:
2021-10-10 11:33:30 +02:00
raise e
password = password_retriever()
self.import_keystore_file(fp, password=password)