コード例 #1
0
ファイル: __init__.py プロジェクト: xu-bin-bin/redash
def create_app(load_admin=True):
    from redash import extensions, handlers
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication
    from redash.metrics.request import provision_app

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATH,
                static_folder=settings.STATIC_ASSETS_PATH,
                static_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter

    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=['ping'])

    if settings.SENTRY_DSN:
        from raven import Client
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler

        client = Client(settings.SENTRY_DSN,
                        release=__version__,
                        install_logging_hook=False)
        sentry = Sentry(app, client=client)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(client=client)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    provision_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    if load_admin:
        init_admin(app)
    mail.init_app(app)
    setup_authentication(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_extensions(app)
    chrome_logger.init_app(app)

    # support cas auth
    if settings.CAS_AUTH:
        from redash.authentication.cas import init_app
        init_app(app)

    return app
コード例 #2
0
ファイル: __init__.py プロジェクト: moritz9/redash
def create_app(load_admin=True):
    from redash import extensions, handlers
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication
    from redash.metrics.request import provision_app

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATH,
                static_folder=settings.STATIC_ASSETS_PATH,
                static_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    #app.wsgi_app = ReverseProxied(app.wsgi_app)
    app.url_map.converters['org_slug'] = SlugConverter


    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=['ping'])

    if settings.SENTRY_DSN:
        from raven import Client
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler

        client = Client(settings.SENTRY_DSN, release=__version__, install_logging_hook=False)
        sentry = Sentry(app, client=client)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(client=client)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    provision_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    if load_admin:
        init_admin(app)
    mail.init_app(app)
    setup_authentication(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_extensions(app)
    chrome_logger.init_app(app)

    return app
コード例 #3
0
ファイル: __init__.py プロジェクト: shayel/redash
def create_app():
    from redash import handlers
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication
    from redash.metrics.request import provision_app

    app = Flask(
        __name__,
        template_folder=settings.STATIC_ASSETS_PATHS[-1],
        static_folder=settings.STATIC_ASSETS_PATHS[-1],
        static_path="/static",
    )

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters["org_slug"] = SlugConverter

    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=["ping"])

    if settings.SENTRY_DSN:
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler

        sentry = Sentry(app, dsn=settings.SENTRY_DSN)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(settings.SENTRY_DSN)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # configure our database
    settings.DATABASE_CONFIG.update({"threadlocals": True})
    app.config["DATABASE"] = settings.DATABASE_CONFIG
    app.config.update(settings.all_settings())

    provision_app(app)
    init_admin(app)
    db.init_app(app)
    mail.init_app(app)
    setup_authentication(app)
    handlers.init_app(app)

    return app
コード例 #4
0
ファイル: __init__.py プロジェクト: jmvasquez/redashtest
def create_app():
    from redash import handlers
    from redash.devspark import custom_handlers
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication
    from redash.metrics.request import provision_app

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATHS[-1],
                static_folder=settings.STATIC_ASSETS_PATHS[-1],
                static_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter

    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=['ping'])

    if settings.SENTRY_DSN:
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler
        sentry = Sentry(app, dsn=settings.SENTRY_DSN)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(settings.SENTRY_DSN)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # configure our database
    settings.DATABASE_CONFIG.update({'threadlocals': True})
    app.config['DATABASE'] = settings.DATABASE_CONFIG
    app.config.update(settings.all_settings())

    provision_app(app)
    init_admin(app)
    db.init_app(app)
    mail.init_app(app)
    setup_authentication(app)
    handlers.init_app(app)

    return app
