]> scripts.mit.edu Git - wizard.git/blobdiff - plugins/scripts/wizard_scripts.py
Remove obsoleted function call.
[wizard.git] / plugins / scripts / wizard_scripts.py
index bce7b2b2a61d8c97c6756919d8379fec159f7d95..477efc1a5355c575cb3359558056d9cfc9008676 100644 (file)
@@ -11,27 +11,30 @@ import time
 import errno
 
 import wizard
-from wizard import shell, util
+from wizard import shell, util, user
 
-def deploy_web():
+def deploy_web(dir):
     # try the directory
     homedir, _, web_path = dir.partition("/web_scripts")
     if web_path:
+        name = user.passwd(dir).name
         yield urlparse.ParseResult(
                 "http",
-                util.get_dir_owner(homedir) + ".scripts.mit.edu",
+                name + ".scripts.mit.edu",
                 web_path.rstrip('/'),
                 "", "", "")
         yield urlparse.ParseResult(
                 "http",
                 "scripts.mit.edu",
-                "/~" + util.get_dir_owner(homedir) + web_path.rstrip('/'),
+                "/~" + name + web_path.rstrip('/'),
                 "", "", "")
+    else:
+        logging.info("Directory location did not contain web_scripts: %s", dir)
 
 def user_quota(dir=None):
     """
     Returns a tuple (quota usage, quota limit).  Works only for scripts
-    servers.  Values are in KiB.  Returns ``(0, None)`` if we couldn't figure it out.
+    servers.  Values are in bytes.  Returns ``(0, None)`` if we couldn't figure it out.
     """
     end = 2
     # sometimes the volume is busy; so we try several times
@@ -82,9 +85,10 @@ def _user_quota(dir=None):
             return unknown
     except shell.CallError:
         return unknown
+    logging.debug("vos examine output was:\n\n" + "\n".join(result))
     try:
-        usage = int(result[0].split()[3])
-        limit = int(result[3].split()[1]) # XXX: FRAGILE
+        usage = int(result[0].split()[3]) * 1024
+        limit = int(result[3].split()[1]) * 1024 # XXX: FRAGILE
     except ValueError:
         raise QuotaParseError("vos examine output was:\n\n" + "\n".join(result))
     return (usage, limit)
@@ -98,3 +102,51 @@ class QuotaParseError(wizard.Error):
 
 ERROR: Could not parse quota. %s
 """ % self.msg
+
+def sql_auth(url):
+    if url.driver == "mysql":
+        try:
+            url.host, url.username, url.password = shell.Shell().eval("/mit/scripts/sql/bin/get-password").split()
+            return url
+        except shell.CallError:
+            pass
+    return None
+
+def user_email(name):
+    # XXX: simplistic strategy which doesn't work most of the time
+    return "%s@scripts.mit.edu" % name
+
+def user_operator():
+    """
+    Returns username of the person operating this script based
+    off of the :envvar:`SSH_GSSAPI_NAME` environment variable.
+
+    .. note::
+
+        :envvar:`SSH_GSSAPI_NAME` is not set by a vanilla OpenSSH
+        distributions.  Scripts servers are patched to support this
+        environment variable.
+    """
+    principal = os.getenv("SSH_GSSAPI_NAME")
+    if not principal:
+        return None
+    instance, _, _ = principal.partition("@")
+    if instance.endswith("/root"):
+        username, _, _ = principal.partition("/")
+    else:
+        username = instance
+    return username
+
+def user_passwd(dir, uid):
+    # XXX: simplistic heuristic for detecting AFS.  The correct thing to
+    # is either to statfs and match magic number, use one of the
+    # vos tools or check mounted directories.
+    if not dir.startswith("/afs/"):
+        return None
+    try:
+        result = shell.eval("hesinfo %d uid", uid)
+    except shell.CallError:
+        return None
+    name, password, uid, gid, gecos, homedir, shell = result.split(":")
+    realname = gecos.split(",")[0]
+    return user.Info(name, uid, gid, realname, homedir, shell)