]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/sql.py
Properly register salt values as random.
[wizard.git] / wizard / sql.py
index f19f5e3cbb6022881b614e22f747038f51b2373b..548d8a6d399c5b4cd897eb1337e7d732bb970a5f 100644 (file)
@@ -1,5 +1,7 @@
 import sqlalchemy
 import os
+import pkg_resources
+import copy
 
 from wizard import shell
 
@@ -14,10 +16,13 @@ def connect(url):
     meta.reflect()
     return meta
 
-def fill_url(url):
+def auth(url):
     """
     If the URL has a database name but no other values, it will
     use the global configuration, and then try the database name.
+
+    This function implements a plugin interface named
+    :ref:`wizard.sql.auth`.
     """
     if not url:
         return None
@@ -28,13 +33,12 @@ def fill_url(url):
     if any((url.host, url.username, url.password)):
         # don't try for defaults if a few of these were set
         return url
-    # this is hook stuff
-    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
+    for entry in pkg_resources.iter_entry_points("wizard.sql.auth"):
+        func = entry.load()
+        r = func(copy.copy(url))
+        print r
+        if r is not None:
+            return r
     env_dsn = os.getenv("WIZARD_DSN")
     if env_dsn:
         old_url = url