Add 2 day TTL to page tokens
This commit is contained in:
parent
b4bddacedb
commit
335c8eb3a9
3 changed files with 9 additions and 6 deletions
|
@ -24,6 +24,8 @@ from endpoints.decorators import check_anon_protection
|
|||
from util.saas.metricqueue import time_decorator
|
||||
from util.security.crypto import encrypt_string, decrypt_string
|
||||
|
||||
# TTL (in seconds) for page tokens.
|
||||
_PAGE_TOKEN_TTL = datetime.timedelta(days=2).total_seconds()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
api_bp = Blueprint('api', __name__)
|
||||
|
@ -223,7 +225,8 @@ def page_support(func):
|
|||
|
||||
if query_args['next_page']:
|
||||
# Decrypt the page token.
|
||||
unencrypted = decrypt_string(query_args['next_page'], app.config['PAGE_TOKEN_KEY'])
|
||||
unencrypted = decrypt_string(query_args['next_page'], app.config['PAGE_TOKEN_KEY'],
|
||||
ttl=_PAGE_TOKEN_TTL)
|
||||
if unencrypted is not None:
|
||||
try:
|
||||
page_token = json.loads(unencrypted)
|
||||
|
@ -231,7 +234,7 @@ def page_support(func):
|
|||
pass
|
||||
|
||||
# Note: if page_token is None, we'll receive the first page of results back.
|
||||
(result, next_page_token) = func(self, query_args, page_token, *args, **kwargs)
|
||||
(result, next_page_token) = func(self, query_args, page_token=page_token, *args, **kwargs)
|
||||
if next_page_token is not None:
|
||||
result['next_page'] = encrypt_string(json.dumps(next_page_token),
|
||||
app.config['PAGE_TOKEN_KEY'])
|
||||
|
|
Reference in a new issue