Skip to content

Commit

Permalink
Port bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
aemous committed Oct 16, 2024
1 parent f11eb3d commit 0ed740b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
12 changes: 11 additions & 1 deletion awscli/botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def compute_client_args(self, service_model, client_config,
endpoint_bridge, region_name, endpoint_url,
is_secure, scoped_config):
service_name = service_model.endpoint_prefix
logger.debug(f'CLI ARGS.PY: {client_config.sigv4a_signing_region_set}')
protocol = service_model.metadata['protocol']
parameter_validation = True
if client_config and not client_config.parameter_validation:
Expand Down Expand Up @@ -222,6 +221,7 @@ def compute_client_args(self, service_model, client_config,
self._compute_retry_config(config_kwargs)
self._compute_request_compression_config(config_kwargs)
self._compute_user_agent_appid_config(config_kwargs)
self._compute_sigv4a_signing_region_set_config(config_kwargs)
s3_config = self.compute_s3_config(client_config)

is_s3_service = self._is_s3_service(service_name)
Expand Down Expand Up @@ -580,3 +580,13 @@ def _compute_user_agent_appid_config(self, config_kwargs):
f'maximum length of {USERAGENT_APPID_MAXLEN} characters.'
)
config_kwargs['user_agent_appid'] = user_agent_appid

def _compute_sigv4a_signing_region_set_config(self, config_kwargs):
sigv4a_signing_region_set = config_kwargs.get(
'sigv4a_signing_region_set'
)
if sigv4a_signing_region_set is None:
sigv4a_signing_region_set = self._config_store.get_config_variable(
'sigv4a_signing_region_set'
)
config_kwargs['sigv4a_signing_region_set'] = sigv4a_signing_region_set
4 changes: 0 additions & 4 deletions awscli/botocore/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def set_operation_specific_signer(context, signing_name, **kwargs):
authenticated at all, but can include other auth modes such as sigv4
without body signing.
"""
logger.debug(f'context: {context}')
auth_type = context.get('auth_type')

# Auth type will be None if the operation doesn't have a configured auth
Expand Down Expand Up @@ -221,13 +220,10 @@ def set_operation_specific_signer(context, signing_name, **kwargs):

def _resolve_sigv4a_region(context):
region = None
logger.debug(f'context: {context}')
if 'client_config' in context:
print(f'client config: {context["client_config"].sigv4a_signing_region_set}')
region = context['client_config'].sigv4a_signing_region_set
if not region and context.get('signing', {}).get('region'):
region = context['signing']['region']
logger.debug(f'BOTO REGION: {region}')
return region or '*'


Expand Down
5 changes: 0 additions & 5 deletions awscli/botocore/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def full_config(self):
:rtype: dict
"""
if self._config is None:
print(f'self._config IS NONE!')
try:
config_file = self.get_config_variable('config_file')
self._config = botocore.configloader.load_config(config_file)
Expand Down Expand Up @@ -814,7 +813,6 @@ def create_client(self, service_name, region_name=None,
"""
default_client_config = self.get_default_client_config()
print(f'DEFAULT CONFIG: {default_client_config.sigv4a_signing_region_set}')
# If a config is provided and a default config is set, then
# use the config resulting from merging the two.
if config is not None and default_client_config is not None:
Expand All @@ -826,8 +824,6 @@ def create_client(self, service_name, region_name=None,

region_name = self._resolve_region_name(region_name, config)

print(f'SESSION CREATE CLIENT: {config.sigv4a_signing_region_set}')

# Figure out the verify value base on the various
# configuration options.
if verify is None:
Expand Down Expand Up @@ -874,7 +870,6 @@ def create_client(self, service_name, region_name=None,
loader, endpoint_resolver, self.user_agent(), event_emitter,
response_parser_factory, exceptions_factory, config_store,
user_agent_creator=user_agent_creator)
print(f'scoped config: {self.get_scoped_config()}')
client = client_creator.create_client(
service_name=service_name, region_name=region_name,
is_secure=use_ssl, endpoint_url=endpoint_url, verify=verify,
Expand Down
4 changes: 0 additions & 4 deletions awscli/clidriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def create_clidriver(args=None):
args, _ = parser.parse_known_args(args)
debug = args.debug
session = botocore.session.Session()
print(f'ENV VAR: {os.environ["AWS_SIGV4A_SIGNING_REGION_SET"]}')
print(f'CLIDRIVER FULL CONFIG: {session.full_config}')
_set_user_agent_for_session(session)
load_plugins(session.full_config.get('plugins', {}),
event_hooks=session.get_component('event_emitter'))
Expand Down Expand Up @@ -975,8 +973,6 @@ def invoke(self, service_name, operation_name, parameters, parsed_globals):
value is returned.
"""
print('CLIDRIVER: ABOUT TO CREATE CLIENT')
print(f'full config: {self._session.full_config}')
client = self._session.create_client(
service_name, region_name=parsed_globals.region,
endpoint_url=parsed_globals.endpoint_url,
Expand Down
45 changes: 42 additions & 3 deletions tests/functional/botocore/test_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# language governing permissions and limitations under the License.
import pytest

from botocore.session import get_session
from botocore.config import Config
from tests import create_session, mock

# In the future, a service may have a list of credentials requirements where one
# signature may fail and others may succeed. e.g. a service may want to use bearer
Expand All @@ -31,7 +32,7 @@


def _all_test_cases():
session = get_session()
session = create_session()
loader = session.get_component('data_loader')

services = loader.list_available_services('service-2')
Expand Down Expand Up @@ -74,4 +75,42 @@ def assert_all_requirements_match(auth_config, message):
auth_requirements = set(
AUTH_TYPE_REQUIREMENTS[auth_type] for auth_type in auth_config
)
assert len(auth_requirements) == 1
assert len(auth_requirements) == 1, message


@pytest.mark.parametrize(
"client_config_val, env_var_val, config_file_val, expected",
[
("foo", "bar", "baz", "foo"),
("foo", None, None, "foo"),
(None, "foo", "bar", "foo"),
(None, None, "foo", "foo"),
("foo", None, "bar", "foo"),
(None, None, None, None),
],
)
def test_sigv4a_signing_region_set_config_from_environment(
client_config_val, env_var_val, config_file_val, expected, tmp_path
):
if config_file_val:
tmp_config_file_path = tmp_path / 'config'
tmp_config_file_path.write_text(
f'[default]\nsigv4a_signing_region_set={config_file_val}\n'
)
environ = {'AWS_CONFIG_FILE': str(tmp_config_file_path)}
else:
environ = {'AWS_CONFIG_FILE': "file-does-not-exist"}

if env_var_val:
environ['AWS_SIGV4A_SIGNING_REGION_SET'] = env_var_val

if client_config_val:
config = Config(sigv4a_signing_region_set=client_config_val)
else:
config = Config()

with mock.patch('os.environ', environ):
session = create_session()
session.config_filename = 'no-exist-foo'
s3 = session.create_client('s3', config=config)
assert s3.meta.config.sigv4a_signing_region_set == expected

0 comments on commit 0ed740b

Please sign in to comment.