diff --git a/canarytools/models/canarytokens.py b/canarytools/models/canarytokens.py index 5a67f90..4424e04 100644 --- a/canarytools/models/canarytokens.py +++ b/canarytools/models/canarytokens.py @@ -6,6 +6,8 @@ import logging logger = logging.getLogger('canarytools') +CANARYTOKENS_PAGE_SIZE_LIMIT = 2500 + class CanaryTokens(object): def __init__(self, console): """Initialize CanaryToken @@ -137,8 +139,30 @@ def all(self, include_endpoints=True): >>> import canarytools >>> tokens = console.tokens.all() """ - params = {'include_endpoints': str(include_endpoints)} - return self.console.get('canarytokens/fetch', params, self.parse) + cursor = None + all_tokens = [] + + while True: + params = { + 'limit': CANARYTOKENS_PAGE_SIZE_LIMIT, + 'render_transients': str(include_endpoints), + } + + if cursor: + params['cursor'] = cursor + + response = self.console.get('canarytokens/paginate', params, parser=dict) + + all_tokens.extend( + CanaryToken.parse(self.console, token) + for token in response.get('canarytokens', []) + ) + + cursor = response.get('cursor', {}) + if not cursor: + break + + return all_tokens def parse(self, data): """Parse JSON data