[Zope-DB] Change connection objects outside of Zope
Matthew T. Kromer
matt@zope.com
Thu, 16 Aug 2001 11:07:59 -0400
Mark Langkau wrote:
>Hi,
>
>Thanks for the new list!
>
Whoohoo! You scored first post ;)
>Here's a general question about changing connect strings for any
>database adapter. We are using DCOracle2 Beta4 (about to upgrade to Beta
>5).
>
>How would I go about programmatically changing the connect string in a
>database connection object? In our production environment, we change our
>database passwords on a regular basis. It will become a pain to change
>all of the hard coded user/password strings in the connection objects.
>(There may not be a large number to change - but *remembering* to change
>them, and to find all of them will become a maintenance issue ;-)
>
I'd suggest there are two ways to think about the problem:
1) the brute force way you envision -- paw through the ZODB looking for
connections and tweak them
or
2) Contemplate extending the connection object to allow for external
connection parameterization.
Doing (1) isn't actually very hard -- its a matter of firing up python,
importing Zope, and either doing a recursive search (which can take a
while) or going to known locations to adjust objects. The downside of
doing that is that it's highly nonportable. But the gist of it (after
you import Zope) is to get the application as the root object, and then
traverse from the root object -- e.g. if R is the Root, and you want
'/myapp/MyDB' you get R.myapp.MyDB. After getting the object, you
modify it, and usually set its _p_changed flag to 1, then call
get_transaction().commit() to save the changes.
Here's a simple example:
import Zope
app = Zope.app()
oracle = app.sql.baneOracle # folder called "sql" connection
object named "baneOracle"
oracle.connection_string = "scott/tiger"
oracle._p_changed = 1
get_transaction().commit()
However, inasmuch as thats not all that tricky, I'd like to think more
about trying to satisfy authentication externally.
Anybody got a preferred mechanism for this?
>
>It would be great to have an external script that would look for the
>connection object, and if it finds a match for a username (or other
>parameters to ensure we're looking at the right thing), then change the
>password. We could have a script that changes the actual database
>account info, then call the script that would make the same change in
>Zope.
>
>That's the high level concept. Is anyone doing something like this? If
>this sounds like a reasonable idea, I could make a recipe request at
>ZopeLabs.
>
>Thanks,
>Mark
>
>
>
>
>_______________________________________________
>Zope-DB mailing list
>Zope-DB@zope.org
>http://lists.zope.org/mailman/listinfo/zope-db
>