From 69e9c1225896bc828c852bbe99730e643ebd2ee7 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 22 Apr 2020 14:50:13 +0200 Subject: [PATCH] gatekeeper reformats update_available_slots to add_update_appointment - add_update_appointment handles the slot count and also keeps a copy of the appointment uuid and slots taken. - gatekeeper.appointments is turned to a dict uuid:slots so appointment updates can be computed with no further data - deleting appointment will also allow to update the slot count with no further data from both the Watcher and the Responder --- teos/gatekeeper.py | 41 +++++++++++++++++-------------- test/teos/unit/test_gatekeeper.py | 33 ++++++++++++------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/teos/gatekeeper.py b/teos/gatekeeper.py index d0416a7..b333501 100644 --- a/teos/gatekeeper.py +++ b/teos/gatekeeper.py @@ -27,9 +27,9 @@ class UserInfo: self.available_slots = available_slots self.subscription_expiry = subscription_expiry - # FIXME: this list is currently never wiped if not appointments: - self.appointments = [] + # A dictionary of the form uuid:required_slots for each user appointment + self.appointments = {} else: self.appointments = appointments @@ -136,21 +136,20 @@ class Gatekeeper: except (InvalidParameter, InvalidKey, SignatureError): raise AuthenticationFailure("Wrong message or signature.") - def update_available_slots(self, user_id, new_appointment, old_appointment=None): + def add_update_appointment(self, user_id, uuid, appointment): """ - Updates (add/removes) slots from a user subscription. + Adds (or updates) an appointment to a user subscription. The user slots are updated accordingly. - Slots are removed if a new appointment is given, or an update is given with an appointment bigger than the - old one. + Slots are taken if a new appointment is given, or an update is given with an appointment bigger than the + existing one. - Slots are added if an update is given but the new appointment is smaller than the old one. + Slots are given back if an update is given but the new appointment is smaller than the existing one. Args: - user_id(:obj:`str`): the public key that identifies the user (33-bytes hex str). - new_appointment (:obj:`dict`): the summary of new appointment the user is requesting - to add. - old_appointment (:obj:`dict`): the summary old appointment the user wants to replace. - Optional. + user_id (:obj:`str`): the public key that identifies the user (33-bytes hex str). + uuid (:obj:`str`): the appointment uuid. + appointment (:obj:`ExtendedAppointment