Exemple #1
0
from CTFd.api.v1.submissions import submissions_namespace
from CTFd.api.v1.tags import tags_namespace
from CTFd.api.v1.awards import awards_namespace
from CTFd.api.v1.hints import hints_namespace
from CTFd.api.v1.flags import flags_namespace
from CTFd.api.v1.files import files_namespace
from CTFd.api.v1.config import configs_namespace
from CTFd.api.v1.notifications import notifications_namespace
from CTFd.api.v1.pages import pages_namespace
from CTFd.api.v1.unlocks import unlocks_namespace
from CTFd.api.v1.category import category_namespace

api = Blueprint('api', __name__, url_prefix='/api/v1')
CTFd_API_v1 = Api(api, version='v1')

CTFd_API_v1.add_namespace(challenges_namespace, '/challenges')
CTFd_API_v1.add_namespace(tags_namespace, '/tags')
CTFd_API_v1.add_namespace(awards_namespace, '/awards')
CTFd_API_v1.add_namespace(hints_namespace, '/hints')
CTFd_API_v1.add_namespace(flags_namespace, '/flags')
CTFd_API_v1.add_namespace(submissions_namespace, '/submissions')
CTFd_API_v1.add_namespace(scoreboard_namespace, '/scoreboard')
CTFd_API_v1.add_namespace(teams_namespace, '/teams')
CTFd_API_v1.add_namespace(users_namespace, '/users')
CTFd_API_v1.add_namespace(statistics_namespace, '/statistics')
CTFd_API_v1.add_namespace(files_namespace, '/files')
CTFd_API_v1.add_namespace(notifications_namespace, '/notifications')
CTFd_API_v1.add_namespace(configs_namespace, '/configs')
CTFd_API_v1.add_namespace(pages_namespace, '/pages')
CTFd_API_v1.add_namespace(unlocks_namespace, '/unlocks')
CTFd_API_v1.add_namespace(category_namespace, '/category')
Exemple #2
0
"""API module."""
from flask_restx import Api

from reviews_microservice import __version__
from reviews_microservice.namespaces.publications_reviews import (
    api as publications_reviews_namespace,
)
from reviews_microservice.namespaces.token import api as token_namespace
from reviews_microservice.namespaces.users_reviews import api as users_reviews_namespace

api = Api(
    prefix="/v1",
    version=__version__,
    title="Reviews API",
    description="Reviews microservice for bookbnb",
    default="Reviews",
    default_label="Reviews operations",
    validate=True,
)

api.add_namespace(users_reviews_namespace, path='/user_reviews')
api.add_namespace(publications_reviews_namespace, path='/publication_reviews')
api.add_namespace(token_namespace, path='/token')


@api.errorhandler
def handle_exception(error: Exception):
    """When an unhandled exception is raised"""
    message = "Error: " + getattr(error, 'message', str(error))
    return {'message': message}, getattr(error, 'code', 500)
Exemple #3
0
def registerBlueprints(app: Flask):
    '''
    配置蓝图
    :param app:
    :return:
    '''
    SECRET_KEY = app.config.get('SECRET_KEY',
                                '11cfcdd982ee4964af7e94fa3488b218')
    BASE_PATH = app.config.get('BASE_PATH', '/')
    # Swagger 配置
    SWAGGER_API_VERSION = app.config.get('SWAGGER_API_VERSION', '1.0')
    SWAGGER_TITLE = app.config.get('SWAGGER_TITLE', 'Swagger API')
    SWAGGER_DESCRIPTION = app.config.get('SWAGGER_DESCRIPTION',
                                         'API Document specifications')
    SWAGGER_TERMS_URL = app.config.get('SWAGGER_TERMS_URL',
                                       'https://pingbook.top')
    SWAGGER_CONTACT = app.config.get('SWAGGER_CONTACT',
                                     '<pingbook.top> [email protected]')
    SWAGGER_CONTACT_URL = app.config.get('SWAGGER_CONTACT_URL',
                                         'https://pingbook.top')
    SWAGGER_CONTACT_EMAIL = app.config.get(
        'SWAGGER_CONTACT_EMAIL', '<pingbook.top> [email protected]')
    SWAGGER_LICENSE = app.config.get('SWAGGER_LICENSE', 'MIT')
    SWAGGER_LICENSE_URL = app.config.get('SWAGGER_LICENSE_URL',
                                         'https://pingbook.top')
    # controller路径
    CONTROLLERS_MODULE_PATH = app.config.get('CONTROLLERS_PATH',
                                             'app.api.controller')
    SWAGGER_API_VERSION = ''.join(SWAGGER_API_VERSION.split('.'))

    # blueprint = Blueprint('api', __name__,
    #                       url_prefix=url_prefix,
    #                       # static_url_path='core',
    #                       static_folder='static',
    #                       template_folder='templates')
    # flask-restplus对应的api接口
    api = Api(version=SWAGGER_API_VERSION,
              doc=BASE_PATH,
              security=SECRET_KEY,
              title=SWAGGER_TITLE,
              description=SWAGGER_DESCRIPTION,
              terms_url=SWAGGER_TERMS_URL,
              contact=SWAGGER_CONTACT,
              contact_url=SWAGGER_CONTACT_URL,
              contact_email=SWAGGER_CONTACT_EMAIL,
              license=SWAGGER_LICENSE,
              license_url=SWAGGER_LICENSE_URL)
    api.init_app(app)
    # 注册namespaces
    for name in find_modules(CONTROLLERS_MODULE_PATH,
                             include_packages=False,
                             recursive=True):
        log.info('导入的controller模块是: %s' % name)
        modname = import_string(name)
        for item in dir(modname):
            item = getattr(modname, item)
            if isinstance(item, Namespace):
                api.add_namespace(item)

    def default_error_handler(error):
        '''
           :param error: 对应下面的errr
           :return:
           '''
        msg = "WebRequest resulted in {}".format(error)
        log.exception(error, exc_info=True)
        responsecode = WebResponseCode.NOT_FOUND if isinstance(
            error, HTTPException) else WebResponseCode.INTERNAL_SERVER_ERROR
        responsemessage = getattr(error, 'message', msg)
        response = {
            'code': responsecode.code,
            'msg': responsemessage,
            'request_time':
            datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        }
        with app.app_context():
            return jsonify(response)

    for code in default_exceptions.keys():
        ex = default_exceptions.get(code)
        app.register_error_handler(ex, default_error_handler)
Exemple #4
0
from flask_restx import Api
from flask import Blueprint

from .main.controller.user_controller import api as user_ns
from .main.controller.auth_controller import api as auth_ns
from .main.controller.post_controller import api as post_ns
from .main.controller.health_controller import api as health_ns

blueprint = Blueprint('api', __name__, url_prefix='/api')

api = Api(blueprint,
          title='FLASK RESTPLUS(RESTX) API BOILER-PLATE WITH JWT',
          version='1.0',
          description='a boilerplate for flask restplus (restx) web service'
          )

api.add_namespace(user_ns, path='/v1/user')
api.add_namespace(auth_ns, path='/v1/auth')
api.add_namespace(health_ns, path='/health')
api.add_namespace(post_ns, path='/v1/post')
Exemple #5
0
                        x_host=1,
                        x_prefix=1)

# Set up Swagger and API
authorizations = {
    'bearer': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'Authorization'
    }
}

api = Api(app, authorizations=authorizations)

# Register namespaces
api.add_namespace(slack_api)
api.add_namespace(roman_api)
api.add_namespace(registration_api)

api.add_namespace(version_api, path='/')
api.add_namespace(status_api, path='/')

# Load configuration
config_file = 'config'
if importing.find_spec(config_file):
    app.config.from_object(config_file)

# App startup
if __name__ == '__main__':
    logger.info('Starting the application.')
    app.run(host="localhost", port=8080)
Exemple #6
0
from flask import Blueprint
from flask_restx import Api

from .records import rec_ns

api_v1 = Blueprint("api", __name__)
api_ = Api(
    api_v1,
    version="1.0",
    title="Records API",
    description="A simple REST API",
)

api_.add_namespace(rec_ns)
Exemple #7
0
from flask import Blueprint
from flask_restx import Api

from hello_world.blueprints.main.controllers.user_controller import api as user_ns

bp = Blueprint('api', __name__)

api = Api(bp,
          title="API Hello World",
          version="0.0.1",
          description="Apenas um hello world",
          doc="/docs")

api.add_namespace(user_ns, path="/hello")


def init_app(app):
    app.register_blueprint(bp, url_prefix='/api')
Exemple #8
0
"""app/__init__.py: Create api doc and add namespaces"""
__author__ = "Girard Alexandre"

from flask_restx import Api
from flask import Blueprint

from .main.controller.id_controller import api as client_ns

blueprint = Blueprint('api', __name__)

api = Api(blueprint,
          title='TP_CleanCode API',
          version='1.0',
          description='Evaluated API'
          )

api.add_namespace(client_ns, path='/client')
Exemple #9
0
except ModuleNotFoundError:
    from flask_restplus import Api

from packit_service.service.api.copr_builds import ns as copr_builds_ns
from packit_service.service.api.srpm_builds import ns as srpm_builds_ns
from packit_service.service.api.projects import ns as projects_ns
from packit_service.service.api.healthz import ns as healthz_ns
from packit_service.service.api.installations import ns as installations_ns
from packit_service.service.api.testing_farm import ns as testing_farm_ns
from packit_service.service.api.webhooks import ns as webhooks_ns
from packit_service.service.api.whitelist import ns as whitelist_ns

# https://flask-restplus.readthedocs.io/en/stable/scaling.html
blueprint = Blueprint("api", __name__, url_prefix="/api")
api = Api(
    app=blueprint,
    version="1.0",
    title="Packit Service API",
    description="https://packit.dev/packit-as-a-service",
)

api.add_namespace(copr_builds_ns)
api.add_namespace(projects_ns)
api.add_namespace(healthz_ns)
api.add_namespace(installations_ns)
api.add_namespace(testing_farm_ns)
api.add_namespace(webhooks_ns)
api.add_namespace(whitelist_ns)
api.add_namespace(koji_builds_ns)
api.add_namespace(srpm_builds_ns)
Exemple #10
0
from flask_restx import Api

from project.api.ping import ping_namespace
from project.api.users.views import users_namespace

api = Api(version="1.0", title="Users API", doc="/doc/")

api.add_namespace(ping_namespace, path="/ping")
api.add_namespace(users_namespace, path="/users")
Exemple #11
0
from flask_restx import Api

from .tarjetametrobus import api as tarjetametrobus
from .todos import api as todos
from .amazon import api as amazon

api = Api(
    title="Christhoval's Services",
    version='0.0.1',
    description='This is our sample API'
)

api.add_namespace(todos)
api.add_namespace(tarjetametrobus)
api.add_namespace(amazon)
Exemple #12
0
from flask_restx import Api
from flask_cors import CORS

from datos import db

from api.mozos_api import nsMozo
from api.productos_api import nsProducto
from api.adiciones_api import nsAdicion
from api.detalles_api import nsDetalle

app = Flask(__name__)
app.config[
    'SQLALCHEMY_DATABASE_URI'] = "postgresql://*****:*****@localhost/TuMenu"
CORS(app)
db.init_app(app)

with app.app_context():
    db.create_all()

api = Api(app,
          version='1.0.beta',
          title='TuMenú',
          description='Administracion de restaurante')

api.add_namespace(nsMozo)
api.add_namespace(nsProducto)
api.add_namespace(nsAdicion)
api.add_namespace(nsDetalle)

if __name__ == '__main__':
    app.run()
Exemple #13
0
from flask import Flask
from flask_restx import Api
from flask_cors import CORS

# ROUTES

from routes.ipfs import api as ipfs_api

app = Flask(__name__)

cors = CORS(app, supports_credentials=True)

api = Api()
api = Api(
    version='0.9.1',
    title='hesychasm',
    description='A serverless API for managing IPFS Content Identifiers (CIDs)',
    contact='*****@*****.**')

# NAMESPACES

api.add_namespace(ipfs_api)

api.init_app(app)

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5001)
Exemple #14
0
from flask_restx import Api
from .gdrive_api import api as ns1
from .speech_api import api as ns2
from .video_to_text_converter_api import api as ns3
from .mcq_generator_api import api as ns4
from .summarizer_api import api as ns5
from .gallery_api import api as ns6
from .tester_api import api as ns7

api = Api(
    version="0.1",
    title="Deep Read APIs",
    description=
    "APIs For uploading files, text transcription, summarization and MCQ generation."
)

api.add_namespace(ns1)
api.add_namespace(ns2)
api.add_namespace(ns3)
api.add_namespace(ns4)
api.add_namespace(ns5)
api.add_namespace(ns6)
api.add_namespace(ns7)
Exemple #15
0
from flask_restx import Api
from flask import Flask
from .api_namespace import api_ns

api = Api(version='0.1',
          title='Text Feature Extraction Backend API',
          description='Text Analytics')
api.add_namespace(api_ns)


def create_app(config_name):

    from core.config import config
    from werkzeug.middleware.proxy_fix import ProxyFix

    application = Flask(__name__)
    application.config.from_object(config[config_name])
    config[config_name].init_app(application)
    application.wsgi_app = ProxyFix(application.wsgi_app)

    return application
Exemple #16
0
from .main.controller.people_controller import api as people_ns
from .main.controller.communes_controller import api as communes_ns
from .main.controller.departements_controller import api as departements_ns
from .main.controller.mspp_report_age_controller import api as mspp_report_age_ns
from .main.controller.mspp_report_departement_controller import api as mspp_report_departement_ns

blueprint = Blueprint(
    'api',
    __name__,  #url_prefix='/api',
    static_url_path='static')

static_blueprint = Blueprint('reactjs',
                             __name__,
                             url_prefix='/',
                             static_url_path='static')

api = Api(blueprint,
          title='REST API for MLHAITI covid19',
          version='1.0',
          description='A rest ',
          doc='/')

api.add_namespace(people_ns, path='/api/people')
api.add_namespace(user_ns, path='/api/user')
api.add_namespace(communes_ns, path='/api/communes')
api.add_namespace(departements_ns, path='/api/departements')
api.add_namespace(mspp_report_age_ns, path='/api/mspp/report/age')
api.add_namespace(mspp_report_departement_ns,
                  path='/api/mspp/report/departement')
api.add_namespace(auth_ns)
Exemple #17
0
from CTFd.api.v1.unlocks import unlocks_namespace
from CTFd.api.v1.users import users_namespace

api = Blueprint("api", __name__, url_prefix="/api/v1")
CTFd_API_v1 = Api(api,
                  version="v1",
                  doc=current_app.config.get("SWAGGER_UI_ENDPOINT"))

CTFd_API_v1.schema_model("APISimpleErrorResponse",
                         APISimpleErrorResponse.schema())
CTFd_API_v1.schema_model("APIDetailedSuccessResponse",
                         APIDetailedSuccessResponse.schema())
CTFd_API_v1.schema_model("APISimpleSuccessResponse",
                         APISimpleSuccessResponse.schema())

CTFd_API_v1.add_namespace(challenges_namespace, "/challenges")
CTFd_API_v1.add_namespace(tags_namespace, "/tags")
CTFd_API_v1.add_namespace(topics_namespace, "/topics")
CTFd_API_v1.add_namespace(awards_namespace, "/awards")
CTFd_API_v1.add_namespace(hints_namespace, "/hints")
CTFd_API_v1.add_namespace(flags_namespace, "/flags")
CTFd_API_v1.add_namespace(submissions_namespace, "/submissions")
CTFd_API_v1.add_namespace(scoreboard_namespace, "/scoreboard")
CTFd_API_v1.add_namespace(teams_namespace, "/teams")
CTFd_API_v1.add_namespace(users_namespace, "/users")
CTFd_API_v1.add_namespace(statistics_namespace, "/statistics")
CTFd_API_v1.add_namespace(files_namespace, "/files")
CTFd_API_v1.add_namespace(notifications_namespace, "/notifications")
CTFd_API_v1.add_namespace(configs_namespace, "/configs")
CTFd_API_v1.add_namespace(pages_namespace, "/pages")
CTFd_API_v1.add_namespace(unlocks_namespace, "/unlocks")
Exemple #18
0
from flask_restx import Api

from src.castingagency.api.routes.actors import actor_namespace
from src.castingagency.api.routes.movies import movie_namespace
from src.castingagency.auth.auth import AuthError


api = Api(version="1.0", title="Casting Agency API", doc="/docs",
          description="Udacity Casting Agency API that provided details on movies and actors that the agency"
                      " has produced.", contact="Jamaal Sanders",
          contact_email="*****@*****.**")

# AuthError exceptions raised by the @requires_auth(permission) decorator method
@api.errorhandler(AuthError)
def auth_error(auth_error):
    print(auth_error)
    return {'message': auth_error.error['description'], 'success': False}, auth_error.status_code

api.add_namespace(actor_namespace, path="/actors")
api.add_namespace(movie_namespace, path="/movies")
from flask_restx import Api
from flask import Blueprint

from .user.controller import api as user_ns

# Import controller APIs as namespaces.
api_bp = Blueprint("api", __name__)

api = Api(api_bp, title="API", description="Main routes.")

# API namespaces
api.add_namespace(user_ns)
Exemple #20
0
from flask_restx import Api

from project.api.auth.views import namespace as auth_namespace
from project.api.ping.views import namespace as ping_namespace
from project.api.users.views import namespace as users_namespace

api = Api(version="1.0", title="Users API", doc="/doc")

api.add_namespace(ping_namespace, "/ping")
api.add_namespace(users_namespace, "/users")
api.add_namespace(auth_namespace, "/auth")
Exemple #21
0
from flask import Blueprint
from flask_restx import Api

from app.views.qrcode_decode import qrcode_api
from app.views.user import user_api

v1 = Blueprint("v1", __name__, url_prefix='/api/v1')
api_v1 = Api(v1)

api_v1.add_namespace(qrcode_api)
api_v1.add_namespace(user_api)
Exemple #22
0
from flask_restx import Api
from flask import Blueprint

# Namespaces
from .main.controller.product_controller import api as prod_ns
from .main.controller.store_controller import api as store_ns

blueprint = Blueprint('api', __name__)

api = Api(blueprint,
          title='Cargamos Store API',
          version='1',
          prefix='/api/v1',
          description='API REST')

api.add_namespace(prod_ns, path='/products')
api.add_namespace(store_ns, path='/stores')
from flask_restx import Api
from .controller import orders_blueprint, namespaces

# create swagger api
orders_swagger_api = Api(
    orders_blueprint,
    title="Customer Orders API",
    description="API Methods for managing Customer Orders",
    doc="/orders/help"  #/orders/help
)

# register all namespaces
for ns in namespaces:
    orders_swagger_api.add_namespace(ns)
Exemple #24
0
    'apikey': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'X-Token'
    }
}

api = Api(blueprint,
          title='Test Automation Backend',
          version='1.0',
          description='A backend for the Test Automation web service',
          authorizations = authorizations,
          security='apikey',
          doc='/' if os.getenv('BOILERPLATE_ENV') != 'prod' else False
          )

api.add_namespace(user_ns)
api.add_namespace(auth_ns)
api.add_namespace(cert_ns)
api.add_namespace(test_ns)
api.add_namespace(task_ns)
api.add_namespace(testresult_ns)
api.add_namespace(taskresource_ns)
api.add_namespace(endpoint_ns)
api.add_namespace(script_ns)
api.add_namespace(organization_ns)
api.add_namespace(team_ns)
api.add_namespace(store_ns)
api.add_namespace(setting_ns)
api.add_namespace(pypi_ns)
Exemple #25
0
# from .trace import API as TRACE_API
from .ssrs_reverse_proxy import api as SSRS_REVERSE_PROXY_API
from .meta import api as META_API
from .ops import api as OPS_API
import os

SSRS_BASE_URI = os.getenv('SSRS_BASE_URI')

# This will add the Authorize button to the swagger docs
# TODO oauth2 & openid may not yet be supported by restplus <- check on this
AUTHORIZATIONS = {
    'apikey': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'Authorization'
    }
}

API = Api(
    title='SSRS API',
    version='1.0',
    description='SSRS API for Service BC',
    prefix='/',
    security=['apikey'],
    authorizations=AUTHORIZATIONS)

API.add_namespace(OPS_API, path='/api/v1')
API.add_namespace(META_API, path='/api/v1')
API.add_namespace(SSRS_REVERSE_PROXY_API, path=f'/{SSRS_BASE_URI}')
Exemple #26
0
logger.add(os.path.join(LOGS_FOLDER, LOGS_FILE), rotation='500MB')

# Flask application
application = Flask(__name__)

# CORS setup
CORS(application)

# Crontab configurations
crontab = Crontab(application)
@crontab.job(minute='0,5,10,15,20,25,30,35,40,45,50,55')
def schedule_speed_test():
    dao = SpeedTestDAO()
    dao.save_test(run_speed_test())


# Add HTML endpoints

# Flask Rest_plus API
api = Api(app=application)

# Add API endpoints
api.add_namespace(speedtest_api, '/spdtest')


logger.info('Running.')

# Testing endpoint
if __name__ == '__main__':
    application.run(debug=True, host='0.0.0.0')
import logging
from os import getenv
from flask import Blueprint, current_app
from flask_restx import Api, abort
from service.api.namespaces.verication_profile_ns import api as verication_profile

log = logging.getLogger(__name__)

if getenv('API_VERSION') is not None:
    api_version = getenv('API_VERSION')
else:
    api_version = 1

print('!!!!!!!!!!!!!!!!!!!!!!!', api_version)
bp = Blueprint("api", __name__, url_prefix=f"/api/v{api_version}")
api = Api(bp,
          version=str(1),
          title='API',
          description='Skylove Admin Moderator API service')

api.add_namespace(verication_profile)


@api.errorhandler
def default_error_handler(e):
    message = 'An unhandled exception occurred.'
    log.exception(message)

    if not current_app.debug:
        abort(500, message)
Exemple #28
0
from flask import Blueprint
from flask_restx import Api

from app.views.api.user import user_api
from app.configs import CONFIG
from app.utils import errors
from app.views.api.demo import demo_api


v1 = Blueprint("v1", __name__, url_prefix='/api/v1')
api_v1 = Api(v1, title='普通用户接口', doc=CONFIG.DOC_URL_PATH, description=errors.gen_doc())
api_v1.add_namespace(user_api)
api_v1.add_namespace(demo_api)
Exemple #29
0
from flask import Blueprint
from flask_restx import Api

from resources.pages import pages_collection
from resources.users import users_collection
from resources.banks import banks_collection

blueprint = Blueprint('api_v1', __name__, url_prefix='/open-banking/v1')
api = Api(
    blueprint, 
    title='Safra Open API', 
    version='1.0.0', 
    description='Safra Open feature set',
    contact='',
    catch_all_404s = True,
    ordered = True
)

api.add_namespace(pages_collection)
api.add_namespace(users_collection)
api.add_namespace(banks_collection)
Exemple #30
0
from flask_restx import Api

from simple_events.apis.auth import api as ns_auth
from simple_events.apis.event import api as ns_event
from simple_events.apis.ticket import api as ns_ticket


api = Api(
    title='Simple Events API',
    version='1.0',
    description='An API for a simple Events & Tickets management.'
)

# Add namespaces
api.add_namespace(ns_auth)
api.add_namespace(ns_event)
api.add_namespace(ns_ticket)