simple_ssl_context() is now a helper exposed in module sfa.util.ssl
[sfa.git] / sfa / client / manifolduploader.py
index e377c8d..510382f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # inspired from tophat/bin/uploadcredential.py
 #
 # so the defaults below are of no real importance
 # this for now points at demo.myslice.info, but sounds like a
 # better default for the long run
-DEFAULT_URL = "http://myslice.onelab.eu:7080"
-DEFAULT_PLATFORM = 'ple'
+import getpass
 
-# starting with 2.7.9 we need to turn off server verification
-import ssl
-try:
-    turn_off_server_verify = {'context': ssl._create_unverified_context()}
-except:
-    turn_off_server_verify = {}
+import xmlrpc.client
 
-import getpass
+from sfa.util.ssl import simple_ssl_context
 
-from sfa.util.py23 import xmlrpc_client
+DEFAULT_URL = "http://myslice.onelab.eu:7080"
+DEFAULT_PLATFORM = 'ple'
 
 
 class ManifoldUploader:
@@ -52,7 +47,7 @@ class ManifoldUploader:
 
     def username(self):
         if not self._username:
-            self._username = raw_input("Enter your manifold username: ")
+            self._username = input("Enter your manifold username: ")
         return self._username
 
     def password(self):
@@ -64,7 +59,7 @@ class ManifoldUploader:
 
     def platform(self):
         if not self._platform:
-            self._platform = raw_input(
+            self._platform = input(
                 "Enter your manifold platform [%s]: " % DEFAULT_PLATFORM)
             if self._platform.strip() == "":
                 self._platform = DEFAULT_PLATFORM
@@ -72,7 +67,7 @@ class ManifoldUploader:
 
     def url(self):
         if not self._url:
-            self._url = raw_input(
+            self._url = input(
                 "Enter the URL for your manifold API [%s]: " % DEFAULT_URL)
             if self._url.strip() == "":
                 self._url = DEFAULT_URL
@@ -88,17 +83,10 @@ class ManifoldUploader:
     # won't be happy with several calls issued in the same session
     # so we do not cache this one
     def proxy(self):
-        #        if not self._proxy:
-        #            url=self.url()
-        #            self.logger.info("Connecting manifold url %s"%url)
-        #            self._proxy = xmlrpc_client.ServerProxy(url, allow_none = True)
-        #        return self._proxy
         url = self.url()
         self.logger.debug("Connecting manifold url %s" % url)
-        proxy = xmlrpc_client.ServerProxy(url, allow_none=True,
-                                          **turn_off_server_verify)
-
-        return proxy
+        return xmlrpc.client.ServerProxy(url, allow_none=True,
+                                         context=simple_ssl_context())
 
     # does the job for one credential
     # expects the credential (string) and an optional message (e.g. hrn) for reporting
@@ -146,7 +134,7 @@ class ManifoldUploader:
             self.logger.info("  V2 Update returned code %s and error >>%s<<" % (
                 retcod2['code'], retcod2['description']))
             self.logger.debug("****** full retcod2")
-            for k, v in retcod2.items():
+            for k, v in list(retcod2.items()):
                 self.logger.debug("**** %s: %s" % (k, v))
             return False
         except Exception as e:
@@ -169,17 +157,22 @@ def main():
                         help="the filenames to upload")
     parser.add_argument('-u', '--url', dest='url', action='store', default=None,
                         help='the URL of the manifold API')
-    parser.add_argument('-p', '--platform', dest='platform', action='store', default=None,
+    parser.add_argument('-p', '--platform', dest='platform',
+                        action='store', default=None,
                         help='the manifold platform name')
-    parser.add_argument('-U', '--user', dest='username', action='store', default=None,
+    parser.add_argument('-U', '--user', dest='username',
+                        action='store', default=None,
                         help='the manifold username')
-    parser.add_argument('-P', '--password', dest='password', action='store', default=None,
+    parser.add_argument('-P', '--password', dest='password',
+                        action='store', default=None,
                         help='the manifold password')
-    parser.add_argument('-v', '--verbose', dest='verbose', action='count', default=0,
+    parser.add_argument('-v', '--verbose', dest='verbose',
+                        action='count', default=0,
                         help='more and more verbose')
     args = parser.parse_args()
 
-    from sfa.util.sfalogging import sfi_logger
+    from sfa.util.sfalogging import init_logger, logger as sfi_logger
+    init_logger('console')
     sfi_logger.enable_console()
     sfi_logger.setLevelFromOptVerbose(args.verbose)
     uploader = ManifoldUploader(url=args.url, platform=args.platform,