Skip to content

Commit f97cc5a

Browse files
author
Alexandre Ferland
committed
Merge branch 'add_custom_options'
2 parents 37a41ee + 8a3fae8 commit f97cc5a

File tree

8 files changed

+31
-5
lines changed

8 files changed

+31
-5
lines changed

dev_requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
pyldap==2.4.25.1
1+
-r requirements.txt
2+
Sphinx==1.4.3
3+

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def __getattr__(cls, name):
6363
# built documents.
6464
#
6565
# The short X.Y version.
66-
version = '1.0.0'
66+
version = '1.1.0'
6767
# The full version, including alpha/beta/rc tags.
68-
release = '1.0.0'
68+
release = '1.1.0'
6969

7070
# The language for content autogenerated by Sphinx. Refer to documentation
7171
# for a list of supported languages.

docs/index.rst

+6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ directives:
9696
Default: '*'
9797
``LDAP_GROUP_MEMBER_FILTER_FIELD`` The group member filter field to use when using OpenLDAP.
9898
Default: '*'
99+
``LDAP_CUSTOM_OPTIONS`` ``dict`` of ldap options you want to set in this format: {option: value}.
100+
Default: ``None``
99101
================================== ================================================================
100102

101103

@@ -114,6 +116,10 @@ History
114116

115117
Changes:
116118

119+
- 1.1.0 June 7, 2016
120+
121+
- Add the ability the pass any valid pyldap config options via the LDAP_CUSTOM_OPTIONS configuration directive.
122+
117123
- 1.0.1 June 5, 2016
118124

119125
- Fix ldap filter import.

examples/blueprints/blueprints/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import ldap
2+
3+
14
class BaseConfig(object):
25
PROJECT = 'foo'
36
SECRET_KEY = 'dev key'
@@ -9,3 +12,4 @@ class BaseConfig(object):
912
LDAP_USERNAME = 'CN=user,OU=Users,DC=example,DC=org'
1013
LDAP_PASSWORD = 'password'
1114
LDAP_LOGIN_VIEW = 'core.login'
15+
LDAP_CUSTOM_OPTIONS = {ldap.OPT_REFERRALS: 0}

examples/groups/app.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ldap as l
12
from flask import Flask, g, request, session, redirect, url_for
23
from flask_simpleldap import LDAP
34

@@ -9,6 +10,7 @@
910
app.config['LDAP_BASE_DN'] = 'OU=users,dc=example,dc=org'
1011
app.config['LDAP_USERNAME'] = 'CN=user,OU=Users,DC=example,DC=org'
1112
app.config['LDAP_PASSWORD'] = 'password'
13+
app.config['LDAP_CUSTOM_OPTIONS'] = {l.OPT_REFERRALS: 0}
1214

1315
ldap = LDAP(app)
1416

flask_simpleldap/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def init_app(app):
5959
app.config.setdefault('LDAP_OPENLDAP', False)
6060
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*')
6161
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER_FIELD', '*')
62+
app.config.setdefault('LDAP_CUSTOM_OPTIONS', None)
6263

6364
if app.config['LDAP_USE_SSL'] or app.config['LDAP_USE_TLS']:
6465
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
@@ -74,6 +75,14 @@ def init_app(app):
7475
if app.config['LDAP_{0}'.format(option)] is None:
7576
raise LDAPException('LDAP_{0} cannot be None!'.format(option))
7677

78+
@staticmethod
79+
def _set_custom_options(conn):
80+
options = current_app.config['LDAP_CUSTOM_OPTIONS']
81+
if options:
82+
for k, v in options.items():
83+
conn.set_option(k, v)
84+
return conn
85+
7786
@property
7887
def initialize(self):
7988
"""Initialize a connection to the LDAP server.
@@ -88,6 +97,7 @@ def initialize(self):
8897
current_app.config['LDAP_PORT']))
8998
conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
9099
current_app.config['LDAP_TIMEOUT'])
100+
conn = self._set_custom_options(conn)
91101
conn.protocol_version = ldap.VERSION3
92102
if current_app.config['LDAP_USE_TLS']:
93103
conn.start_tls_s()

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Flask==0.11
2-
mock==2.0.0
2+
mock==2.0.0 # for ci
3+
pyldap==2.4.25.1
4+

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='Flask-SimpleLDAP',
12-
version='1.0.1',
12+
version='1.1.0',
1313
url='https://github.com/admiralobvious/flask-simpleldap',
1414
license='MIT',
1515
author='Alexandre Ferland',

0 commit comments

Comments
 (0)