[Pypi-checkins] r992 - in trunk/pypi: . tools

martin.von.loewis python-checkins at python.org
Sun Nov 20 22:20:20 CET 2011


Author: martin.von.loewis
Date: Sun Nov 20 22:20:20 2011
New Revision: 992

Added:
   trunk/pypi/tools/sql-migrate-20111120.sql   (contents, props changed)
Modified:
   trunk/pypi/pkgbase_schema.sql
   trunk/pypi/store.py
   trunk/pypi/webui.py
Log:
Use SQL store for associations.


Modified: trunk/pypi/pkgbase_schema.sql
==============================================================================
--- trunk/pypi/pkgbase_schema.sql	(original)
+++ trunk/pypi/pkgbase_schema.sql	Sun Nov 20 22:20:20 2011
@@ -293,4 +293,25 @@
   CONSTRAINT openid_whitelist__pkey PRIMARY KEY (name, trust_root)
 );
 
+-- tables for the python-openid library, using default table names
+CREATE TABLE oid_nonces
+(
+   server_url VARCHAR(2047) NOT NULL,
+   timestamp INTEGER NOT NULL,
+   salt CHAR(40) NOT NULL,
+   PRIMARY KEY (server_url, timestamp, salt)
+);
+
+CREATE TABLE oid_associations
+(
+   server_url VARCHAR(2047) NOT NULL,
+   handle VARCHAR(255) NOT NULL,
+   secret BYTEA NOT NULL,
+   issued INTEGER NOT NULL,
+   lifetime INTEGER NOT NULL,
+   assoc_type VARCHAR(64) NOT NULL,
+   PRIMARY KEY (server_url, handle),
+   CONSTRAINT secret_length_constraint CHECK (LENGTH(secret) <= 128)
+);
+
 commit;

Modified: trunk/pypi/store.py
==============================================================================
--- trunk/pypi/store.py	(original)
+++ trunk/pypi/store.py	Sun Nov 20 22:20:20 2011
@@ -20,6 +20,7 @@
 # csrf modules
 import hmac
 from base64 import b64encode
+import openid.store.sqlstore
 
 def enumerate(sequence):
     return [(i, sequence[i]) for i in range(len(sequence))]
@@ -2019,6 +2020,11 @@
 
         cursor = self._cursor = self._conn.cursor()
 
+    def oid_store(self):
+        if self.config.database_driver == 'sqlite3':
+            return openid.store.sqlstore.SQLiteStore(self._conn)
+        return openid.store.sqlstore.PostgreSQLStore(self._conn)
+
     def force_close(self):
         '''Force closure of the current persistent connection.
         '''

Added: trunk/pypi/tools/sql-migrate-20111120.sql
==============================================================================
--- (empty file)
+++ trunk/pypi/tools/sql-migrate-20111120.sql	Sun Nov 20 22:20:20 2011
@@ -0,0 +1,23 @@
+begin;
+CREATE TABLE oid_nonces
+(
+   server_url VARCHAR(2047) NOT NULL,
+   timestamp INTEGER NOT NULL,
+   salt CHAR(40) NOT NULL,
+   PRIMARY KEY (server_url, timestamp, salt)
+);
+
+CREATE TABLE oid_associations
+(
+   server_url VARCHAR(2047) NOT NULL,
+   handle VARCHAR(255) NOT NULL,
+   secret BYTEA NOT NULL,
+   issued INTEGER NOT NULL,
+   lifetime INTEGER NOT NULL,
+   assoc_type VARCHAR(64) NOT NULL,
+   PRIMARY KEY (server_url, handle),
+   CONSTRAINT secret_length_constraint CHECK (LENGTH(secret) <= 128)
+);
+
+GRANT ALL ON oid_nonces, oid_associations TO pypi;
+commit;

Modified: trunk/pypi/webui.py
==============================================================================
--- trunk/pypi/webui.py	(original)
+++ trunk/pypi/webui.py	Sun Nov 20 22:20:20 2011
@@ -29,7 +29,6 @@
 # OpenId provider imports
 OPENID_FILESTORE = '/tmp/openid-filestore' 
 
-from openid.store.filestore import FileOpenIDStore
 from openid.server import server as OpenIDServer
 
 # local imports
@@ -218,8 +217,6 @@
         self.loggedin = False      # was a valid cookie sent?
         self.usercookie = None
         self.failed = None # error message if initialization already produced a failure
-        op_endpoint = "%s?:action=openid_endpoint" % (self.config.url,)
-        self.oid_server = OpenIDServer.Server(FileOpenIDStore(OPENID_FILESTORE), op_endpoint=op_endpoint)
 
         # XMLRPC request or not?
         if self.env.get('CONTENT_TYPE') != 'text/xml':
@@ -269,6 +266,8 @@
         try:
             try:
                 self.store.get_cursor() # make sure we can connect
+                op_endpoint = "%s?:action=openid_endpoint" % (self.config.url,)
+                self.oid_server = OpenIDServer.Server(self.store.oid_store(), op_endpoint=op_endpoint)
                 self.inner_run()
             except NotFound, err:
                 self.fail('Not Found (%s)' % err, code=404)


More information about the Pypi-checkins mailing list