def create_app(app_name='api', blueprints=BLUEPRINTS): app = Flask(app_name) config = load_config() app.config.from_object(config) blueprints_resister(app, blueprints) extensions_load(app) @app.before_request def verify_user(): if request.path in ('/v1/child_photo/like', ): open_id = request.args.get('openid') if not open_id: if 'MicroMessenger' in request.user_agent.to_header(): # 说明是微信客户端 wx_callback = request.args.get('event_path') wx_callback = '{}&openid=1'.format(wx_callback) if wx_callback is not None: wx_callback_api_url = "https://}".format( callback_url=wx_callback) resp = make_response( jsonify({ 'data': { 'code': 999, 'wx_callback': wx_callback_api_url } })) print('wx_callxxxxx: {}'.format(wx_callback_api_url)) # resp.headers['location'] = wx_callback_api_url return resp return app
def create_protected_endpoint(self): class ProtectedEndpoint(Resource): @auth def get(self): return "Lorem ipsum sit dolor amet" rest_api.resources = [] rest_api.add_resource(ProtectedEndpoint, "/protected_resource") self.app = create_app(load_config()) self.client = self.app.test_client()
def create_app(app_name='api', blueprints=None): app = Flask(app_name) config = load_config() app.config.from_object(config) if not blueprints: blueprints = BLUEPRINTS blueprints_resister(app, blueprints) extensions_load(app) return app
envK = "HTTP_X_PROXY_REMOTE_USER" # app.logger.info("Found remote user: "******"HTTP_X_REMOTE_USER")) if (envK in env) and env.get(envK): # print("We're live") return env.get(envK) elif ("DEBUG" in app.config) and app.config["DEBUG"]: # print("We're in debug: " + cfg["DEBUG"]["user"]) return cfg["DEBUG"]["user"] else: return None ###################################################### # SETUP ###################################################### # Set up the Flask app app = Flask(__name__) from api.switch import switch from api.config import load_config cfg = load_config('api/config.yaml') @app.before_request def before_request(): g.dbDynamic = dynamicDB.connect() @app.teardown_request def teardown_request(exception): dbD = getattr(g, 'dbDynamic', None) if (dbD is not None) and (not dbD.is_closed()): dbD.close()
from peewee import * from playhouse.migrate import * from api.models import * from api.config import load_config here = os.path.dirname(__file__) cfg = load_config(os.path.join(here, 'api/config.yaml')) # db = os.path.join(here,cfg['databases']['dynamic']) # print("db", db) # mainDB = SqliteDatabase(cfg['databases']['dev']) # my_db = SqliteDatabase(db, # pragmas = ( ('busy_timeout', 100), # ('journal_mode', 'WAL') # ), # threadlocals = True # ) mainDB = MySQLDatabase("urcpp_flask_v2", host="db", user="******", passwd="DanforthLabor123!") # Creates the class that will be used by Peewee to store the database class dbModel(Model): class Meta: database = mainDB migrator = MySQLMigrator(mainDB)
import json from flask import Flask, request, make_response, jsonify from api.config import load_config from extensions import migrate, db, celery from api.resources import BLUEPRINTS config = load_config() def create_app(app_name='api', blueprints=BLUEPRINTS): app = Flask(app_name) config = load_config() app.config.from_object(config) blueprints_resister(app, blueprints) extensions_load(app) @app.before_request def verify_user(): if request.path in ('/v1/child_photo/like', ): open_id = request.args.get('openid') if not open_id: if 'MicroMessenger' in request.user_agent.to_header(): # 说明是微信客户端 wx_callback = request.args.get('event_path') wx_callback = '{}&openid=1'.format(wx_callback) if wx_callback is not None: wx_callback_api_url = "https://}".format( callback_url=wx_callback) resp = make_response(
else: return None ###################################################### # SETUP ###################################################### # Set up the Flask app base_path = os.path.dirname(__file__) app = Flask(__name__) app.config.from_pyfile("settings.py") from api.config import load_config # cfg = load_config('/var/www/html/urcpp-flask/api/config.yaml') cfg = load_config(os.path.join(base_path, 'config.yaml')) app.config['SECRET_KEY'] = open(os.path.join(base_path, 'secret_key'), 'rb').read() app.config['TEMPLATE_AUTO_RELOAD'] = True login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' login_manager.login_message = None mail = Mail(app) #mail using configuration values of the application from api.switch import switch @app.before_request
def __init__(self, config_name="ModisAPI"): self._config = load_config(Modis.CONFIG_PATH, config_name) self._defaults = self._config['defaults'] self._modis_tiles = self._load_modis_tiles() self._api_key = get_api_key(self._config) self._m = m.ModapsClient()
def __init__(self, config_name="SentinelAPI"): self._config = load_config(Sentinel5P.CONFIG_PATH, config_name) self._defaults = self._config['default'] self._api_link = self._config['api_link'] user, password = get_credentials(self._config) self._api = SentinelAPI(user, password, self._api_link)