Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/dynamodb.py
1566 views
1
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import base64
14
import binascii
15
import logging
16
17
logger = logging.getLogger(__name__)
18
19
20
def register_dynamodb_paginator_fix(event_emitter):
21
DynamoDBPaginatorFix(event_emitter).register_events()
22
23
24
def parse_last_evaluated_key_binary(parsed, **kwargs):
25
# Because we disable parsing blobs into a binary type and leave them as
26
# a base64 string if a binary field is present in the continuation token
27
# as is the case with dynamodb the binary will be double encoded. This
28
# ensures that the continuation token is properly converted to binary to
29
# avoid double encoding the contination token.
30
last_evaluated_key = parsed.get('LastEvaluatedKey', None)
31
if last_evaluated_key is None:
32
return
33
for key, val in last_evaluated_key.items():
34
if 'B' in val:
35
val['B'] = base64.b64decode(val['B'])
36
37
38
class DynamoDBPaginatorFix(object):
39
def __init__(self, event_emitter):
40
self._event_emitter = event_emitter
41
42
def register_events(self):
43
self._event_emitter.register(
44
'calling-command.dynamodb.*', self._maybe_register_pagination_fix
45
)
46
47
def _maybe_register_pagination_fix(self, parsed_globals, **kwargs):
48
if parsed_globals.paginate:
49
self._event_emitter.register(
50
'after-call.dynamodb.*', parse_last_evaluated_key_binary
51
)
52
53