Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolve #1519] PoC for centralised exception handling #1525

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions sceptre/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
import warnings
from typing import Optional, Dict, Tuple, Any

import boto3
import deprecation

import boto3
from botocore.credentials import Credentials
from botocore.exceptions import ClientError

from sceptre.exceptions import InvalidAWSCredentialsError, RetryLimitExceededError
from sceptre.exceptions import (
InvalidAWSCredentialsError,
RetryLimitExceededError,
SceptreException,
)
from sceptre.helpers import mask_key, create_deprecated_alias_property


Expand Down Expand Up @@ -463,8 +468,21 @@ def call(
if kwargs is None: # pragma: no cover
kwargs = {}

client = self._get_client(service, region, profile, stack_name, sceptre_role)
return getattr(client, command)(**kwargs)
# Centralised exception handling where he catch some confusing errors from the Boto3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he/we?

# client and send back hints on how to fix.
try:
client = self._get_client(
service, region, profile, stack_name, sceptre_role
)
return getattr(client, command)(**kwargs)
except ClientError as err:
if err.response["Error"]["Code"] == "ForbiddenException":
raise SceptreException(
"ForbiddenException: Confirm your current AWS profile is authenticated",
"and has the necessary access.",
) from err
else:
raise

def _coalesce_sceptre_role(self, iam_role: str, sceptre_role: str) -> str:
"""Evaluates the iam_role and sceptre_role parameters as passed to determine which value to
Expand Down