This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
mandaye/mandaye/backends/default.py

90 lines
2.9 KiB
Python

from importlib import import_module
from mandaye import config
from mandaye.exceptions import ImproperlyConfigured
def import_backend(path):
try:
mod = import_module(path)
except ImportError, e:
raise ImproperlyConfigured('Error importing backend %s: "%s"' % (path, e))
return mod
storage_conn = None
if config.storage_backend == "mandaye.backends.sql":
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
if not "sqlite" in config.db_url:
storage_conn = scoped_session(
sessionmaker(
bind=create_engine(config.db_url, pool_size=16,
pool_recycle=1800)
)
)
else:
storage_conn = scoped_session(
sessionmaker(
bind=create_engine(config.db_url)
)
)
backend = import_backend(config.storage_backend)
Association = backend.Association
class AssociationExample(object):
"""
association dictionnary return by the following methods:
{
'id': '', # identifier of your association (must be unique)
'sp_name': '', # name of the service provider (defined in the mappers)
'sp_login': '', # login on the service provider
'sp_post_values': '', # the post values for sp login form
'idp_unique_id:': '', # the unique identifier of the identity provider (ex.: a saml NameID)
'idp_name': '', # identity provide name
'last_connection': datetime.datetime, # last connection with this association
'creation_date': datetime.datetime, # creation date of this association
}
"""
@staticmethod
def get(sp_name, idp_unique_id, idp_name='dafault'):
""" return a list of dict with associations that matching all of this options """
pass
@staticmethod
def get_by_id(asso_id):
""" return an dict of the association with the id or None if it doesn't exist """
pass
@staticmethod
def has_id(asso_id):
""" return a boolean """
pass
@staticmethod
def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name):
""" update or create an associtaion which match the following values
return the association id
"""
pass
@staticmethod
def delete(asso_id):
""" delete the association which has the following asso_id """
pass
@staticmethod
def get_last_connected(sp_name, idp_unique_id, idp_name='default'):
""" get the last connecting association which match the parameters
return a dict of the association
"""
pass
@staticmethod
def update_last_connection(asso_id):
""" update the association last conenction time with the current time
return a dict of the association
"""
pass