Skip to content

Commit e8afc60

Browse files
Merge commit '952d073e8ea55e4a68c6772e443807d86e5a0590' into stage-release-develop
* commit '952d073e8ea55e4a68c6772e443807d86e5a0590': Add pagination backcompat for kinesis list-streams
2 parents 485d36b + 952d073 commit e8afc60

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

awscli/customizations/kinesis.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 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+
14+
15+
def register_kinesis_list_streams_pagination_backcompat(event_emitter):
16+
# The ListStreams previously used the ExclusiveStartStreamName parameter
17+
# for input tokens to pagination. This operation was then updated to
18+
# also allow for the typical NextToken input and output parameters. The
19+
# pagination model was also updated to use the NextToken field instead of
20+
# the ExclusiveStartStreamName field for input tokens. However, the
21+
# ExclusiveStartStreamName is still a valid parameter to control pagination
22+
# of this operation and is incompatible with the NextToken parameter. So,
23+
# the CLI needs to continue to treat the ExclusiveStartStreamName as if it
24+
# is a raw input token parameter to the API by disabling auto-pagination if
25+
# provided. Otherwise, if it was treated as a normal API parameter, errors
26+
# would be thrown when paginating across multiple pages since the parameter
27+
# is incompatible with the NextToken parameter.
28+
event_emitter.register(
29+
'building-argument-table.kinesis.list-streams',
30+
undocument_exclusive_start_stream_name,
31+
)
32+
event_emitter.register(
33+
'operation-args-parsed.kinesis.list-streams',
34+
disable_pagination_when_exclusive_start_stream_name_provided,
35+
)
36+
37+
38+
def undocument_exclusive_start_stream_name(argument_table, **kwargs):
39+
argument_table['exclusive-start-stream-name']._UNDOCUMENTED = True
40+
41+
42+
def disable_pagination_when_exclusive_start_stream_name_provided(
43+
parsed_args, parsed_globals, **kwargs
44+
):
45+
if parsed_args.exclusive_start_stream_name is not None:
46+
parsed_globals.paginate = False

awscli/handlers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
from awscli.customizations.sms_voice import register_sms_voice_hide
9393
from awscli.customizations.dynamodb import register_dynamodb_paginator_fix
9494
from awscli.customizations.overridesslcommonname import register_override_ssl_common_name
95+
from awscli.customizations.kinesis import \
96+
register_kinesis_list_streams_pagination_backcompat
9597

9698

9799
def awscli_initialize(event_handlers):
@@ -185,3 +187,4 @@ def awscli_initialize(event_handlers):
185187
register_sms_voice_hide(event_handlers)
186188
register_dynamodb_paginator_fix(event_handlers)
187189
register_override_ssl_common_name(event_handlers)
190+
register_kinesis_list_streams_pagination_backcompat(event_handlers)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2022 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 json
14+
15+
from awscli.testutils import BaseAWSCommandParamsTest, BaseAWSHelpOutputTest
16+
17+
18+
class TestListStreams(BaseAWSCommandParamsTest):
19+
20+
prefix = ['kinesis', 'list-streams']
21+
22+
def test_exclusive_start_stream_name_disables_auto_pagination(self):
23+
cmdline = self.prefix + ['--exclusive-start-stream-name', 'stream-1']
24+
self.parsed_responses = [
25+
{
26+
'StreamNames': ['stream-1', 'stream-2'],
27+
'StreamSummaries': [
28+
{'StreamName': 'stream-1'},
29+
{'StreamName': 'stream-2'},
30+
],
31+
'HasMoreStreams': True,
32+
'NextToken': 'token',
33+
}
34+
]
35+
expected_params = {'ExclusiveStartStreamName': 'stream-1'}
36+
stdout, _, _ = self.assert_params_for_cmd(cmdline, expected_params)
37+
output = json.dumps(stdout)
38+
self.assertIn('NextToken', output)
39+
self.assertIn('HasMoreStreams', output)
40+
41+
def test_exclusive_start_stream_name_incompatible_with_page_args(self):
42+
cmdline = self.prefix + ['--exclusive-start-stream-name', 'stream-1']
43+
cmdline += ['--page-size', '1']
44+
_, stderr, _ = self.run_cmd(cmdline, expected_rc=255)
45+
self.assertIn('Error during pagination: Cannot specify', stderr)
46+
self.assertIn('--page-size', stderr)
47+
48+
49+
class TestListStreamsHelp(BaseAWSHelpOutputTest):
50+
def test_exclusive_start_stream_name_is_undocumented(self):
51+
self.driver.main(['kinesis', 'list-streams', 'help'])
52+
self.assert_not_contains('--exclusive-start-steam-name')

0 commit comments

Comments
 (0)