forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making login module generic / overridable
- Loading branch information
1 parent
e3521c1
commit 4518dcb
Showing
10 changed files
with
365 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
from models import DAG | ||
|
||
__version__ = "0.4.3" | ||
|
||
''' | ||
Authentication is implemented using flask_login and different environments can | ||
implement their own login mechanisms by providing an `airflow_login` module | ||
in their PYTHONPATH. airflow_login should be based off the | ||
`airflow.www.login` | ||
''' | ||
try: | ||
# Environment specific login | ||
import airflow_login | ||
login = airflow_login | ||
except ImportError: | ||
# Default login, no real authentication | ||
from airflow import default_login | ||
login = default_login | ||
|
||
from models import DAG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
''' | ||
Override this file to handle your authenticatin / login. | ||
Copy and alter this file and put in your PYTHONPATH as airflow_login.py, | ||
the new module will override this one. | ||
''' | ||
|
||
import flask_login | ||
from flask_login import login_required, current_user, logout_user | ||
|
||
from flask import url_for, redirect | ||
|
||
from airflow import settings | ||
from airflow import models | ||
|
||
DEFAULT_USERNAME = 'airflow' | ||
|
||
login_manager = flask_login.LoginManager() | ||
login_manager.login_view = 'airflow.login' # Calls login() bellow | ||
login_manager.login_message = None | ||
|
||
|
||
class User(models.BaseUser): | ||
|
||
def is_active(self): | ||
'''Required by flask_login''' | ||
return True | ||
|
||
def is_authenticated(self): | ||
'''Required by flask_login''' | ||
return True | ||
|
||
def is_anonymous(self): | ||
'''Required by flask_login''' | ||
return False | ||
|
||
def data_profiling(self): | ||
'''Provides access to data profiling tools''' | ||
return True | ||
|
||
def is_superuser(self): | ||
'''Access all the things''' | ||
return True | ||
|
||
models.User = User # hack! | ||
|
||
|
||
@login_manager.user_loader | ||
def load_user(userid): | ||
session = settings.Session() | ||
user = session.query(User).filter(User.id == userid).first() | ||
session.expunge_all() | ||
session.commit() | ||
session.close() | ||
return user | ||
|
||
|
||
def login(self, request): | ||
session = settings.Session() | ||
user = session.query(User).filter( | ||
User.username == DEFAULT_USERNAME).first() | ||
if not user: | ||
user = User( | ||
username=DEFAULT_USERNAME, | ||
has_access=True, | ||
is_superuser=True) | ||
session.merge(user) | ||
session.expunge_all() | ||
session.commit() | ||
session.close() | ||
flask_login.login_user(user) | ||
return redirect(request.args.get("next") or url_for("index")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.