SF.net SVN: gar:[25425] csw/mgar/gar/v2/lib/python/rest.py

cgrzemba at users.sourceforge.net cgrzemba at users.sourceforge.net
Wed Dec 2 08:20:22 CET 2015


Revision: 25425
          http://sourceforge.net/p/gar/code/25425
Author:   cgrzemba
Date:     2015-12-02 07:20:21 +0000 (Wed, 02 Dec 2015)
Log Message:
-----------
reduce ssh get_password noise

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/rest.py

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2015-12-01 15:28:11 UTC (rev 25424)
+++ csw/mgar/gar/v2/lib/python/rest.py	2015-12-02 07:20:21 UTC (rev 25425)
@@ -551,10 +551,18 @@
 
 
 def GetUsernameAndPassword():
+  from base64 import b64decode, b64encode
   username = os.environ["LOGNAME"]
   password = None
   authfile = os.path.join('/etc/opt/csw/releases/auth', username)
+  lauthfile = os.path.join(os.environ["HOME"],'.auth_'+username)
   try:
+    with open(lauthfile, 'r') as af:
+      password = af.read().strip()
+      return username, b64decode(password)      
+  except IOError as e:
+    logging.debug("%s password not cached: %s", lauthfile, e)
+  try:
     with open(authfile, 'r') as af:
       password = af.read().strip()
   except IOError as e:
@@ -568,7 +576,10 @@
       password = stdout.strip()
     else:
       logging.debug('Failed running %r', args)
+  
+    with os.fdopen(os.open(lauthfile,os.O_WRONLY | os.O_CREAT, 0o600),"w") as af:
+      af.write(b64encode(password))
 
-  logging.debug('Could not find password for user %r.', username)
+  logging.debug('Looked for password for user %r.', username)
 
   return username, password

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list