Skip to content
Snippets Groups Projects
Unverified Commit db5750c4 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Remove some duplication in token insertion implementations

parent 1a6e2aed
Branches
No related tags found
1 merge request!128Add an interface for inserting tokens
...@@ -308,13 +308,9 @@ class VoucherStore(object): ...@@ -308,13 +308,9 @@ class VoucherStore(object):
in refs in refs
) )
@with_cursor def _insert_unblinded_tokens(self, cursor, unblinded_tokens):
def insert_unblinded_tokens(self, cursor, unblinded_tokens):
""" """
Store some unblinded tokens, for example as part of a backup-restore Helper function to really insert unblinded tokens into the database.
process.
:param list[unicode] unblinded_tokens: The unblinded tokens to store.
""" """
cursor.executemany( cursor.executemany(
""" """
...@@ -327,6 +323,16 @@ class VoucherStore(object): ...@@ -327,6 +323,16 @@ class VoucherStore(object):
), ),
) )
@with_cursor
def insert_unblinded_tokens(self, cursor, unblinded_tokens):
"""
Store some unblinded tokens, for example as part of a backup-restore
process.
:param list[unicode] unblinded_tokens: The unblinded tokens to store.
"""
self._insert_unblinded_tokens(cursor, unblinded_tokens)
@with_cursor @with_cursor
def insert_unblinded_tokens_for_voucher(self, cursor, voucher, public_key, unblinded_tokens): def insert_unblinded_tokens_for_voucher(self, cursor, voucher, public_key, unblinded_tokens):
""" """
...@@ -362,12 +368,10 @@ class VoucherStore(object): ...@@ -362,12 +368,10 @@ class VoucherStore(object):
) )
if cursor.rowcount == 0: if cursor.rowcount == 0:
raise ValueError("Cannot insert tokens for unknown voucher; add voucher first") raise ValueError("Cannot insert tokens for unknown voucher; add voucher first")
cursor.executemany( self._insert_unblinded_tokens(
""" cursor,
INSERT INTO [unblinded-tokens] VALUES (?)
""",
list( list(
(t.unblinded_token,) t.unblinded_token
for t for t
in unblinded_tokens in unblinded_tokens
), ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment