Beispiel #1
0
    def load_blueprints(self):
        """
        Load blueprints for common routes like swagger documentation,
        config, health and RPC routes.
        """
        from .blueprints import config_bp, health_bp, index_bp, call_rpc, list_rpc

        if self.config["ENABLE_SWAGGER_ROUTES"]:
            self.logger.debug("Enabling swagger routes...")
            swagger = get_swagger_blueprint()
            self.register_blueprint(swagger)
        if self.config["ENABLE_CONFIG_ROUTES"]:
            self.logger.debug("Enabling config routes...")
            self.register_blueprint(config_bp)
        if self.config["ENABLE_HEALTH_ROUTES"]:
            self.logger.debug("Enabling health routes...")
            self.register_blueprint(health_bp)
        if self.config["ENABLE_JSONRPC_ROUTES"]:
            self.logger.debug("Enabling RPC routes...")
            rpc_route = ("/" + self.config["API_VERSION"] + "/" +
                         self.config["RPC_BASE_ROUTE"] + "/" +
                         self.config["RPC_ROUTE_NAME"])
            self.add_url_rule(rpc_route,
                              "call_rpc",
                              view_func=call_rpc,
                              methods=["POST", "OPTIONS"])
            self.add_url_rule(rpc_route,
                              "list_rpc",
                              view_func=list_rpc,
                              methods=["GET", "OPTIONS"])
        if self.config["ENABLE_INDEX_ROUTES"]:
            self.logger.debug("Enabling index routes...")
            self.register_blueprint(index_bp)
Beispiel #2
0
def Main(environ, start_response):
    password = get_secret("mysql-password")
    username = get_secret("mysql-username")

    instance = Eve(logger=Logger(), settings=Settings(), validator=ValidatorSQL, data=SQL)
    instance.on_post_GET += log_get
    instance.register_blueprint(get_swagger_blueprint())

    healthcheck = EveHealthCheck(instance, "/healthcheck")

    database = instance.data.driver
    Base.metadata.bind = database.engine
    database.Model = Base 
    database.create_all()
    database.session.commit()

    def runner():
        instance.run(use_reloader=False)
def create_app():
    app = Eve()
    swagger = get_swagger_blueprint()
    app.register_blueprint(swagger)

    # required. See http://swagger.io/specification/#infoObject for details.
    app.config['SWAGGER_INFO'] = {
        'title': 'My Supercool API',
        'version': '1.0',
        'description': 'an API description',
        'termsOfService': 'my terms of service',
        'schemes': ['http', 'https'],
    }

    # optional. Will use flask.request.host if missing.
    app.config['SWAGGER_HOST'] = 'https://myhost.com'

    return app
    def setUp(self, settings=None):
        self.this_directory = os.path.dirname(os.path.realpath(__file__))
        if settings is None:
            settings = os.path.join(self.this_directory, "test_settings.py")

        self.setupDB()

        self.settings = settings
        self.app = eve.Eve(settings=self.settings)

        swagger = eve_swagger.get_swagger_blueprint()

        self.app.register_blueprint(swagger)
        self.app.config["SWAGGER_INFO"] = {
            "title": "Test eve-swagger",
            "version": "0.0.1",
        }

        self.test_client = self.app.test_client()
        self.domain = self.app.config["DOMAIN"]

        self.swagger_doc = self.get_swagger_doc()
Beispiel #5
0
 def load_blueprints(self):
     if self.config["ENABLE_SWAGGER_ROUTES"]:
         logger.debug("Enabling swagger routes...")
         swagger = get_swagger_blueprint()
         self.register_blueprint(swagger)
     if self.config["ENABLE_CONFIG_ROUTES"]:
         logger.debug("Enabling config routes...")
         self.register_blueprint(config_bp)
     if self.config["ENABLE_HEALTH_ROUTES"]:
         logger.debug("Enabling health routes...")
         self.register_blueprint(health_bp)
     # if self.config["ENABLE_JSONRPC_ROUTES"]:
     #     logger.debug("Enabling RPC routes...")
     #     rpc_route = '/' + self.config["API_VERSION"] + '/' + self.config["RPC_BASE_ROUTE"] + '/' + self.config["RPC_ROUTE_NAME"]
     #     self.add_url_rule(
     #         rpc_route, "call_rpc", view_func=call_rpc, methods=["POST", "OPTIONS"]
     #     )
     #     self.add_url_rule(
     #         rpc_route, "list_rpc", view_func=list_rpc, methods=["GET", "OPTIONS"]
     #     )
     if self.config["ENABLE_INDEX_ROUTES"]:
         logger.debug("Enabling index routes...")
         self.register_blueprint(index_bp)
Beispiel #6
0
from eve import Eve
from eve_swagger import get_swagger_blueprint, add_documentation

import logging

app = Eve()

swagger = get_swagger_blueprint()
app.register_blueprint(swagger)

# required. See http://swagger.io/specification/#infoObject for details.
app.config['SWAGGER_INFO'] = {
    'title': 'My Supercool API',
    'version': '1.0',
    'description': 'an API description',
    'termsOfService': 'my terms of service',
    'schemes': ['http', 'https'],
}

# optional. Will use flask.request.host if missing.
app.config['SWAGGER_HOST'] = 'https://inventorydoc.com'


def log_every_get_request(resource, request, payload):
    app.logger.info(request)


def log_every_post(resource, request):
    app.logger.info(resource)

Beispiel #7
0
                }
            }
        }
        self._validate_schema(schema, field, value, None)
        if not -180.0 <= value['coordinates'][0] <= 180.0:
            self._error(field, "Longitude must be in the range -180.0, 180.0")
        if not -90.0 <= value['coordinates'][1] <= 90.0:
            self._error(field, "Latitude must be in the range -90.0, 90.0")


settingsfile = path.join(path.abspath(path.dirname(__file__)), 'settings.py')
api = Eve(API_NAME, validator=KeySchemaValidator, settings=settingsfile)

Compress(api)

api.register_blueprint(get_swagger_blueprint())
api.config['SWAGGER_INFO'] = {
    'title': 'Taarifa API',
    'version': '0.1.0',
}

resource_url = lambda resource: '/' + api.config['URL_PREFIX'] + '/' + resource


def get_schema(resource):
    "Get the schema for a given resource."
    return api.config['DOMAIN'][resource]['schema']


def add_document(resource, document):
    "Add a new document to the given resource."