sentry.auth.db – sentry.auth.db module reference

Database authentication

class sentry.auth.db.DBAuth(db)

Authenticate using mysql. If we’re allowed to connect to the given database, then we’re authenticated.

authenticate(user, pw)
class sentry.auth.db.SingleTableAuth(db, tablename, usercol, pwcol, hasher)

Bases: sentry.auth.base.BaseAuth Authentication against a single table.

db: The database to connect to. If this has a engine attribute, then that will be treated as a sqlalchemy engine and used to connect to the database. Otherwise, sqlalchemy.create_engine(db) will be used.

tablename: The table containing the user / password information

usercol: The name of the column that contains the username

pwcol: The name of the column that contains the password

hasher: A callable that is called with the stored password in the database and the supplied password and returns True if the supplied password is valid.

Example usage:

>>> from sentry.hashers import Hasher
>>> h = Hasher("sha1")
>>> h.hsh("testpass")
'206c80413b9a96c1312cc346b7d2517b84463edd'
>>> from sqlalchemy import Table, Column, Unicode, MetaData, create_engine
>>> meta = MetaData(create_engine("sqlite://"))
>>> users_table = Table("users", meta,
...                 Column("username", Unicode(40), nullable = False),
...                 Column("password", Unicode(40), nullable = False))
>>> meta.create_all()
>>> result = users_table.insert().execute(username = "testuser",
...                 password = '206c80413b9a96c1312cc346b7d2517b84463edd')
>>> users_table.select(users_table.c.password).execute().fetchall()
[(u'testuser', u'206c80413b9a96c1312cc346b7d2517b84463edd')]
>>> single = SingleTableAuth(meta, "users", "username", "password", h)
>>> single.authenticate("testuser", "testpass")
True
>>> single.authenticate("testuser", "badpass")
False
authenticate(username, password)
getAuthInfo(user)
class sentry.auth.db.TwoTableAuth(userParams, pwParams, hasher)

Authentication against two tables.

userParams and pwParams are dictionaries that have the following keys:

db: the database to connect to

table: the table to use

col: the name of the column to use

joincol: the column to join the two tables together

hasher: A callable that us called with the stored password
in the database and the supplied password. Must return True if the supplied password is valid.
authenticate(username, password)