Coverage for airflow.default_login: 45%

# Coverage for airflow.default_login : 45%

## 40 statements 18 run 22 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ''' Override this file to handle your authenticating / 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 DefaultUser(object): def __init__(self, user): self.user = user 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! #del User @login_manager.user_loader def load_user(userid): session = settings.Session() user = session.query(models.User).filter(models.User.id == userid).first() session.expunge_all() session.commit() session.close() return DefaultUser(user) def login(self, request): session = settings.Session() user = session.query(models.User).filter( models.User.username == DEFAULT_USERNAME).first() if not user: user = models.User( username=DEFAULT_USERNAME, is_superuser=True) session.merge(user) session.commit() flask_login.login_user(DefaultUser(user)) session.commit() session.close() return redirect(request.args.get("next") or url_for("index"))