Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
added the no_auth option
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekziade committed Apr 23, 2014
1 parent 68e32ed commit 8473ff6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions loadsweb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def main():
session_opts[key] = config.get(key, default)

app = SessionMiddleware(get_app(), session_opts)
app.auth = Cork(config.get('auth_conf', 'auth_conf'))
app.authorize = app.auth.make_auth_decorator(fail_redirect="/login",
role="user")
if config.get('no_auth'):
app.authorize = app.auth = None
else:
app.auth = Cork(config.get('auth_conf', 'auth_conf'))
app.authorize = app.auth.make_auth_decorator(fail_redirect="/login",
role="user")
app.config = config
app.controller = Controller(config['db'], config['dboptions'],
broker=config['broker'])
Expand Down
10 changes: 6 additions & 4 deletions loadsweb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def load_conf(config_file=None):
# default config
options = ['db', 'wsserver', 'wsscheme', 'wsport', 'broker', 'debug',
'host', 'port']
'host', 'port', 'no_auth']

config = {'db': 'python',
'dboptions': {},
Expand All @@ -16,7 +16,8 @@ def load_conf(config_file=None):
'broker': 'ipc:///tmp/loads-front.ipc',
'debug': True,
'host': '0.0.0.0',
'port': 8080}
'port': 8080,
'no_auth': False}

if config_file is not None:
config_parser = Config(config_file)
Expand All @@ -31,8 +32,9 @@ def load_conf(config_file=None):
def authorize():
def _authorize(func):
def __authorize(*args, **kw):
redir = '/login?from=%s' % request.path
get_app().auth.require(fail_redirect=redir)
if get_app().auth is not None:
redir = '/login?from=%s' % request.path
get_app().auth.require(fail_redirect=redir)
return func(*args, **kw)
return __authorize
return _authorize
Expand Down

0 comments on commit 8473ff6

Please sign in to comment.