コード例 #1
0
ファイル: app.py プロジェクト: ragnarokatz/wp1
def create_app():
  app = flask.Flask(__name__)

  rq_user = os.environ.get('RQ_USER')
  rq_pass = os.environ.get('RQ_PASS')
  redis_creds = get_redis_creds()

  if rq_user is not None and rq_pass is not None:
    app.config.from_object(rq_dashboard.default_settings)
    if redis_creds is not None:
      app.config.update({'RQ_DASHBOARD_REDIS_HOST': redis_creds['host']})
      app.config.update({'RQ_DASHBOARD_REDIS_PORT': redis_creds['port']})
    add_basic_auth(rq_dashboard.blueprint, rq_user, rq_pass)
    app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq")
  else:
    print('No RQ_USER/RQ_PASS found in env. RQ dashboard not created.')

  @app.teardown_request
  def close_dbs(ex):
    if has_db('wikidb'):
      conn = get_db('wikidb')
      conn.close()
    if has_db('wp10db'):
      conn = get_db('wp10db')
      conn.close()

  @app.route('/')
  def index():
    wp10db = get_db('wp10db')
    count = logic_project.count_projects(wp10db)
    return flask.render_template('index.html.jinja2', count=count)

  return app
コード例 #2
0
def register_rq(app):
    username = app.config.get("RQ_DASHBOARD_USERNAME")
    password = app.config.get("RQ_DASHBOARD_PASSWORD")

    if username and password:
        add_basic_auth(blueprint=rq, username=username, password=password)
        app.logger.info(f"Creating RQ-dashboard login for {username}")

    app.register_blueprint(rq, url_prefix="/dashboard")
コード例 #3
0
def setup_rq_dashboard(app):

    app.config.from_object(settings)
    add_basic_auth(
        blueprint,
        app.config["RQ_DASHBOARD"]["username"],
        app.config["RQ_DASHBOARD"]["password"],
    )

    app.register_blueprint(blueprint, url_prefix="/api/admin/rq")

    # Force harcoded settings for RQ Dashboard
    app.config["REDIS_HOST"] = app.config["REDIS"]["host"]
    app.config["REDIS_PORT"] = app.config["REDIS"]["port"]
    app.config["REDIS_PASSWORD"] = app.config["REDIS"]["password"]
コード例 #4
0
ファイル: app.py プロジェクト: adityavs/wp1
def create_app():
  app = flask.Flask(__name__)
  cors = flask_cors.CORS(app)
  gzip = flask_gzip.Gzip(app, minimum_size=256)

  rq_user = os.environ.get('RQ_USER')
  rq_pass = os.environ.get('RQ_PASS')
  redis_creds = get_redis_creds()

  if rq_user is not None and rq_pass is not None:
    app.config.from_object(rq_dashboard.default_settings)
    if redis_creds is not None:
      app.config.update({'RQ_DASHBOARD_REDIS_HOST': redis_creds['host']})
      app.config.update({'RQ_DASHBOARD_REDIS_PORT': redis_creds['port']})
    add_basic_auth(rq_dashboard.blueprint, rq_user, rq_pass)
    app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq")
  else:
    print('No RQ_USER/RQ_PASS found in env. RQ dashboard not created.')

  @app.teardown_request
  def close_dbs(ex):
    if has_db('wikidb'):
      conn = get_db('wikidb')
      conn.close()
    if has_db('wp10db'):
      conn = get_db('wp10db')
      conn.close()

  @app.route('/')
  def index():
    return flask.send_from_directory('.', "swagger.html")

  @app.route("/v1/openapi.yml")
  @nocache
  def swagger_api_docs_yml():
    return flask.send_from_directory(".", "openapi.yml")

  app.register_blueprint(projects, url_prefix='/v1/projects')

  return app
コード例 #5
0
def create_app(config_mode=None, config_file=None):
    app = Flask(__name__)
    app.url_map.strict_slashes = False
    cors.init_app(app)
    compress.init_app(app)
    required_setting_missing = False

    @app.before_request
    def clear_trailing():
        request_path = request.path

        if request_path != "/" and request_path.endswith("/"):
            return redirect(request_path[:-1])

    app.config.from_object(default_settings)

    if config_mode:
        app.config.from_object(getattr(config, config_mode))
    elif config_file:
        app.config.from_pyfile(config_file)
    else:
        app.config.from_envvar("APP_SETTINGS", silent=True)

    username = app.config.get("RQ_DASHBOARD_USERNAME")
    password = app.config.get("RQ_DASHBOARD_PASSWORD")
    prefix = app.config.get("API_URL_PREFIX")
    server_name = app.config.get("SERVER_NAME")

    for setting in app.config.get("REQUIRED_SETTINGS", []):
        if not app.config.get(setting):
            required_setting_missing = True
            logger.error(f"App setting {setting} is missing!")

    if app.config.get("PROD_SERVER"):
        if server_name:
            logger.info(f"SERVER_NAME is {server_name}.")
        else:
            logger.error(f"SERVER_NAME is not set!")

        for setting in app.config.get("REQUIRED_PROD_SETTINGS", []):
            if not app.config.get(setting):
                required_setting_missing = True
                logger.error(f"App setting {setting} is missing!")

    if not required_setting_missing:
        logger.info(f"All required app settings present!")

    if username and password:
        add_basic_auth(blueprint=rq, username=username, password=password)
        logger.info(f"Creating RQ-dashboard login for {username}")

    app.register_blueprint(api)
    app.register_blueprint(rq, url_prefix=f"{prefix}/dashboard")

    if app.config.get("TALISMAN"):
        from flask_talisman import Talisman

        Talisman(app)

    if app.config.get("HEROKU") or app.config.get("DEBUG_MEMCACHE"):
        cache_type = get_cache_type(spread=False)
    else:
        cache_type = "filesystem"

    if config_mode not in {"Production", "Custom", "Ngrok"}:
        app.config["ENVIRONMENT"] = "staging"

    cache_config = get_cache_config(cache_type, **app.config)

    ###########################################################################
    # TODO - remove once mezmorize PR is merged
    if cache_type == "filesystem" and not cache_config.get("CACHE_DIR"):
        cache_config["CACHE_DIR"] = path.join(
            path.abspath(path.dirname(__file__)), "cache")
    ###########################################################################

    cache.init_app(app, config=cache_config)
    return app
コード例 #6
0
ファイル: __init__.py プロジェクト: dmitrypol/covid19
from flask_assets import Environment, Bundle
from flask_caching import Cache
from flask_marshmallow import Marshmallow
from flask_rq2 import RQ
import rq_dashboard
from rq_dashboard.cli import add_basic_auth
import chartkick

APP = Flask(__name__)
APP.config.from_pyfile('config.py')
MA = Marshmallow(APP)

#   https://github.com/metabolize/rq-dashboard-on-heroku/blob/master/app.py#L10-L16
add_basic_auth(
    blueprint=rq_dashboard.blueprint,
    username=os.environ.get('RQ_DASHBOARD_USERNAME'),
    password=os.environ.get('RQ_DASHBOARD_PASSWORD'),
)
APP.register_blueprint(rq_dashboard.blueprint, url_prefix='/rq')

WALRUS_DB = APP.config.get('WALRUS_DB')
RQ_CLIENT = RQ(APP)
CACHE = Cache(APP)

ASSETS = Environment(APP)
JSB = Bundle('main.js', output='tmp/main.js')
ASSETS.register('js_all', JSB)

CK = Blueprint('ck_page',
               __name__,
               static_folder=chartkick.js(),