Skip to content

Commit 742df86

Browse files
authored
Merge pull request #2554 from joguSD/hide-presigned
Hide generate_presigned_url for all clients but S3
2 parents 9fdb83b + 135cc88 commit 742df86

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

botocore/docs/client.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@
2121
from botocore.compat import OrderedDict
2222

2323

24+
def _allowlist_generate_presigned_url(method_name, service_name, **kwargs):
25+
if method_name != 'generate_presigned_url':
26+
return None
27+
return service_name in ['s3']
28+
29+
2430
class ClientDocumenter(object):
31+
_CLIENT_METHODS_FILTERS = [
32+
_allowlist_generate_presigned_url,
33+
]
34+
2535
def __init__(self, client, shared_examples=None):
2636
self._client = client
2737
self._shared_examples = shared_examples
@@ -36,10 +46,36 @@ def document_client(self, section):
3646
"""
3747
self._add_title(section)
3848
self._add_class_signature(section)
39-
client_methods = get_instance_public_methods(self._client)
49+
client_methods = self._get_client_methods()
4050
self._add_client_intro(section, client_methods)
4151
self._add_client_methods(section, client_methods)
4252

53+
def _get_client_methods(self):
54+
client_methods = get_instance_public_methods(self._client)
55+
return self._filter_client_methods(client_methods)
56+
57+
def _filter_client_methods(self, client_methods):
58+
filtered_methods = {}
59+
for method_name, method in client_methods.items():
60+
include = self._filter_client_method(
61+
method=method,
62+
method_name=method_name,
63+
service_name=self._service_name,
64+
)
65+
if include:
66+
filtered_methods[method_name] = method
67+
return filtered_methods
68+
69+
def _filter_client_method(self, **kwargs):
70+
# Apply each filter to the method
71+
for filter in self._CLIENT_METHODS_FILTERS:
72+
filter_include = filter(**kwargs)
73+
# Use the first non-None value returned by any of the filters
74+
if filter_include is not None:
75+
return filter_include
76+
# Otherwise default to including it
77+
return True
78+
4379
def _add_title(self, section):
4480
section.style.h2('Client')
4581

tests/functional/docs/test_s3.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def test_hides_content_md5_when_impossible_to_provide(self):
4343
self.assertNotIn('ContentMD5=\'string\'',
4444
method_contents.decode('utf-8'))
4545

46+
def test_generate_presigned_url_documented(self):
47+
content = self.get_docstring_for_method('s3', 'generate_presigned_url')
48+
self.assert_contains_line('generate_presigned_url', content)
49+
4650
def test_copy_source_documented_as_union_type(self):
4751
content = self.get_docstring_for_method('s3', 'copy_object')
4852
dict_form = (
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2021 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+
from botocore.docs.service import ServiceDocumenter
14+
from tests.functional.docs import BaseDocsFunctionalTest
15+
16+
17+
class TestSecretsManagerDocs(BaseDocsFunctionalTest):
18+
def test_generate_presigned_url_is_not_documented(self):
19+
documenter = ServiceDocumenter('secretsmanager', self._session)
20+
docs = documenter.document_service()
21+
self.assert_not_contains_line('generate_presigned_url', docs)

0 commit comments

Comments
 (0)