From 3727671ee573e970d80843f8b4f9e1d27e4c8846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Tue, 13 Jul 2010 11:37:53 +0200 Subject: [PATCH] Change AddAuthorizedKey to also allow filehandles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is required to use this function over paramiko sftp file handles. Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/utils.py b/lib/utils.py index f846f3b26..d1b461804 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -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: -- GitLab