Add a way to only save registration resources

This commit is contained in:
Brad Warren 2016-05-25 16:32:03 -07:00
parent 29822aad9d
commit 14e2ea92ee
2 changed files with 28 additions and 5 deletions

View file

@ -186,16 +186,29 @@ class AccountFileStorage(interfaces.AccountStorage):
return acc
def save(self, account):
self._save(account, regr_only=False)
def save_regr(self, account):
"""Save the registration resource.
:param Account account: account whose regr should be saved
"""
self._save(account, regr_only=True)
def _save(self, account, regr_only):
account_dir_path = self._account_dir_path(account.id)
le_util.make_or_verify_dir(account_dir_path, 0o700, os.geteuid(),
self.config.strict_permissions)
try:
with open(self._regr_path(account_dir_path), "w") as regr_file:
regr_file.write(account.regr.json_dumps())
with le_util.safe_open(self._key_path(account_dir_path),
"w", chmod=0o400) as key_file:
key_file.write(account.key.json_dumps())
with open(self._metadata_path(account_dir_path), "w") as metadata_file:
metadata_file.write(account.meta.json_dumps())
if not regr_only:
with le_util.safe_open(self._key_path(account_dir_path),
"w", chmod=0o400) as key_file:
key_file.write(account.key.json_dumps())
with open(self._metadata_path(
account_dir_path), "w") as metadata_file:
metadata_file.write(account.meta.json_dumps())
except IOError as error:
raise errors.AccountStorageError(error)

View file

@ -137,6 +137,16 @@ class AccountFileStorageTest(unittest.TestCase):
# restore
self.assertEqual(self.acc, self.storage.load(self.acc.id))
def test_save_regr(self):
self.storage.save_regr(self.acc)
account_path = os.path.join(self.config.accounts_dir, self.acc.id)
self.assertTrue(os.path.exists(account_path))
self.assertTrue(os.path.exists(os.path.join(
account_path, "regr.json")))
for file_name in "meta.json", "private_key.json":
self.assertFalse(os.path.exists(
os.path.join(account_path, file_name)))
def test_find_all(self):
self.storage.save(self.acc)
self.assertEqual([self.acc], self.storage.find_all())