[LYN-4200] Fail and log error if required aws config file is not found (#1099)

This commit is contained in:
Vincent Liu
2021-06-03 10:59:11 -07:00
committed by GitHub
parent 54fdca353b
commit ba02652e63
4 changed files with 1261 additions and 1132 deletions
@@ -48,7 +48,8 @@ class ConfigurationManager(object):
def configuration(self, new_configuration: ConfigurationManager) -> None:
self._configuration = new_configuration
def setup(self, config_path: str) -> None:
def setup(self, config_path: str) -> bool:
result: bool = True
logger.info("Setting up default configuration ...")
try:
normalized_config_path: str = file_utils.normalize_file_path(config_path);
@@ -63,5 +64,7 @@ class ConfigurationManager(object):
self._configuration.account_id = aws_utils.get_default_account_id()
self._configuration.region = aws_utils.get_default_region()
except (RuntimeError, FileNotFoundError) as e:
logger.exception(e)
logger.error(e)
result = False
logger.debug(self._configuration)
return result
@@ -74,11 +74,18 @@ if __name__ == "__main__":
logger.warning("Failed to load style sheet for resource mapping tool")
logger.info("Initializing boto3 default session ...")
aws_utils.setup_default_session(arguments.profile)
try:
aws_utils.setup_default_session(arguments.profile)
except RuntimeError as error:
logger.error(error)
environment_utils.cleanup_qt_environment()
exit(-1)
logger.info("Initializing configuration manager ...")
configuration_manager: ConfigurationManager = ConfigurationManager()
configuration_manager.setup(arguments.config_path)
if not configuration_manager.setup(arguments.config_path):
environment_utils.cleanup_qt_environment()
exit(-1)
logger.info("Initializing thread manager ...")
thread_manager: ThreadManager = ThreadManager()
File diff suppressed because it is too large Load Diff
@@ -12,10 +12,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import boto3
from botocore.paginate import (PageIterator, Paginator)
from botocore.client import BaseClient
from botocore.exceptions import ClientError
from botocore.exceptions import (ClientError, ConfigNotFound, NoCredentialsError, ProfileNotFound)
from typing import Dict, List
from model import (constants, error_messages)
from model import error_messages
from model.basic_resource_attributes import (BasicResourceAttributes, BasicResourceAttributesBuilder)
"""
@@ -65,8 +65,11 @@ def _initialize_boto3_aws_client(service: str, region: str = "") -> BaseClient:
def setup_default_session(profile: str) -> None:
global default_session
default_session = boto3.session.Session(profile_name=profile)
try:
global default_session
default_session = boto3.session.Session(profile_name=profile)
except (ConfigNotFound, ProfileNotFound) as error:
raise RuntimeError(error)
def get_default_account_id() -> str:
@@ -76,6 +79,8 @@ def get_default_account_id() -> str:
except ClientError as error:
raise RuntimeError(error_messages.AWS_SERVICE_REQUEST_CLIENT_ERROR_MESSAGE.format(
"get_caller_identity", error.response['Error']['Code'], error.response['Error']['Message']))
except NoCredentialsError as error:
raise RuntimeError(error)
def get_default_region() -> str: