This repository has been archived by the owner on Sep 14, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Resolves #20]
- Loading branch information
Showing
7 changed files
with
64 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: invoke serve --port $VCAP_APP_PORT | ||
web: gunicorn main:app --bind 0.0.0.0:$VCAP_APP_PORT --config hooks.py |
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,42 @@ | ||
import os | ||
|
||
from sandman import app | ||
|
||
from flask import request | ||
from flask.ext.cors import CORS | ||
from flask.ext.basicauth import BasicAuth | ||
|
||
import aws | ||
import utils | ||
import config | ||
|
||
def make_app(): | ||
app.json_encoder = utils.APIJSONEncoder | ||
app.config['CASE_INSENSITIVE'] = config.CASE_INSENSITIVE | ||
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLA_URI | ||
app.config['BASIC_AUTH_USERNAME'] = os.environ.get('AUTOAPI_ADMIN_USERNAME', '') | ||
app.config['BASIC_AUTH_PASSWORD'] = os.environ.get('AUTOAPI_ADMIN_PASSWORD', '') | ||
|
||
CORS(app) | ||
basic_auth = BasicAuth(app) | ||
|
||
@app.before_request | ||
def refresh(): | ||
tables = utils.get_tables() | ||
if tables != app.config['SQLALCHEMY_TABLES']: | ||
utils.refresh_tables() | ||
app.config['SQLALCHEMY_TABLES'] = tables | ||
app.config['SQLALCHEMY_TABLES'] = utils.get_tables() | ||
|
||
@app.before_request | ||
def protect_admin(): | ||
if request.path.startswith('/admin/'): | ||
if not basic_auth.authenticate(): | ||
return basic_auth.challenge() | ||
|
||
blueprint = aws.make_blueprint() | ||
app.register_blueprint(blueprint) | ||
|
||
utils.activate(admin=True) | ||
|
||
return app |
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,11 @@ | ||
import os | ||
import sys | ||
import multiprocessing | ||
|
||
sys.path.insert(0, os.getcwd()) | ||
import aws | ||
|
||
def when_ready(server): | ||
pool = multiprocessing.Pool(processes=1) | ||
pool.apply_async(aws.fetch_bucket) | ||
pool.close() |
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,3 @@ | ||
from app import make_app | ||
|
||
app = make_app() |
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