Projet

Général

Profil

Télécharger (2,87 ko) Statistiques
| Branche: | Tag: | Révision:

root / mandaye / backends / default.py @ c62aae38

1

    
2
from importlib import import_module
3

    
4
from mandaye import config
5
from mandaye.exceptions import ImproperlyConfigured
6

    
7
def import_backend(path):
8
    try:
9
        mod = import_module(path)
10
    except ImportError, e:
11
        raise ImproperlyConfigured('Error importing backend %s: "%s"' % (path, e))
12
    return mod
13

    
14
storage_conn = None
15
if config.storage_backend == "mandaye.backends.sql":
16
    from sqlalchemy import create_engine
17
    from sqlalchemy.orm import sessionmaker, scoped_session
18
    if not "sqlite" in config.db_url:
19
       storage_conn = scoped_session(
20
                sessionmaker(
21
                    bind=create_engine(config.db_url, pool_size=16,
22
                        pool_recycle=1800)
23
                    )
24
                )
25
    else:
26
        storage_conn = scoped_session(
27
                sessionmaker(
28
                    bind=create_engine(config.db_url)
29
                    )
30
                )
31

    
32
backend = import_backend(config.storage_backend)
33
Association = backend.Association
34

    
35
class AssociationExample(object):
36
    """
37
    association dictionnary return by the following methods:
38
    {
39
        'id': '', # identifier of your association (must be unique)
40
        'sp_name': '', # name of the service provider (defined in the mappers)
41
        'sp_login': '', # login on the service provider
42
        'sp_post_values': '', # the post values for sp login form
43
        'idp_unique_id:': '', # the unique identifier of the identity provider (ex.: a saml NameID)
44
        'idp_name':  '', # identity provide name
45
        'last_connection':  datetime.datetime, # last connection with this association
46
        'creation_date':  datetime.datetime, # creation date of this association
47
    }
48
    """
49

    
50
    @staticmethod
51
    def get(sp_name, idp_unique_id, idp_name='dafault'):
52
        """ return a list of dict with associations that matching all of this options """
53
        pass
54

    
55
    @staticmethod
56
    def get_by_id(asso_id):
57
        """ return an dict of the association with the id or None if it doesn't exist """
58
        pass
59

    
60
    @staticmethod
61
    def has_id(asso_id):
62
        """ return a boolean """
63
        pass
64

    
65
    @staticmethod
66
    def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id, idp_name):
67
        """ update or create an associtaion which match the following values
68
        return the association id
69
        """
70
        pass
71

    
72
    @staticmethod
73
    def delete(asso_id):
74
        """ delete the association which has the following asso_id """
75
        pass
76

    
77
    @staticmethod
78
    def get_last_connected(sp_name, idp_unique_id, idp_name='default'):
79
        """ get the last connecting association which match the parameters
80
        return a dict of the association
81
        """
82
        pass
83

    
84
    @staticmethod
85
    def update_last_connection(asso_id):
86
        """ update the association last conenction time with the current time
87
        return a dict of the association
88
        """
89
        pass
(2-2/3)