Repository: dmwm/wmcore
Issue: REST.Auth

@amaltaro 
I got below errors [1] when I was running DBS with WMCore 1.2.3. The build was successful, but when I started DBS server, I got these errors. The Auth was introduced last month. I did not get why the building did not bring REST into the rpm. Please take a look. I will need this for the HG1907 release.
Thanks,
Yuyi



[1] Traceback (most recent call last):
  File "/data/srv/HG1906f/sw.yuyi/slc7_amd64_gcc630/cms/dbs3/3.10.0/lib/python2.7/site-packages/WMCore/WebTools/Root.py", line 35, in <module>
    from WMCore.WebTools.FrontEndAuth import FrontEndAuth, NullAuth
  File "/data/srv/HG1906f/sw.yuyi/slc7_amd64_gcc630/cms/dbs3/3.10.0/lib/python2.7/site-packages/WMCore/WebTools/FrontEndAuth.py", line 8, in <module>
    from WMCore.REST.Auth import get_user_info
ImportError: No module named REST.Auth
~                                            

Changed files:
src/python/WMCore/WebTools/FrontEndAuth.py, src/python/WMCore/WebTools/SecureDocumentation.py

diff --git a/src/python/WMCore/WebTools/FrontEndAuth.py b/src/python/WMCore/WebTools/FrontEndAuth.py
index 2a64a1a05..ea5de9b13 100644
--- a/src/python/WMCore/WebTools/FrontEndAuth.py
+++ b/src/python/WMCore/WebTools/FrontEndAuth.py
@@ -5,10 +5,16 @@ import hmac
 
 import cherrypy
 
-from WMCore.REST.Auth import get_user_info
 from Utils.Utilities import lowerCmsHeaders
 
-# -----------------------------------------------------------------------------
+
+def get_user_info():
+    """
+    Helper function to return user based information of the request
+    """
+    return cherrypy.request.user
+
+
 class FrontEndAuth(cherrypy.Tool):
     """
     Transparently allows a back-end cmsweb app to do
@@ -35,7 +41,7 @@ class FrontEndAuth(cherrypy.Tool):
         group = group or []
         site = site or []
         # Sets initial user information for this request
-        assert (getattr(cherrypy.request, "user", None) == None)
+        assert getattr(cherrypy.request, "user", None) is None
         cherrypy.request.user = {'dn': None,
                                  'method': None,
                                  'login': None,
@@ -56,7 +62,7 @@ class FrontEndAuth(cherrypy.Tool):
         """Read and verify the front-end headers, update the user
         dict with information about the authorized user."""
         headers = lowerCmsHeaders(cherrypy.request.headers)
-        user = cherrypy.request.user
+        user = get_user_info()
 
         if 'cms-auth-status' not in headers:
             # Non SSL request
@@ -81,7 +87,7 @@ class FrontEndAuth(cherrypy.Tool):
                     user['roles'][hkname] = {'site': set(), 'group': set()}
                     for r in headers[hk].split():
                         ste_or_grp, name = r.split(':')
-                        user['roles'][hkname][ste_or_grp].add(name);
+                        user['roles'][hkname][ste_or_grp].add(name)
 
         vfy = hmac.new(self.key, prefix + "#" + suffix, hashlib.sha1).hexdigest()
         if vfy != headers["cms-authn-hmac"]:
@@ -93,7 +99,7 @@ class FrontEndAuth(cherrypy.Tool):
     def check_authorization(self, role, group, site, authzfunc):
         """Format the authorization rules into lists and verify if the given
         user is allowed to access."""
-        if authzfunc == None:
+        if authzfunc is None:
             authzfunc = self.defaultAuth
 
         # TOFIX: put role, group and site into canonical form
@@ -132,7 +138,6 @@ class FrontEndAuth(cherrypy.Tool):
         return False
 
 
-# -------------------------------------------------------------------------------
 class NullAuth(cherrypy.Tool):
     def __init__(self, config):
         # Defines the hook point for cherrypy
@@ -150,10 +155,10 @@ class NullAuth(cherrypy.Tool):
         group = group or []
         site = site or []
         cherrypy.log.access_log.warning('NullAuth called for:')
-        cherrypy.log.access_log.warning('\\trole(s): %s \\n\\tgroup(s): %s \\n\\tsite(s): %s' % (role, group, site))
+        cherrypy.log.access_log.warning('\\trole(s): %s \\n\\tgroup(s): %s \\n\\tsite(s): %s', role, group, site)
 
         if authzfunc:
-            cherrypy.log.access_log.warning('\\tusing authorisation function %s' % authzfunc.__name__)
+            cherrypy.log.access_log.warning('\\tusing authorisation function %s', authzfunc.__name__)
         cherrypy.request.user = {'dn': 'None',
                                  'method': 'Null Auth - totally insecure!',
                                  'login': 'fbloggs',
diff --git a/src/python/WMCore/WebTools/SecureDocumentation.py b/src/python/WMCore/WebTools/SecureDocumentation.py
index 4bddcd231..f8b4d5817 100644
--- a/src/python/WMCore/WebTools/SecureDocumentation.py
+++ b/src/python/WMCore/WebTools/SecureDocumentation.py
@@ -1,13 +1,17 @@
-from cherrypy import expose, tools
 import cherrypy
-from WMCore.WebTools.Page import TemplatedPage
-from WMCore.REST.Auth import get_user_info
 from os import listdir
 
+from cherrypy import expose, tools
+
+from WMCore.WebTools.FrontEndAuth import get_user_info
+from WMCore.WebTools.Page import TemplatedPage
+
+
 class SecureDocumentation(TemplatedPage):
     """
     The documentation for the framework
     """
+
     @expose
     @tools.secmodv2()
     def index(self):
@@ -23,7 +27,7 @@ class SecureDocumentation(TemplatedPage):
         index += "<li>Your roles:\\n"
         index += "<ul>\\n"
         for k, v in user['roles'].iteritems():
-            for t in ['group','site']:
+            for t in ['group', 'site']:
                 for n in v[t]:
                     index += "<li><b>%s</b>: %s=%s</li>\\n" % (k, t, n)
         index += "</ul></li></ul>\\n"
@@ -35,8 +39,8 @@ class SecureDocumentation(TemplatedPage):
         for t in templates:
             if '.tmpl' in t:
                 index = "%s\\n<li><a href='%s'>%s</a></li>" % (index,
-                                                      t.replace('.tmpl', ''),
-                                                      t.replace('.tmpl', ''))
+                                                              t.replace('.tmpl', ''),
+                                                              t.replace('.tmpl', ''))
         index = "%s\\n<li><a href='https://twiki.cern.ch/twiki/bin/view/CMS/DMWebtools'>twiki</a>" % (index)
         index = "%s\\n</ol>" % (index)
 
@@ -61,5 +65,4 @@ class SecureDocumentation(TemplatedPage):
     def default(self, *args, **kwargs):
         if len(args) > 0:
             return self.templatepage(args[0])
-        else:
-            return self.index()
+        return self.index()