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

Commit

Permalink
Merge ba33c94 into 117db8a
Browse files Browse the repository at this point in the history
  • Loading branch information
dryewo committed Feb 13, 2018
2 parents 117db8a + ba33c94 commit 93832b6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion piu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import zign.api
import re

from clickclick import error, AliasedGroup, print_table, OutputFormat
from clickclick import error, AliasedGroup, print_table, OutputFormat, warning
from .error_handling import handle_exceptions

import piu
Expand Down Expand Up @@ -146,6 +146,15 @@ def lookup_instance(region, ip_address):
return next(piu.utils.list_running_instances(region, filters), None)


def ssh_keys_added():
try:
# ssh-add -l exits with status 1 (and check_call throws) if there are no keys in the SSH agent
subprocess.check_call(['ssh-add', '-l'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
return True
except Exception:
return False


def _request_access(even_url, cacert, username, hostname, reason, remote_host,
lifetime, clip, connect, tunnel):
data = {'username': username, 'hostname': hostname, 'reason': reason}
Expand Down Expand Up @@ -181,6 +190,10 @@ def _request_access(even_url, cacert, username, hostname, reason, remote_host,
if connect or tunnel:
subprocess.call(command.split())

if not ssh_keys_added():
warning("No SSH identities found. Please add one using ssh-add, for example:")
warning('ssh-add ~/.ssh/id_rsa')

click.secho('You can access your server with the following command:')
click.secho(command)

Expand Down

0 comments on commit 93832b6

Please sign in to comment.