Set the default region for the Resource Mapping Tool when no region is configured via AWS CLI (#2856)
Ensure a valid region is always present when generating resource mapping files.
This commit is contained in:
@@ -105,6 +105,8 @@ class ViewEditController(QObject):
|
||||
|
||||
def _create_new_config_file(self) -> None:
|
||||
configuration: Configuration = self._configuration_manager.configuration
|
||||
self._set_default_region(configuration)
|
||||
|
||||
try:
|
||||
new_config_file_path: str = file_utils.join_path(
|
||||
configuration.config_directory, constants.RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_NAME)
|
||||
@@ -117,6 +119,15 @@ class ViewEditController(QObject):
|
||||
|
||||
self._rescan_config_directory()
|
||||
|
||||
def _set_default_region(self, configuration: Configuration):
|
||||
default_region = configuration.region
|
||||
if not default_region or default_region == 'aws-global':
|
||||
self.set_notification_frame_text_sender.emit(
|
||||
notification_label_text.VIEW_EDIT_PAGE_CREATE_NEW_CONFIG_FILE_NO_DEFAULT_REGION_MESSAGE)
|
||||
logger.warning(notification_label_text.VIEW_EDIT_PAGE_CREATE_NEW_CONFIG_FILE_NO_DEFAULT_REGION_MESSAGE)
|
||||
|
||||
configuration.region = constants.RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_REGION
|
||||
|
||||
def _delete_table_row(self) -> None:
|
||||
indices: List[QModelIndex] = self._table_view.selectedIndexes()
|
||||
self._proxy_model.remove_resources(indices)
|
||||
|
||||
@@ -24,6 +24,7 @@ AWS_RESOURCE_REGIONS: List[str] = ["us-east-2", "us-east-1", "us-west-1", "us-we
|
||||
# Default client&server config file name
|
||||
RESOURCE_MAPPING_CONFIG_FILE_NAME_SUFFIX: str = "_aws_resource_mappings.json"
|
||||
RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_NAME: str = "default" + RESOURCE_MAPPING_CONFIG_FILE_NAME_SUFFIX
|
||||
RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_REGION: str = "us-east-1"
|
||||
|
||||
# View related constants
|
||||
SEARCH_TYPED_RESOURCES_VERSION: str = "Import AWS Resources"
|
||||
|
||||
@@ -5,6 +5,8 @@ For complete copyright and license terms please see the LICENSE at the root of t
|
||||
SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
"""
|
||||
|
||||
from model import constants
|
||||
|
||||
NOTIFICATION_LOADING_MESSAGE: str = "Loading..."
|
||||
|
||||
ERROR_PAGE_OK_TEXT: str = "OK"
|
||||
@@ -21,6 +23,12 @@ VIEW_EDIT_PAGE_RESCAN_TEXT: str = "Rescan"
|
||||
VIEW_EDIT_PAGE_CONFIG_FILES_PLACEHOLDER_TEXT: str = "Found {} config files"
|
||||
VIEW_EDIT_PAGE_SEARCH_PLACEHOLDER_TEXT: str = "Search by Key Name, Type, Name/ID, Account ID or Region"
|
||||
VIEW_EDIT_PAGE_IMPORT_RESOURCES_PLACEHOLDER_TEXT: str = "Import Additional Resources"
|
||||
VIEW_EDIT_PAGE_CREATE_NEW_CONFIG_FILE_NO_DEFAULT_REGION_MESSAGE: str = \
|
||||
f"Resource mapping file {constants.RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_NAME} is created"\
|
||||
f" with {constants.RESOURCE_MAPPING_DEFAULT_CONFIG_FILE_REGION} as the default region. "\
|
||||
f"See <a href=\"https://docs.o3de.org/docs/user-guide/gems/reference/aws/aws-core/configuring-credentials/\">"\
|
||||
f"<span style=\"color:#4A90E2;\">documentation</span></a> "\
|
||||
f"for configuring the AWS credentials and default region."
|
||||
|
||||
VIEW_EDIT_PAGE_SELECT_CONFIG_FILE_MESSAGE: str = "Please select the Config file you would like to view and modify..."
|
||||
VIEW_EDIT_PAGE_NO_CONFIG_FILE_FOUND_MESSAGE: str = \
|
||||
|
||||
+2
-1
@@ -482,6 +482,7 @@ class TestViewEditController(TestCase):
|
||||
mock_json_utils.create_empty_resource_mapping_file.assert_called_once()
|
||||
mock_file_utils.find_files_with_suffix_under_directory.assert_called_once()
|
||||
self._mocked_view_edit_page.set_config_files.assert_called_with(expected_config_files)
|
||||
self._test_view_edit_controller.set_notification_frame_text_sender.emit.assert_called_once()
|
||||
|
||||
@patch("controller.view_edit_controller.file_utils")
|
||||
@patch("controller.view_edit_controller.json_utils")
|
||||
@@ -496,7 +497,7 @@ class TestViewEditController(TestCase):
|
||||
mock_file_utils.join_path.assert_called_once()
|
||||
mock_json_utils.create_empty_resource_mapping_file.assert_called_once()
|
||||
mock_file_utils.find_files_with_suffix_under_directory.assert_not_called()
|
||||
self._test_view_edit_controller.set_notification_frame_text_sender.emit.assert_called_once()
|
||||
assert len(self._test_view_edit_controller.set_notification_frame_text_sender.emit.mock_calls) == 2
|
||||
|
||||
@patch("controller.view_edit_controller.file_utils")
|
||||
def test_page_rescan_button_post_notification_when_find_files_throw_exception(
|
||||
|
||||
Reference in New Issue
Block a user