Skip to content

Commit

Permalink
paramiko
Browse files Browse the repository at this point in the history
  • Loading branch information
jiasli committed Oct 10, 2024
1 parent 5cbb8ef commit 8e9f1d6
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 195 deletions.
46 changes: 0 additions & 46 deletions src/azure-cli-core/azure/cli/core/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,3 @@ def is_valid_ssh_rsa_public_key(openssh_pubkey):
int_len = 4
str_len = struct.unpack('>I', data[:int_len])[0] # this should return 7
return data[int_len:int_len + str_len] == key_type.encode()


def generate_ssh_keys(private_key_filepath, public_key_filepath):
import paramiko
from paramiko.ssh_exception import PasswordRequiredException, SSHException

if os.path.isfile(public_key_filepath):
try:
with open(public_key_filepath, 'r') as public_key_file:
public_key = public_key_file.read()
pub_ssh_dir = os.path.dirname(public_key_filepath)
logger.warning("Public SSH key file '%s' already exists in the directory: '%s'. "
"New SSH key files will not be generated.",
public_key_filepath, pub_ssh_dir)

return public_key
except IOError as e:
raise CLIError(e)

ssh_dir = os.path.dirname(private_key_filepath)
if not os.path.exists(ssh_dir):
os.makedirs(ssh_dir)
os.chmod(ssh_dir, 0o700)

if os.path.isfile(private_key_filepath):
# try to use existing private key if it exists.
try:
key = paramiko.RSAKey(filename=private_key_filepath)
logger.warning("Private SSH key file '%s' was found in the directory: '%s'. "
"A paired public key file '%s' will be generated.",
private_key_filepath, ssh_dir, public_key_filepath)
except (PasswordRequiredException, SSHException, IOError) as e:
raise CLIError(e)

else:
# otherwise generate new private key.
key = paramiko.RSAKey.generate(2048)
key.write_private_key_file(private_key_filepath)
os.chmod(private_key_filepath, 0o600)

with open(public_key_filepath, 'w') as public_key_file:
public_key = '{} {}'.format(key.get_name(), key.get_base64())
public_key_file.write(public_key)
os.chmod(public_key_filepath, 0o644)

return public_key
148 changes: 0 additions & 148 deletions src/azure-cli-core/azure/cli/core/tests/test_keys.py

This file was deleted.

1 change: 0 additions & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
'msal[broker]==1.31.0',
'msrestazure~=0.6.4',
'packaging>=20.9',
'paramiko>=2.0.8,<4.0.0',
'pkginfo>=1.5.0.1',
# psutil can't install on cygwin: https://github.com/Azure/azure-cli/issues/9399
'psutil>=5.9; sys_platform != "cygwin"',
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
'javaproperties~=0.5.1',
'jsondiff~=2.0.0',
'packaging>=20.9',
'paramiko>=2.0.8,<4.0.0',
'pycomposefile>=0.0.29',
'PyGithub~=1.38',
'PyNaCl~=1.5.0',
Expand Down

0 comments on commit 8e9f1d6

Please sign in to comment.