Skip to content

Commit

Permalink
Sigv4a signing region set config bugfix (#3279)
Browse files Browse the repository at this point in the history
Fixes a bug where the sigv4a_signing_region_set configuration in the config file and the corresponding environment variable would be ignored
---------

Co-authored-by: Nate Prewitt <nate.prewitt@gmail.com>
  • Loading branch information
SamRemis and nateprewitt authored Oct 16, 2024
1 parent 35d1020 commit b127e9b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Config-98372.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Config",
"description": "Fixed sigv4a_signing_region_set resolution when set in environment or config file."
}
11 changes: 11 additions & 0 deletions botocore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def compute_client_args(
self._compute_connect_timeout(config_kwargs)
self._compute_user_agent_appid_config(config_kwargs)
self._compute_request_compression_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 @@ -771,3 +772,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
52 changes: 49 additions & 3 deletions tests/functional/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,49 @@ 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


def get_config_file_path(base_path, value):
if value is None:
return "file-does-not-exist"

tmp_config_file_path = base_path / "config"
tmp_config_file_path.write_text(
f"[default]\nsigv4a_signing_region_set={value}\n"
)
return tmp_config_file_path


def get_environ_mock(
request,
env_var_value=None,
config_file_value=None,
):
base_path = request.getfixturevalue("tmp_path")
config_file_path = get_config_file_path(base_path, config_file_value)
return {
"AWS_CONFIG_FILE": str(config_file_path),
"AWS_SIGV4A_SIGNING_REGION_SET": env_var_value,
}


@pytest.mark.parametrize(
"client_config, env_var_val, config_file_val, expected",
[
(Config(sigv4a_signing_region_set="foo"), "bar", "baz", "foo"),
(Config(sigv4a_signing_region_set="foo"), None, None, "foo"),
(None, "bar", "baz", "bar"),
(None, None, "baz", "baz"),
(Config(sigv4a_signing_region_set="foo"), None, "baz", "foo"),
(None, None, None, None),
],
)
def test_sigv4a_signing_region_set_config_from_environment(
client_config, env_var_val, config_file_val, expected, request
):
environ_mock = get_environ_mock(request, env_var_val, config_file_val)
with mock.patch('os.environ', environ_mock):
session = create_session()
s3 = session.create_client('s3', config=client_config)
assert s3.meta.config.sigv4a_signing_region_set == expected

0 comments on commit b127e9b

Please sign in to comment.