Projet

Général

Profil

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

root / mandaye / backends / default.py @ 4c755abe

1

    
2
from datetime import datetime
3
from importlib import import_module
4

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

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

    
15
storage_conn = None
16
if config.storage_backend == "mandaye.backends.sql":
17
    from sqlalchemy import create_engine
18
    from sqlalchemy.orm import sessionmaker, scoped_session
19
    if not "sqlite" in config.db_url:
20
       storage_conn = scoped_session(
21
                sessionmaker(
22
                    bind=create_engine(config.db_url, pool_size=16,
23
                        pool_recycle=1800)
24
                    )
25
                )
26
    else:
27
        storage_conn = scoped_session(
28
                sessionmaker(
29
                    bind=create_engine(config.db_url)
30
                    )
31
                )
32
elif config.storage_backend == "mandaye.backends.ldap_back":
33
    import ldap
34
    storage_conn = ldap.initialize(config.ldap_url)
35
    storage_conn.protocol_version = ldap.VERSION3
36
    storage_conn.simple_bind(config.ldap_bind_dn, config.ldap_bind_password)
37

    
38
backend = import_backend(config.storage_backend)
39
Association = backend.Association
40

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

    
56
    @staticmethod
57
    def get(sp_name, idp_unique_id, idp_name='default'):
58
        """ return a list of dict with associations matching all of this options """
59
        pass
60

    
61
    @staticmethod
62
    def get_by_id(asso_id):
63
        """ return a dict of the association with the id or None if it doesn't exist """
64
        pass
65

    
66
    @staticmethod
67
    def has_id(asso_id):
68
        """ check the given user is present """
69
        pass
70

    
71
    @staticmethod
72
    def update_or_create(sp_name, sp_login, sp_post_values, idp_unique_id,
73
            idp_name='default', creation_date=None, last_connection_date=None):
74
        """ update or create an associtaion which match the following values
75
        creation_date and last_connection_date: by default datetime.utcnow()
76
        return the association id
77
        """
78
        pass
79

    
80
    @staticmethod
81
    def delete(asso_id):
82
        """ delete the association which has the following asso_id """
83
        pass
84

    
85
    @staticmethod
86
    def get_last_connected(sp_name, idp_unique_id, idp_name='default'):
87
        """ get the last connecting association which match the parameters
88
        return a dict of the association
89
        """
90
        pass
91

    
92
    @staticmethod
93
    def update_last_connection(asso_id):
94
        """ update the association last connection time with the current time
95
        return a dict of the association
96
        """
97
        pass
(2-2/4)