コード例 #5
0
ファイル: __init__.py プロジェクト: vatsaluc/redashuc
def create_app(load_admin=True):
    from redash import admin, authentication, extensions, handlers
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.models import db, users
    from redash.metrics.request import provision_app
    from redash.utils import sentry

    sentry.init()

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATH,
                static_folder=settings.STATIC_ASSETS_PATH,
                static_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter

    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=['ping'])

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    provision_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    if load_admin:
        admin.init_admin(app)
    mail.init_app(app)
    authentication.init_app(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_extensions(app)
    chrome_logger.init_app(app)
    users.init_app(app)

    return app
コード例 #6
0
ファイル: __init__.py プロジェクト: ariarijp/redash
def create_app():
    from redash import authentication, extensions, handlers, security
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.models import db, users
    from redash.metrics import request as request_metrics
    from redash.utils import sentry

    sentry.init()

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATH,
                static_folder=settings.STATIC_ASSETS_PATH,
                static_url_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    security.init_app(app)
    request_metrics.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    mail.init_app(app)
    authentication.init_app(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_app(app)
    chrome_logger.init_app(app)
    users.init_app(app)

    return app
コード例 #7
0
ファイル: __init__.py プロジェクト: xiongyingeng/redash
def create_app():
    from redash import authentication, extensions, handlers, security
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.models import db, users
    from redash.metrics import request as request_metrics
    from redash.utils import sentry

    sentry.init()

    app = Flask(__name__,
                template_folder=settings.STATIC_ASSETS_PATH,
                static_folder=settings.STATIC_ASSETS_PATH,
                static_url_path='/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    security.init_app(app)
    request_metrics.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    mail.init_app(app)
    authentication.init_app(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_app(app)
    chrome_logger.init_app(app)
    users.init_app(app)

    return app
コード例 #8
0
ファイル: __init__.py プロジェクト: fanhaipeng0403/redash
def create_app(load_admin=True):

    # 1.redash的__init___文件包含了一些通用的函数或者变量
    # 2.下面引入的模块使用了从这个模块导出的变量
    # 3.这里又从这些模块,导入进来一些函数或者变量
    # 4.形成了相互依赖
    # 5.解决方案
    # 6.调用置后于初始化的过程,比如requeset文件中的使用的 from redash import statsd_client 一定要在 from redash.metrics.request import provision_app前面
    # 7.或者放入函数内部
    # 8.保证首次进入sys.moudle的模块,已经包含了那些初始化的通用变量

    # import语句中的 模块 包含了这个import语句所在模块的 依赖,那么这个import语句应该在这个依赖声明的后面

    from redash import extensions, handlers
    from redash.handlers.webpack import configure_webpack
    from redash.handlers import chrome_logger
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication
    from redash.metrics.request import provision_app

    # https: // www.v2ex.com / t / 289972

    # 创建 flask 对象时候,是需要传一个模块一般是__name__过去,你改下就行了,那个是被当作根地址,确定了template位置
    # 也可以在蓝图的时候指定

    app = Flask(__name__,
                # 指定静态文件目录
                # fix_assets_path(os.environ.get("REDASH_STATIC_ASSETS_PATH", "../client/dist/"))
                template_folder=settings.STATIC_ASSETS_PATH,

                # https://blog.csdn.net/qq_40952927/article/details/81157204
                static_folder=settings.STATIC_ASSETS_PATH,
                static_path='/static')

    # https://www.kancloud.cn/wizardforcel/explore-flask/140842
    # http://python.jobbole.com/84003/
    # 使用了Nginx后,为了获取真实的请求IP
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)

    #  定制url
    app.url_map.converters['org_slug'] = SlugConverter

    # 根据setting文件配置
    if settings.ENFORCE_HTTPS:
        # https: // www.helplib.com / GitHub / article_82448
        # 所有的http重定向为https
        # 什么时候使用 ??????????????????????
        SSLify(app, skips=['ping'])

    # 异常警报和通知处理

    if settings.SENTRY_DSN:
        from raven import Client
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler

        client = Client(settings.SENTRY_DSN, release=__version__, install_logging_hook=False)
        sentry = Sentry(app, client=client)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(client=client)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # 数据库配置
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI

    # 默认自带的配置
    app.config.update(settings.all_settings())

    # 插件和自定义插件初始化
    if load_admin:
        init_admin(app)

    # 数据库
    # db = SQLAlchemy(app)
    db.init_app(app)


    # 数据库迁移
    migrate.init_app(app, db)
    # 邮件
    mail.init_app(app)
    # 请求次数
    limiter.init_app(app)
    # logger
    chrome_logger.init_app(app)
    extensions.init_extensions(app)

    # 一些请求前后的狗子,用于性能测试等
    provision_app(app)

    # 所有的controller入口!!!!!

    handlers.init_app(app)

    # api 认证接口注册!!!!
    setup_authentication(app)

    # webpack!!!!!
    configure_webpack(app)

    return app
コード例 #9
0
ファイル: wsgi.py プロジェクト: carezone/redash
# Make sure we get the right referral address even behind proxies like nginx.
app.wsgi_app = ProxyFix(app.wsgi_app)

api = Api(app)
init_admin(app)

if settings.SENTRY_DSN:
    from raven.contrib.flask import Sentry
    sentry = Sentry(app, dsn=settings.SENTRY_DSN)
    sentry.client.release = __version__

# configure our database
settings.DATABASE_CONFIG.update({'threadlocals': True})
app.config['DATABASE'] = settings.DATABASE_CONFIG
app.config.update(settings.all_settings())
db.init_app(app)
mail.init_app(app)

from redash.authentication import setup_authentication
setup_authentication(app)


@api.representation('application/json')
def json_representation(data, code, headers=None):
    # Flask-Restful checks only for flask.Response but flask-login uses werkzeug.wrappers.Response
    if isinstance(data, Response):
        return data
    resp = make_response(json.dumps(data, cls=utils.JSONEncoder), code)
    resp.headers.extend(headers or {})
    return resp
コード例 #10
0
__version__ = '0.4.0'

app = Flask(__name__,
            template_folder=settings.STATIC_ASSETS_PATH,
            static_folder=settings.STATIC_ASSETS_PATH,
            static_path='/static')


api = Api(app)
init_admin(app)

# configure our database
settings.DATABASE_CONFIG.update({'threadlocals': True})
app.config['DATABASE'] = settings.DATABASE_CONFIG
app.config.update(settings.all_settings())
db.init_app(app)
mail.init_app(app)

from redash.authentication import setup_authentication
setup_authentication(app)

@api.representation('application/json')
def json_representation(data, code, headers=None):
    # Flask-Restful checks only for flask.Response but flask-login uses werkzeug.wrappers.Response
    if isinstance(data, Response):
        return data
    resp = make_response(json.dumps(data, cls=utils.JSONEncoder), code)
    resp.headers.extend(headers or {})
    return resp

from redash import controllers
コード例 #11
0
def create_app(load_admin=True):
    from jose import jwt
    from redash import extensions, handlers
    from redash.handlers.webpack import configure_webpack
    from redash.admin import init_admin
    from redash.models import db
    from redash.authentication import setup_authentication, get_jwt_public_key
    from redash.metrics.request import provision_app
    from jose import jwt

    os.environ['SCRIPT_NAME'] = settings.ROOT_UI_URL

    if settings.REMOTE_JWT_LOGIN_ENABLED:

        class JwtFlask(Flask):
            def process_response(self, response, *args, **kwargs):
                jwttoken = request.cookies.get('jwt', None)

                if jwttoken is not None:
                    try:
                        public_key = get_jwt_public_key()
                        jwt_decoded = jwt.get_unverified_claims(
                            jwttoken) if public_key is '' else jwt.decode(
                                jwttoken, public_key)
                        iat = jwt_decoded['iat']
                        exp = jwt_decoded['exp']
                        now = time.time()

                        if iat + 1200 < now <= exp:
                            email = jwt_decoded.get('email', None)
                            resp = requests.post(
                                settings.REMOTE_JWT_REFRESH_PROVIDER,
                                headers={
                                    'Authorization': 'Bearer ' + jwttoken
                                },
                                data={'email': email})
                            if resp.status_code < 300 and resp.data.get(
                                    'jwt', None) is not None:
                                response.set_cookie('jwt',
                                                    resp.data['jwt'],
                                                    secure=True,
                                                    httponly=True)
                            elif resp.status_code == 401:
                                raise jwt.JWTError(
                                    'The authentication refresh service has denied a refresh, a login is likely in order.'
                                )
                        elif now > exp:
                            raise jwt.JWTClaimsError(
                                'The asserted expiration claim has passed.')
                    except (jwt.ExpiredSignatureError, jwt.JWTClaimsError,
                            jwt.JWTError) as e:
                        return redirect(
                            settings.REMOTE_JWT_EXPIRED_ENDPOINT +
                            urllib.quote_plus(request.referrer
                                              or settings.ROOT_UI_URL))
                return super(JwtFlask,
                             self).process_response(response, *args, **kwargs)

        app = JwtFlask(__name__,
                       template_folder=settings.STATIC_ASSETS_PATH,
                       static_folder=settings.STATIC_ASSETS_PATH,
                       static_url_path=settings.ROOT_UI_URL + '/static')
    else:
        app = Flask(__name__,
                    template_folder=settings.STATIC_ASSETS_PATH,
                    static_folder=settings.STATIC_ASSETS_PATH,
                    static_url_path=settings.ROOT_UI_URL + '/static')

    # Make sure we get the right referral address even behind proxies like nginx.
    app.wsgi_app = ProxyFix(app.wsgi_app, settings.PROXIES_COUNT)
    app.url_map.converters['org_slug'] = SlugConverter
    app.config["APPLICATION_ROOT"] = settings.ROOT_UI_URL
    app.config['TEMPLATES_AUTO_RELOAD'] = True

    if settings.ENFORCE_HTTPS:
        SSLify(app, skips=['ping'])

    if settings.SENTRY_DSN:
        from raven import Client
        from raven.contrib.flask import Sentry
        from raven.handlers.logging import SentryHandler

        client = Client(settings.SENTRY_DSN,
                        release=__version__,
                        install_logging_hook=False)
        sentry = Sentry(app, client=client)
        sentry.client.release = __version__

        sentry_handler = SentryHandler(client=client)
        sentry_handler.setLevel(logging.ERROR)
        logging.getLogger().addHandler(sentry_handler)

    # configure our database
    app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
    app.config.update(settings.all_settings())

    provision_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    if load_admin:
        init_admin(app)
    mail.init_app(app)
    setup_authentication(app)
    limiter.init_app(app)
    handlers.init_app(app)
    configure_webpack(app)
    extensions.init_extensions(app)
    return app