Skip to content

Commit

Permalink
refactored PSA-related models and tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
VJalili committed Dec 14, 2017
1 parent 6f27d09 commit d39c9c3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
34 changes: 17 additions & 17 deletions lib/galaxy/authnz/psa_authnz.py
@@ -1,5 +1,5 @@
from ..authnz import IdentityProvider
from ..model import UserAuthnzToken, SocialAuthNonce, SocialAuthAssociation, SocialAuthPartial, SocialAuthCode
from ..model import UserAuthnzToken, PSANonce, PSAAssociation, PSAPartial, PSACode

from social_core.actions import do_auth, do_complete, do_disconnect
from social_core.backends.utils import get_backend
Expand Down Expand Up @@ -144,11 +144,11 @@ def authenticate(self, trans):
_user = trans.user

_trans = trans
trans.app.model.SocialAuthCode.trans = trans
trans.app.model.PSACode.trans = trans
trans.app.model.UserAuthnzToken.trans = trans
trans.app.model.SocialAuthNonce.trans = trans
trans.app.model.SocialAuthPartial.trans = trans
trans.app.model.SocialAuthAssociation.trans = trans
trans.app.model.PSANonce.trans = trans
trans.app.model.PSAPartial.trans = trans
trans.app.model.PSAAssociation.trans = trans

backend_label = 'google-openidconnect'
self.strategy = Strategy(trans, Storage) # self.load_strategy()
Expand All @@ -163,11 +163,11 @@ def authenticate(self, trans):

def callback(self, state_token, authz_code, trans):
_trans = trans
trans.app.model.SocialAuthCode.trans = trans
trans.app.model.PSACode.trans = trans
trans.app.model.UserAuthnzToken.trans = trans
trans.app.model.SocialAuthNonce.trans = trans
trans.app.model.SocialAuthPartial.trans = trans
trans.app.model.SocialAuthAssociation.trans = trans
trans.app.model.PSANonce.trans = trans
trans.app.model.PSAPartial.trans = trans
trans.app.model.PSAAssociation.trans = trans

uri = '/authn/{provider}/callback' # TODO find a better of doing this -- this info should be passed from buildapp.py
backend_label = 'google-openidconnect'
Expand All @@ -186,11 +186,11 @@ def callback(self, state_token, authz_code, trans):

def disconnect(self, provider, trans, association_id=None):
_trans = trans
trans.app.model.SocialAuthCode.trans = trans
trans.app.model.PSACode.trans = trans
trans.app.model.UserAuthnzToken.trans = trans
trans.app.model.SocialAuthNonce.trans = trans
trans.app.model.SocialAuthPartial.trans = trans
trans.app.model.SocialAuthAssociation.trans = trans
trans.app.model.PSANonce.trans = trans
trans.app.model.PSAPartial.trans = trans
trans.app.model.PSAAssociation.trans = trans
backend_label = 'google-openidconnect'
uri = '/authn/{provider}/callback' # TODO find a better of doing this -- this info should be passed from buildapp.py

Expand Down Expand Up @@ -369,10 +369,10 @@ def continue_pipeline(self, *args, **kwargs):

class Storage:
user = UserAuthnzToken
nonce = SocialAuthNonce
association = SocialAuthAssociation
code = SocialAuthCode
partial = SocialAuthPartial
nonce = PSANonce
association = PSAAssociation
code = PSACode
partial = PSAPartial

@classmethod
def is_integrity_error(cls, exception):
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/model/__init__.py
Expand Up @@ -5014,7 +5014,7 @@ def __init__(self, user_id, provider, state_token, id_token=None, refresh_token=
self.access_token = access_token


class SocialAuthAssociation(AssociationMixin):
class PSAAssociation(AssociationMixin):

# This static property is of type: galaxy.web.framework.webapp.GalaxyWebTransaction
# and it is set in: galaxy.authnz.psa_authnz.PSAAuthnz
Expand Down Expand Up @@ -5054,7 +5054,7 @@ def remove(cls, ids_to_delete):
cls.trans.sa_session.query(cls).filter(cls.id.in_(ids_to_delete)).delete(synchronize_session='fetch')


class SocialAuthCode(CodeMixin):
class PSACode(CodeMixin):
__table_args__ = (UniqueConstraint('code', 'email'),)

# This static property is of type: galaxy.web.framework.webapp.GalaxyWebTransaction
Expand All @@ -5074,7 +5074,7 @@ def get_code(cls, code):
return cls.trans.sa_session.query(cls).filter(cls.code == code).first()


class SocialAuthNonce(NonceMixin):
class PSANonce(NonceMixin):

# This static property is of type: galaxy.web.framework.webapp.GalaxyWebTransaction
# and it is set in: galaxy.authnz.psa_authnz.PSAAuthnz
Expand All @@ -5100,7 +5100,7 @@ def use(cls, server_url, timestamp, salt):
return instance


class SocialAuthPartial(PartialMixin):
class PSAPartial(PartialMixin):

# This static property is of type: galaxy.web.framework.webapp.GalaxyWebTransaction
# and it is set in: galaxy.authnz.psa_authnz.PSAAuthnz
Expand Down
22 changes: 11 additions & 11 deletions lib/galaxy/model/mapping.py
Expand Up @@ -103,8 +103,8 @@
Column("expiration_date", DateTime),
Column("access_token", String))

