def create_app(): """Flask create app function.""" app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = _config.SQLALCHEMY_DATABASE_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = _config.SQLALCHEMY_TRACK_MODIFICATIONS app.config["BDC_AUTH_CLIENT_SECRET"] = _config.BDC_AUTH_CLIENT_SECRET app.config["BDC_AUTH_CLIENT_ID"] = _config.BDC_AUTH_CLIENT_ID app.config["BDC_AUTH_ACCESS_TOKEN_URL"] = _config.BDC_AUTH_ACCESS_TOKEN_URL app.config["JSONIFY_PRETTYPRINT_REGULAR"] = False app.config["JSON_SORT_KEYS"] = False app.config["REDOC"] = {"title": "BDC-STAC"} if __debug__: app.logger.setLevel(logging.DEBUG) with app.app_context(): db.init_app(app) Redoc(app, 'spec/openapi.yaml') from . import views return app
def create_app(config_name=None): """Create Brazil Data Cube application from config object. Args: config_name (string) Config instance name Returns: Flask Application with config instance scope """ app = Flask(__name__) conf = config.get_settings(config_name) app.config.from_object(conf) with app.app_context(): # Initialize Flask SQLAlchemy BDCCatalog(app) Redoc(app, 'spec/openapi.yaml') # Just make sure to initialize db before celery celery_app = celery.create_celery_app(app) celery.celery_app = celery_app setup_app(app) return app
def create_app(config_name='DevelopmentConfig'): """Create Brazil Data Cube application from config object. Args: config_name (string) Config instance name Returns: Flask Application with config instance scope """ app = Flask(__name__) conf = config.get_settings(config_name) app.config.from_object(conf) app.config['REDOC'] = { 'title': 'Web service to authentication (Oauth 2) - OBT', 'spec_route': '/oauth/docs' } if app.config.get('APM_APP_NAME') and app.config.get('APM_SECRET_TOKEN'): from elasticapm.contrib.flask import ElasticAPM app.config['ELASTIC_APM'] = { 'SERVICE_NAME': app.config['APM_APP_NAME'], 'SECRET_TOKEN': app.config['APM_SECRET_TOKEN'], 'SERVER_URL': app.config['APM_HOST'] } ElasticAPM(app) with app.app_context(): CORS(app, resources={r"/*": {"origins": "*"}}) _ = Redoc('./spec/openapi.yaml', app) # DB from bdc_oauth.utils.base_mongo import mongo mongo.init_app(app) mongo.app = app # DB Cache from bdc_oauth.utils.base_redis import redis redis.init_app(app) flask_bcrypt.init_app(app) # Setup blueprint from bdc_oauth.blueprint import bp app.register_blueprint(bp) return app
def create_app(): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = _config.SQLALCHEMY_DATABASE_URI app.config[ 'SQLALCHEMY_TRACK_MODIFICATIONS'] = _config.SQLALCHEMY_TRACK_MODIFICATIONS app.config['BDC_AUTH_CLIENT_SECRET'] = _config.BDC_AUTH_CLIENT_SECRET app.config['BDC_AUTH_CLIENT_ID'] = _config.BDC_AUTH_CLIENT_ID app.config['BDC_AUTH_ACCESS_TOKEN_URL'] = _config.BDC_AUTH_ACCESS_TOKEN_URL app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False app.config['JSON_SORT_KEYS'] = False app.config['REDOC'] = {'title': 'BDC-STAC'} with app.app_context(): BDCCatalog(app) Redoc(app, f'spec/api/{_config.BDC_STAC_API_VERSION}/STAC.yaml') from . import routes return app
def create_app(): """Flask create app function.""" app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = _config.SQLALCHEMY_DATABASE_URI app.config[ "SQLALCHEMY_TRACK_MODIFICATIONS"] = _config.SQLALCHEMY_TRACK_MODIFICATIONS app.config["BDC_AUTH_CLIENT_SECRET"] = _config.BDC_AUTH_CLIENT_SECRET app.config["BDC_AUTH_CLIENT_ID"] = _config.BDC_AUTH_CLIENT_ID app.config["BDC_AUTH_ACCESS_TOKEN_URL"] = _config.BDC_AUTH_ACCESS_TOKEN_URL app.config["JSONIFY_PRETTYPRINT_REGULAR"] = False app.config["JSON_SORT_KEYS"] = False app.config["REDOC"] = {"title": "BDC-STAC"} with app.app_context(): db.init_app(app) Redoc(app, "spec/api/STAC.yaml") from . import routes return app
'minimum': 10, 'maximum': 131072 }, 'height': { 'type': 'integer', 'minimum': 10, 'maximum': 131072 }, 'crop': { 'type': 'boolean' }, }, 'required': ['source'] } redoc = Redoc(app, 'openapi.yaml') @app.errorhandler(400) def bad_request(error): try: return {'error': error.description.message}, 400 except AttributeError: return {'error': error.description}, 400 def convert_common(req, source, fmt): if 'quality' in req and fmt != 'jpeg': return {'message': f"only jpeg format supports quality"}, 400 if 'transparent' in req and fmt != 'png': return {'message': f"only png format supports transparent"}, 400
from config import USER, PASSWORD, HOST, DBNAME from cube_builder_aws.business import CubeBusiness from cube_builder_aws.validators import validate from cube_builder_aws.utils.auth import require_oauth_scopes from cube_builder_aws.version import __version__ app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://{}:{}@{}:5432/{}'.format( USER, PASSWORD, HOST, DBNAME) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True app.config['REDOC'] = {'title': 'Cube Builder AWS', 'spec_route': '/docs'} BDCDatabase(app) business = CubeBusiness() _ = Redoc('./spec/openapi.yaml', app) ######################################### # REQUEST HTTP -> from API Gateway ######################################### @app.route("/", methods=["GET"]) def status(): return jsonify(message='Running', description='Cube Builder AWS', version=__version__), 200 @app.route("/create", methods=["POST"]) @require_oauth_scopes(scope="cube_builder_aws:metadata:POST") def create():
import os from flask import Flask from flask_redoc import Redoc app = Flask(__name__) app.config['REDOC'] = {'title':'Petstore'} redoc = Redoc('petstore.yml', app) @app.route('/') def index(): return "Hello World!" if __name__ == "__main__": app.run()
from api.app import app, api from time import sleep from flask_rest_api import Api, Blueprint import os from flask import Response, request, render_template from src.utils.pykafka_clients import Consumer import json from src.api.tasks import add_data, start_csv_producer, pull_transform_push from flask_redoc import Redoc from pykafka.common import OffsetType redoc = Redoc(app, "petstore.yml") info = { "version": 1, "topics": [{ "name": "Topic Visualizer", "topic": "covid.data.2 " }], } data_blueprint = Blueprint("streams", "streams", url_prefix="/", description="Operations on streams") @data_blueprint.route("/") def basic_info(): return info
import os from flask import Flask from flask_redoc import Redoc from marshmallow import Schema, fields class PetSchema(Schema): name = fields.Str() app = Flask(__name__) app.config['REDOC'] = {'title':'Petstore', 'marshmallow_schemas':[PetSchema]} redoc = Redoc(app,'petstore.yml') @app.route('/') def index(): return "Hello World!" @app.route('/random') def random(): """A cute furry animal endpoint. --- get: description: Get a random pet responses: 200: description: Return a pet content:
def test_redoc_yml(self): app = Flask(__name__) client = app.test_client() Redoc('petstore.yml', app) resp = client.get('/docs') assert resp.status_code == 200