Skip to content

Commit

Permalink
Merge pull request #165 from olcf/ngin_multi_thread
Browse files Browse the repository at this point in the history
parallelize the loading of iddb
  • Loading branch information
Noah Ginsburg authored Apr 5, 2020
2 parents 2f9d49a + 6517d09 commit 498bdf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions libpkpass/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ def _validate_identities(self, swap_list=None):
if not swap_list:
swap_list = self.escrow_and_recipient_list
for recipient in swap_list:
self.identities.verify_identity(recipient)
self.identities.verify_identity(recipient, [])
if recipient not in self.identities.iddb.keys():
raise CliArgumentError(
"Error: Recipient '%s' is not in the recipient database" %
recipient)

if self.args['identity'] in self.identities.iddb.keys():
self.identities.verify_identity(self.args['identity'])
self.identities.verify_identity(self.args['identity'], [])
else:
raise CliArgumentError(
"Error: Your user '%s' is not in the recipient database" %
Expand Down
19 changes: 15 additions & 4 deletions libpkpass/identities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This Module handles the identitydb object"""
import os
import tempfile
import threading
import libpkpass.crypto as crypto
from libpkpass.errors import FileOpenError, CliArgumentError

Expand Down Expand Up @@ -77,12 +78,22 @@ def load_certs_from_directory(self,
if certpath:
self._load_from_directory(certpath, 'certificate')
if verify_on_load:
for key, _ in self.iddb.items():
self.verify_identity(key)
x_ls = self.iddb.keys()
thread_list = []
results = []
for username in x_ls:
thread = threading.Thread(target=self.verify_identity, args=(username, results))
thread_list.append(thread)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()

#######################################################################
def verify_identity(self, identity):
""" Read in all rsa keys from directory and name them as found """
def verify_identity(self, identity, results):
""" Read in all rsa keys from directory and name them as found
results is a meaningless parameter, but is required to make threading work
"""
#######################################################################
try:
self.iddb[identity]['cabundle'] = self.cabundle
Expand Down

0 comments on commit 498bdf9

Please sign in to comment.