From 75a14542d5e576b983be1bd6ee61f1a52cb5c4ca Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Thu, 3 Feb 2022 08:52:59 -0500 Subject: [PATCH] start removing it --- src/_zkapauthorizer/model.py | 29 ----------------------- src/_zkapauthorizer/resource.py | 42 +++++++-------------------------- 2 files changed, 8 insertions(+), 63 deletions(-) diff --git a/src/_zkapauthorizer/model.py b/src/_zkapauthorizer/model.py index 726be23..8b289f4 100644 --- a/src/_zkapauthorizer/model.py +++ b/src/_zkapauthorizer/model.py @@ -362,19 +362,6 @@ class VoucherStore(object): list((token, group_id) for token in unblinded_tokens), ) - @with_cursor - def insert_unblinded_tokens(self, cursor, unblinded_tokens, group_id): - """ - Store some unblinded tokens, for example as part of a backup-restore - process. - - :param list[str] unblinded_tokens: The unblinded tokens to store. - - :param int group_id: The unique identifier of the redemption group to - which these tokens belong. - """ - self._insert_unblinded_tokens(cursor, unblinded_tokens, group_id) - @with_cursor def insert_unblinded_tokens_for_voucher( self, cursor, voucher, public_key, unblinded_tokens, completed, spendable @@ -658,22 +645,6 @@ class VoucherStore(object): """, ) - @with_cursor - def backup(self, cursor): - """ - Read out all state necessary to recreate this database in the event it is - lost. - """ - cursor.execute( - """ - SELECT [token] FROM [unblinded-tokens] ORDER BY [rowid] - """, - ) - tokens = cursor.fetchall() - return { - "unblinded-tokens": list(token for (token,) in tokens), - } - def start_lease_maintenance(self): """ Get an object which can track a newly started round of lease maintenance diff --git a/src/_zkapauthorizer/resource.py b/src/_zkapauthorizer/resource.py index 2a37249..fcea68b 100644 --- a/src/_zkapauthorizer/resource.py +++ b/src/_zkapauthorizer/resource.py @@ -21,9 +21,7 @@ vouchers for fresh tokens. In the future it should also allow users to read statistics about token usage. """ -from itertools import islice -from json import load, loads -from sys import maxsize +from json import loads from twisted.logger import Logger from twisted.web.http import BAD_REQUEST @@ -178,8 +176,8 @@ def authorizationless_resource_tree( ), ) root.putChild( - b"unblinded-token", - _UnblindedTokenCollection( + b"lease-maintenance", + _LeaseMaintenanceResource( store, controller, ), @@ -321,10 +319,10 @@ class _ProjectVersion(Resource): ) -class _UnblindedTokenCollection(Resource): +class _LeaseMaintenanceResource(Resource): """ - This class implements inspection of unblinded tokens. Users **GET** this - resource to find out about unblinded tokens in the system. + This class implements inspection of lease maintenance activity. Users + **GET** this resource to learn about lease maintenance spending. """ _log = Logger() @@ -336,40 +334,16 @@ class _UnblindedTokenCollection(Resource): def render_GET(self, request): """ - Retrieve some unblinded tokens and associated information. + Retrieve the spending information. """ application_json(request) - state = self._store.backup() - unblinded_tokens = state["unblinded-tokens"] - - limit = request.args.get(b"limit", [None])[0] - if limit is not None: - limit = min(maxsize, int(limit)) - - position = request.args.get(b"position", [b""])[0].decode("utf-8") - return dumps_utf8( { - "total": len(unblinded_tokens), - "spendable": self._store.count_unblinded_tokens(), - "unblinded-tokens": list( - islice( - (token for token in unblinded_tokens if token > position), limit - ) - ), + "total": self._store.count_unblinded_tokens(), "lease-maintenance-spending": self._lease_maintenance_activity(), } ) - def render_POST(self, request): - """ - Store some unblinded tokens. - """ - application_json(request) - unblinded_tokens = load(request.content)["unblinded-tokens"] - self._store.insert_unblinded_tokens(unblinded_tokens, group_id=0) - return dumps_utf8({}) - def _lease_maintenance_activity(self): activity = self._store.get_latest_lease_maintenance_activity() if activity is None: -- GitLab