Commit 3727671e authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Change AddAuthorizedKey to also allow filehandles



This is required to use this function over paramiko
sftp file handles.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 2a73861a
......@@ -1338,18 +1338,22 @@ def ParseCpuMask(cpu_mask):
return cpu_list
def AddAuthorizedKey(file_name, key):
def AddAuthorizedKey(file_obj, key):
"""Adds an SSH public key to an authorized_keys file.
@type file_name: str
@param file_name: path to authorized_keys file
@type file_obj: str or file handle
@param file_obj: path to authorized_keys file
@type key: str
@param key: string containing key
"""
key_fields = key.split()
f = open(file_name, 'a+')
if isinstance(file_obj, basestring):
f = open(file_obj, 'a+')
else:
f = file_obj
try:
nl = True
for line in f:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment