Skip to content

Commit

Permalink
Added clear method to the nonce service.
Browse files Browse the repository at this point in the history
  • Loading branch information
piraz committed Oct 27, 2020
1 parent 3a85f6d commit 7a4a67a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion peasant/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def consume(self, **kwargs):
"""
raise NotImplementedError

def clear(self, **kwargs):
""" Clears a nonce sent to the request
:param kwargs:
:key request: The Http request being serviced.
:key nonce: The nonce being consumed by the server.
"""
raise NotImplementedError

def block_request(self, **kwargs):
raise NotImplementedError

Expand All @@ -52,7 +60,9 @@ def wrapper(self, *args, **kwargs):
nonce = self.nonce_service.from_request(request=self)
if self.nonce_service.consume(
request=self, nonce=nonce) is not None:
return method(self, *args, **kwargs)
retval = method(self, *args, **kwargs)
self.nonce_service.clear(request=self, nonce=nonce)
return retval
else:
self.nonce_service.block_request(request=self)
return wrapper

0 comments on commit 7a4a67a

Please sign in to comment.