Skip to content

Commit 6715c0f

Browse files
committed
Add generic support for client context params to vendored botocore.
1 parent 569b4fe commit 6715c0f

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
@@ -12,6 +12,7 @@
1212
# language governing permissions and limitations under the License.
1313
import inspect
1414

15+
from botocore import xform_name
1516
from botocore.compat import OrderedDict
1617
from botocore.docs.example import ResponseExampleDocumenter
1718
from botocore.docs.method import (
@@ -308,3 +309,56 @@ def _add_response_params(self, section, shape):
308309
shape,
309310
include=[self._GENERIC_ERROR_SHAPE],
310311
)
312+
313+
314+
class ClientContextParamsDocumenter:
315+
_CONFIG_GUIDE_LINK = (
316+
'https://boto3.amazonaws.com/'
317+
'v1/documentation/api/latest/guide/configuration.html'
318+
)
319+
320+
OMITTED_CONTEXT_PARAMS = {
321+
's3': (
322+
'Accelerate',
323+
'DisableMultiRegionAccessPoints',
324+
'ForcePathStyle',
325+
'UseArnRegion',
326+
),
327+
's3control': ('UseArnRegion',),
328+
}
329+
330+
def __init__(self, service_name, context_params):
331+
self._service_name = service_name
332+
self._context_params = context_params
333+
334+
def document_context_params(self, section):
335+
self._add_title(section)
336+
self._add_overview(section)
337+
self._add_context_params_list(section)
338+
339+
def _add_title(self, section):
340+
section.style.h2('Client Context Parameters')
341+
342+
def _add_overview(self, section):
343+
section.style.new_line()
344+
section.write(
345+
'Client context parameters are configurable on a client '
346+
'instance via the ``client_context_params`` parameter in the '
347+
'``Config`` object. For more detailed instructions and examples '
348+
'on the exact usage of context params see the '
349+
)
350+
section.style.external_link(
351+
title='configuration guide',
352+
link=self._CONFIG_GUIDE_LINK,
353+
)
354+
section.write('.')
355+
section.style.new_line()
356+
357+
def _add_context_params_list(self, section):
358+
section.style.new_line()
359+
sn = f'``{self._service_name}``'
360+
section.writeln(f'The available {sn} client context params are:')
361+
for param in self._context_params:
362+
section.style.new_line()
363+
name = f'``{xform_name(param.name)}``'
364+
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
@@ -38,6 +42,7 @@ def __init__(self, service_name, session):
3842
'client-exceptions',
3943
'paginator-api',
4044
'waiter-api',
45+
'client-context-params',
4146
]
4247

4348
def document_service(self):
@@ -54,6 +59,10 @@ def document_service(self):
5459
self.client_exceptions(doc_structure.get_section('client-exceptions'))
5560
self.paginator_api(doc_structure.get_section('paginator-api'))
5661
self.waiter_api(doc_structure.get_section('waiter-api'))
62+
context_params_section = doc_structure.get_section(
63+
'client-context-params'
64+
)
65+
self.client_context_params(context_params_section)
5766
return doc_structure.flush_structure()
5867

5968
def title(self, section):
@@ -104,3 +113,17 @@ def get_examples(self, service_name):
104113
loader = self._session.get_component('data_loader')
105114
examples = loader.load_service_model(service_name, 'examples-1')
106115
return examples['examples']
116+
117+
def client_context_params(self, section):
118+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
119+
params_to_omit = omitted_params.get(self._service_name, [])
120+
service_model = self._client.meta.service_model
121+
raw_context_params = service_model.client_context_parameters
122+
context_params = [
123+
p for p in raw_context_params if p.name not in params_to_omit
124+
]
125+
if context_params:
126+
context_param_documenter = ClientContextParamsDocumenter(
127+
self._service_name, context_params
128+
)
129+
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
@@ -74,3 +76,23 @@ def test_copy_source_param_docs_also_modified(self):
7476
self.assert_contains_line(
7577
"You can also provide this value as a dictionary", param_docs
7678
)
79+
80+
def test_s3_context_params_omitted(self):
81+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
82+
s3_omitted_params = omitted_params['s3']
83+
content = ServiceDocumenter(
84+
's3', self._session, self.root_services_path
85+
).document_service()
86+
for param in s3_omitted_params:
87+
param_name = f'``{xform_name(param)}``'
88+
self.assert_not_contains_line(param_name, content)
89+
90+
def test_s3control_context_params_omitted(self):
91+
omitted_params = ClientContextParamsDocumenter.OMITTED_CONTEXT_PARAMS
92+
s3control_omitted_params = omitted_params['s3control']
93+
content = ServiceDocumenter(
94+
's3control', self._session, self.root_services_path
95+
).document_service()
96+
for param in s3control_omitted_params:
97+
param_name = f'``{xform_name(param)}``'
98+
self.assert_not_contains_line(param_name, content)

0 commit comments

Comments
 (0)