Skip to content

Commit bcfd4ea

Browse files
committed
Move AUTH modules into common auth package
1 parent f14bb05 commit bcfd4ea

File tree

6 files changed

+23
-40
lines changed

6 files changed

+23
-40
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

+5-7
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,13 +171,11 @@ 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))
174+
logger.debug('Available Auth options {}'.format(AUTH_MODULES))
177175

178-
if auth_options:
176+
if AUTH_MODULES:
179177
auth_choices = []
180-
for name, options in auth_options.items():
178+
for name, options in AUTH_MODULES.items():
181179
choice = (name, options.get('label', name))
182180
auth_choices.append(choice)
183181
field_kw = {
@@ -197,7 +195,7 @@ def handle(self, organization_id):
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

+4-7
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
@@ -200,13 +200,10 @@ class UserInvite(KQueenView):
200200
def handle(self):
201201
form_cls = UserInviteForm
202202

203-
modules = AuthModules()
204203

205-
auth_options = modules.__dict__
206-
207-
if auth_options:
204+
if AUTH_MODULES:
208205
auth_choices = []
209-
for name, options in auth_options.items():
206+
for name, options in AUTH_MODULES.items():
210207
choice = (name, options.get('label', name))
211208
auth_choices.append(choice)
212209
field_kw = {
@@ -228,7 +225,7 @@ def handle(self):
228225
notify = True
229226
if hasattr(form, 'auth_method'):
230227
auth_method = form.auth_method.data
231-
notify = auth_options.get(auth_method, {}).get('notify', True)
228+
notify = AUTH_MODULES.get(auth_method, {}).get('notify', True)
232229
password = ''
233230
active = True
234231
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)