Skip to content
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
15 changes: 13 additions & 2 deletions runpod/cli/groups/ssh/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import click
from prettytable import PrettyTable

from .functions import generate_ssh_key_pair, get_user_pub_keys
from .functions import add_ssh_key, generate_ssh_key_pair, get_user_pub_keys


class SSHGroup(click.Group):
Expand Down Expand Up @@ -69,7 +69,18 @@ def add_key(key, key_file):
Adds an SSH key to the current user account.
If no key is provided, one will be generated.
"""
if not key and not key_file:
if key_file:
with open(key_file, "r", encoding="utf-8") as f:
public_key = f.read().strip()
if not public_key:
raise click.ClickException("The specified key file is empty.")
add_ssh_key(public_key)
elif key:
public_key = key.strip()
if not public_key:
raise click.ClickException("The provided public key is empty.")
add_ssh_key(public_key)
else:
click.confirm("Would you like to add an SSH key to your account?", abort=True)
key_name = click.prompt(
"Please enter a name for this key", default="RunPod-Key", type=str
Expand Down