Skip to content

Commit 7e20f81

Browse files
committed
Move AUTH modules into common auth package
1 parent 4810580 commit 7e20f81

File tree

6 files changed

+47
-66
lines changed

6 files changed

+47
-66
lines changed

kqueen_ui/auth.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
from itsdangerous import URLSafeTimedSerializer
22
from flask import current_app as app
33
from kqueen_ui.api import get_kqueen_client
4+
from kqueen_ui.config import current_config
45

56
import logging
67

78
logger = logging.getLogger('kqueen_ui')
9+
config = current_config()
10+
11+
AUTH_MODULES = {
12+
"local": {
13+
"label": "Local",
14+
"notify": config.get("LOCAL_AUTH_NOTIFY")
15+
},
16+
"ldap": {
17+
"label": "LDAP",
18+
"notify": config.get("LDAP_AUTH_NOTIFY")
19+
}
20+
}
821

922

1023
def authenticate(username, password):

kqueen_ui/blueprints/manager/views.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from flask import Blueprint, current_app as app, flash, jsonify, redirect, render_template, request, session, url_for
55
from flask_babel import format_datetime
66
from kqueen_ui.api import get_kqueen_client
7-
from kqueen_ui.config.auth import AuthModules
7+
from kqueen_ui.auth import AUTH_MODULES
88
from kqueen_ui.auth import generate_confirmation_token
99
from kqueen_ui.blueprints.ui.utils import generate_password, sanitize_resource_metadata
1010
from kqueen_ui.generic_views import KQueenView
@@ -171,33 +171,31 @@ class MemberCreate(KQueenView):
171171
def handle(self, organization_id):
172172
form_cls = MemberCreateForm
173173

174-
modules = AuthModules()
175-
auth_options = modules.__dict__
176-
logger.debug('Available Auth options {}'.format(auth_options))
177-
178-
if auth_options:
179-
auth_choices = []
180-
for name, options in auth_options.items():
181-
choice = (name, options.get('label', name))
182-
auth_choices.append(choice)
183-
field_kw = {
184-
'auth_method': {
185-
'type': 'select',
186-
'label': 'Authentication Method',
187-
'choices': auth_choices,
188-
'validators': {
189-
'required': True
190-
}
174+
logger.debug('Available Auth options {}'.format(AUTH_MODULES))
175+
176+
auth_choices = []
177+
for name, options in AUTH_MODULES.items():
178+
choice = (name, options.get('label', name))
179+
auth_choices.append(choice)
180+
field_kw = {
181+
'auth_method': {
182+
'type': 'select',
183+
'label': 'Authentication Method',
184+
'choices': auth_choices,
185+
'validators': {
186+
'required': True
191187
}
192188
}
193-
form_cls.append_fields(field_kw)
189+
}
190+
191+
form_cls.append_fields(field_kw)
194192
form = form_cls()
195193
if form.validate_on_submit():
196194
auth_method = 'local'
197195
notify = True
198196
if hasattr(form, 'auth_method'):
199197
auth_method = form.auth_method.data
200-
notify = auth_options.get(auth_method, {}).get('notify', True)
198+
notify = AUTH_MODULES.get(auth_method, {}).get('notify', True)
201199
password = ''
202200
active = True
203201
if auth_method == 'local':

kqueen_ui/blueprints/ui/views.py

+15-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
render_template, request, session, url_for)
44
from flask_babel import format_datetime
55
from kqueen_ui.api import get_kqueen_client
6-
from kqueen_ui.config.auth import AuthModules
6+
from kqueen_ui.auth import AUTH_MODULES
77
from kqueen_ui.auth import authenticate, confirm_token, generate_confirmation_token
88
from kqueen_ui.generic_views import KQueenView
99
from kqueen_ui.utils.email import EmailMessage
@@ -201,35 +201,30 @@ class UserInvite(KQueenView):
201201
def handle(self):
202202
form_cls = UserInviteForm
203203

204-
modules = AuthModules()
205-
206-
auth_options = modules.__dict__
207-
208-
if auth_options:
209-
auth_choices = []
210-
for name, options in auth_options.items():
211-
choice = (name, options.get('label', name))
212-
auth_choices.append(choice)
213-
field_kw = {
214-
'auth_method': {
215-
'type': 'select',
216-
'label': 'Authentication Method',
217-
'choices': auth_choices,
218-
'validators': {
219-
'required': True
220-
}
204+
auth_choices = []
205+
for name, options in AUTH_MODULES.items():
206+
choice = (name, options.get('label', name))
207+
auth_choices.append(choice)
208+
field_kw = {
209+
'auth_method': {
210+
'type': 'select',
211+
'label': 'Authentication Method',
212+
'choices': auth_choices,
213+
'validators': {
214+
'required': True
221215
}
222216
}
223-
form_cls.append_fields(field_kw)
217+
}
224218

219+
form_cls.append_fields(field_kw)
225220
form = form_cls()
226221
if form.validate_on_submit():
227222
organization = 'Organization:{}'.format(session['user']['organization']['id'])
228223
auth_method = 'local'
229224
notify = True
230225
if hasattr(form, 'auth_method'):
231226
auth_method = form.auth_method.data
232-
notify = auth_options.get(auth_method, {}).get('notify', True)
227+
notify = AUTH_MODULES.get(auth_method, {}).get('notify', True)
233228
password = ''
234229
active = True
235230
if auth_method == 'local':

kqueen_ui/config/auth.py

-24
This file was deleted.

kqueen_ui/config/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class BaseConfig:
5959
# Authentication choices
6060
LDAP_AUTH_NOTIFY = False
6161
LOCAL_AUTH_NOTIFY = True
62-
AUTH_OPTIONS = {}
6362

6463
@classmethod
6564
def get(cls, name, default=None):

kqueen_ui/config/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Config(BaseConfig):
5-
DEBUG = False
5+
DEBUG = True
66
LOG_CONFIG = 'kqueen_ui/utils/logger_config.yml'
77

88
# CSRF settings

0 commit comments

Comments
 (0)