model.SocialAuthAssociation.table = Table(
"social_auth_association", metadata,
model.PSAAssociation.table = Table(
"psa_association", metadata,
Column('id', Integer, primary_key=True),
Column('server_url', VARCHAR(255)),
Column('handle', VARCHAR(255)),
Expand All @@ -113,21 +113,21 @@
Column('lifetime', Integer),
Column('assoc_type', VARCHAR(64)))

model.SocialAuthCode.table = Table(
"social_auth_code", metadata,
model.PSACode.table = Table(
"psa_code", metadata,
Column('id', Integer, primary_key=True),
Column('email', VARCHAR(200)),
Column('code', VARCHAR(32)))

model.SocialAuthNonce.table = Table(
model.PSANonce.table = Table(
"psa_nonce", metadata,
Column('id', Integer, primary_key=True),
Column('server_url', VARCHAR(255)),
Column('timestamp', Integer),
Column('salt', VARCHAR(40)))

model.SocialAuthPartial.table = Table(
"social_auth_partial", metadata,
model.PSAPartial.table = Table(
"psa_partial", metadata,
Column('id', Integer, primary_key=True),
Column('token', VARCHAR(32)),
Column('data', TEXT),
Expand Down Expand Up @@ -1636,13 +1636,13 @@ def simple_mapping(model, **kwds):
primaryjoin=(model.UserOAuth2.table.c.user_id == model.User.table.c.id))
))

mapper(model.SocialAuthAssociation, model.SocialAuthAssociation.table, properties=None)
mapper(model.PSAAssociation, model.PSAAssociation.table, properties=None)

mapper(model.SocialAuthCode, model.SocialAuthCode.table, properties=None)
mapper(model.PSACode, model.PSACode.table, properties=None)

mapper(model.SocialAuthNonce, model.SocialAuthNonce.table, properties=None)
mapper(model.PSANonce, model.PSANonce.table, properties=None)

mapper(model.SocialAuthPartial, model.SocialAuthPartial.table, properties=None)
mapper(model.PSAPartial, model.PSAPartial.table, properties=None)

mapper(model.UserAuthnzToken, model.UserAuthnzToken.table, properties=dict(
user=relation(model.User,
Expand Down
26 changes: 13 additions & 13 deletions lib/galaxy/model/migrate/versions/0137_psa_tables.py
Expand Up @@ -10,8 +10,8 @@
log = logging.getLogger(__name__)
metadata = MetaData()

social_auth_association = Table(
"social_auth_association", metadata,
psa_association = Table(
"psa_association", metadata,
Column('id', Integer, primary_key=True),
Column('server_url', VARCHAR(255)),
Column('handle', VARCHAR(255)),
Expand All @@ -21,8 +21,8 @@
Column('assoc_type', VARCHAR(64)))


social_auth_code = Table(
"social_auth_code", metadata,
psa_code = Table(
"psa_code", metadata,
Column('id', Integer, primary_key=True),
Column('email', VARCHAR(200)),
Column('code', VARCHAR(32)))
Expand All @@ -36,8 +36,8 @@
Column('salt', VARCHAR(40)))


social_auth_partial = Table(
"social_auth_partial", metadata,
psa_partial = Table(
"psa_partial", metadata,
Column('id', Integer, primary_key=True),
Column('token', VARCHAR(32)),
Column('data', TEXT),
Expand All @@ -63,10 +63,10 @@ def upgrade(migrate_engine):

# Create UserOAuth2Table
try:
social_auth_association.create()
social_auth_code.create()
psa_association.create()
psa_code.create()
psa_nonce.create()
social_auth_partial.create()
psa_partial.create()
oidc_rp_user_authnz_tokens.create()
except Exception as e:
log.exception("Creating UserOAuth2 table failed: %s" % str(e))
Expand All @@ -78,10 +78,10 @@ def downgrade(migrate_engine):

# Drop UserOAuth2Table
try:
social_auth_association.drop()
social_auth_code.drop()
pas_nonce.drop()
social_auth_partial.drop()
psa_association.drop()
psa_code.drop()
psa_nonce.drop()
psa_partial.drop()
oidc_rp_user_authnz_tokens.drop()
except Exception as e:
log.exception("Dropping UserOAuth2 table failed: %s" % str(e))

0 comments on commit d39c9c3

Please sign in to comment.