Fix V2 catalog and tag pagination
This commit is contained in:
parent
7ac3b05a1d
commit
db0eab0461
7 changed files with 105 additions and 38 deletions
|
@ -22,10 +22,7 @@ from auth.auth import process_oauth
|
|||
from endpoints.csrf import csrf_protect
|
||||
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()
|
||||
from util.pagination import encrypt_page_token, decrypt_page_token
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
api_bp = Blueprint('api', __name__)
|
||||
|
@ -221,28 +218,15 @@ def page_support(page_token_kwarg='page_token', parsed_args_kwarg='parsed_args')
|
|||
@wraps(func)
|
||||
@query_param('next_page', 'The page token for the next page', type=str)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
page_token = None
|
||||
|
||||
if kwargs[parsed_args_kwarg]['next_page']:
|
||||
# Decrypt the page token.
|
||||
unencrypted = decrypt_string(kwargs[parsed_args_kwarg]['next_page'],
|
||||
app.config['PAGE_TOKEN_KEY'],
|
||||
ttl=_PAGE_TOKEN_TTL)
|
||||
if unencrypted is not None:
|
||||
try:
|
||||
page_token = json.loads(unencrypted)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Note: if page_token is None, we'll receive the first page of results back.
|
||||
page_token = decrypt_page_token(kwargs[parsed_args_kwarg]['next_page'])
|
||||
kwargs[page_token_kwarg] = page_token
|
||||
|
||||
(result, next_page_token) = func(self, *args, **kwargs)
|
||||
if next_page_token is not None:
|
||||
result['next_page'] = encrypt_string(json.dumps(next_page_token),
|
||||
app.config['PAGE_TOKEN_KEY'])
|
||||
result['next_page'] = encrypt_page_token(next_page_token)
|
||||
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
return inner
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ def aggregated_log_view(log, kinds, start_time):
|
|||
if synthetic_date.day < start_time.day:
|
||||
synthetic_date = synthetic_date + relativedelta(months=1)
|
||||
|
||||
view = {
|
||||
view = {
|
||||
'kind': kinds[log.kind_id],
|
||||
'count': log.count,
|
||||
'datetime': format_date(synthetic_date),
|
||||
|
|
Reference in a new issue