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('file {} could not be parsed as keyfile: {}'.format(fp, e))
|
|
|
|
except DecryptError as e:
|
|
|
|
if password_retriever == None:
|
|
|
|
raise e
|
|
|
|
password = password_retriever()
|
|
|
|
self.import_keystore_file(fp, password=password)
|