Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge 350be6a into e4afb7c
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunrn committed Mar 20, 2020
2 parents e4afb7c + 350be6a commit eb5a779
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion piu/cli.py
Expand Up @@ -420,7 +420,8 @@ def send_odd_ssh_key(ec2, odd_hostname: str, public_key: str) -> bool:
try:
odd_attributes = instance_attributes(ec2, "ip-address", odd_ip)
except RuntimeError as e:
print("Failed to find odd host {0:s}: {1:s}".format(odd_hostname), e)
print("Failed to find odd host {0:s} in current account".format(odd_hostname))
return False
return send_ssh_key("odd", odd_attributes, public_key)


Expand Down
14 changes: 14 additions & 0 deletions piu/error_handling.py
Expand Up @@ -26,6 +26,13 @@ def is_credentials_expired_error(e: ClientError) -> bool:
return e.response["Error"]["Code"] in ["ExpiredToken", "RequestExpired"]


def is_permissions_error(e: ClientError) -> bool:
return (
e.response["Error"]["Code"] == "AccessDeniedException"
and "ec2-instance-connect" in e.response["Error"]["Message"]
)


def handle_exceptions(func):
@functools.wraps(func)
def wrapper():
Expand All @@ -47,6 +54,13 @@ def wrapper():
file=sys.stderr,
)
sys.exit(1)
elif is_permissions_error(e):
print(
"Do you have permissions to use SSH in this account? If this is a Kubernetes account"
" please consider using alternate access methods as described in the documentation "
"https://cloud.docs.zalando.net/howtos/access-private-resources/"
)
sys.exit(1)
else:
file_name = store_exception(e)
print("Unknown Error.\n" "Please create an issue with the content of {fn}".format(fn=file_name))
Expand Down

0 comments on commit eb5a779

Please sign in to comment.