Skip to content

Commit faa07dc

Browse files
authored
[v2] Add generic support for client context params to vendored botocore (#10126)
1 parent 4c1c85b commit faa07dc

8 files changed

Lines changed: 306 additions & 38 deletions

File tree

awscli/botocore/args.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def compute_client_args(
266266
disable_request_compression=(
267267
client_config.disable_request_compression
268268
),
269+
client_context_params=client_config.client_context_params,
269270
user_agent_extra=client_config.user_agent_extra,
270271
user_agent_appid=client_config.user_agent_appid,
271272
sigv4a_signing_region_set=(
@@ -577,14 +578,16 @@ def _build_endpoint_resolver(
577578
credentials=credentials,
578579
account_id_endpoint_mode=account_id_endpoint_mode,
579580
)
580-
# botocore does not support client context parameters generically
581-
# for every service. Instead, the s3 config section entries are
582-
# available as client context parameters. In the future, endpoint
583-
# rulesets of services other than s3/s3control may require client
584-
# context parameters.
585-
client_context = (
586-
s3_config_raw if self._is_s3_service(service_name_raw) else {}
587-
)
581+
# Client context params for s3 conflict with the available settings
582+
# in the `s3` parameter on the `Config` object. If the same parameter
583+
# is set in both places, the value in the `s3` parameter takes priority.
584+
if client_config is not None:
585+
client_context = client_config.client_context_params or {}
586+
else:
587+
client_context = {}
588+
if self._is_s3_service(service_name_raw):
589+
client_context.update(s3_config_raw)
590+
588591
sig_version = (
589592
client_config.signature_version
590593
if client_config is not None

awscli/botocore/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ class Config:
193193
194194
Defaults to None.
195195
196+
:type client_context_params: dict
197+
:param client_context_params: A dictionary of parameters specific to
198+
individual services. If available, valid parameters can be found in
199+
the ``Client Context Parameters`` section of the service client's
200+
documentation. Invalid parameters or ones that are not used by the
201+
specified service will be ignored.
202+
203+
Defaults to None.
204+
196205
:type sigv4a_signing_region_set: string
197206
:param sigv4a_signing_region_set: A set of AWS regions to apply the signature for
198207
when using SigV4a for signing. Set to ``*`` to represent all regions.
@@ -272,6 +281,7 @@ class Config:
272281
('ignore_configured_endpoint_urls', None),
273282
('request_min_compression_size_bytes', None),
274283
('disable_request_compression', None),
284+
('client_context_params', None),
275285
('sigv4a_signing_region_set', None),
276286
('request_checksum_calculation', None),
277287
('response_checksum_validation', None),

awscli/botocore/docs/client.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import inspect
1414
import os
1515

16+
from botocore import xform_name
1617
from botocore.compat import OrderedDict
1718
from botocore.docs.bcdoc.restdoc import DocumentStructure
1819
from botocore.docs.example import ResponseExampleDocumenter
@@ -376,3 +377,56 @@ def _add_response_params(self, section, shape):
376377
shape,
377378
include=[self._GENERIC_ERROR_SHAPE],
378379
)
380+
381+
382+
class ClientContextParamsDocumenter:
383+
_CONFIG_GUIDE_LINK = (
384+
'https://boto3.amazonaws.com/'
385+
'v1/documentation/api/latest/guide/configuration.html'
386+
)
387+
388+
OMITTED_CONTEXT_PARAMS = {
389+
's3': (
390+
'Accelerate',
391+
'DisableMultiRegionAccessPoints',
392+
'ForcePathStyle',
393+
'UseArnRegion',
394+
),
395+
's3control': ('UseArnRegion',),
396+
}
397+
398+
def __init__(self, service_name, context_params):
399+
self._service_name = service_name
400+
self._context_params = context_params
401+
402+
def document_context_params(self, section):
403+
self._add_title(section)
404+
self._add_overview(section)
405+
self._add_context_params_list(section)
406+
407+
def _add_title(self, section):
408+
section.style.h2('Client Context Parameters')
409+
410+
def _add_overview(self, section):
411+
section.style.new_line()
412+
section.write(
413+
'Client context parameters are configurable on a client '
414+
'instance via the ``client_context_params`` parameter in the '
415+
'``Config`` object. For more detailed instructions and examples '
416+
'on the exact usage of context params see the '
417+
)
418+
section.style.external_link(
419+
title='configuration guide',
420+
link=self._CONFIG_GUIDE_LINK,
421+
)
422+
section.write('.')
423+
section.style.new_line()
424+
425+
def _add_context_params_list(self, section):
426+
section.style.new_line()
427+
sn = f'``{self._service_name}``'
428+
section.writeln(f'The available {sn} client context params are:')
429+
for param in self._context_params:
430+
section.style.new_line()
431+
name = f'``{xform_name(param.name)}``'
432+
section.write(f'* {name} ({param.type}) - {param.documentation}')

awscli/botocore/docs/service.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
1313
from botocore.docs.bcdoc.restdoc import DocumentStructure
14-
from botocore.docs.client import ClientDocumenter, ClientExceptionsDocumenter
14+
from botocore.docs.client import (
15+
ClientContextParamsDocumenter,
16+
ClientDocumenter,
17+
ClientExceptionsDocumenter,
18+
)
1519
from botocore.docs.paginator import PaginatorDocumenter
1620
from botocore.docs.utils import get_official_service_name
1721
from botocore.docs.waiter import WaiterDocumenter
@@ -39,6 +43,7 @@ def __init__(self, service_name, session, root_docs_path):
3943
'client-exceptions',
4044
'paginator-api',
4145
'waiter-api',
46+
'client-context-params',
4247
]
4348

4449
def document_service(self):
@@ -55,6 +60,10 @@ def document_service(self):
5560
self.client_exceptions(doc_structure.get_section('client-exceptions'))
5661
self.paginator_api(doc_structure.get_section('paginator-api'))
5762
self.waiter_api(doc_structure.get_section('waiter-api'))
63+
context_params_section = doc_structure.get_section(
64+
'client-context-params'
65+
)
66+
self.client_context_params(context_params_section)
5867
return doc_structure.flush_structure()
5968

6069
def title(self, section):
@@ -110,3 +119,17 @@ def get_examples(self, service_name):
110119
loader = self._session.get_component('data_loader')
111120
examples = loader.load_service_model(service_name, 'examples-1')
112121
return examples['examples']
122+
123+
def client_context_params(self, section):
124+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
125+
params_to_omit = omitted_params.get(self._service_name, [])
126+
service_model = self._client.meta.service_model
127+
raw_context_params = service_model.client_context_parameters
128+
context_params = [
129+
p for p in raw_context_params if p.name not in params_to_omit
130+
]
131+
if context_params:
132+
context_param_documenter = ClientContextParamsDocumenter(
133+
self._service_name, context_params
134+
)
135+
context_param_documenter.document_context_params(section)

tests/functional/botocore/docs/test_s3.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
from botocore import xform_name
14+
from botocore.docs.client import ClientContextParamsDocumenter
1315
from botocore.docs.service import ServiceDocumenter
1416

1517
from tests.functional.botocore.docs import BaseDocsFunctionalTest
@@ -79,3 +81,23 @@ def test_copy_source_param_docs_also_modified(self):
7981
self.assert_contains_line(
8082
"You can also provide this value as a dictionary", param_docs
8183
)
84+
85+
def test_s3_context_params_omitted(self):
86+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
87+
s3_omitted_params = omitted_params['s3']
88+
content = ServiceDocumenter(
89+
's3', self._session, self.root_services_path
90+
).document_service()
91+
for param in s3_omitted_params:
92+
param_name = f'``{xform_name(param)}``'
93+
self.assert_not_contains_line(param_name, content)
94+
95+
def test_s3control_context_params_omitted(self):
96+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
97+
s3control_omitted_params = omitted_params['s3control']
98+
content = ServiceDocumenter(
99+
's3control', self._session, self.root_services_path
100+
).document_service()
101+
for param in s3control_omitted_params:
102+
param_name = f'``{xform_name(param)}``'
103+
self.assert_not_contains_line(param_name, content)

0 commit comments

Comments
 (0)