def lmio_api(dev=False, username=None, password=None): r""" Generate a Flask App that will serve meshes landmarks and templates to landmarker.io Parameters ---------- adapter: :class:`LandmarkerIOAdapter` Concrete implementation of the LandmarkerIOAdapter. Will be queried for all data to pass to landmarker.io. dev: `bool`, optional If True, listen to anyone for CORS. username : str, optional If provided basic auth will be applied for this username. Requires password to also be provided. password : str, optional If provided basic auth will be applied for this password. Requires username to also be provided. Returns ------- api, app, api_endpoint """ app = Flask(__name__) # create the flask app # 1. configure CORS decorator cors_dict = { 'origin': Server.origin, 'headers': ['Origin', 'X-Requested-With', 'Content-Type', 'Accept'], 'methods': ['HEAD', 'GET', 'POST', 'PATCH', 'PUT', 'OPTIONS', 'DELETE'], 'credentials': True } if dev: # in development mode, accept CORS from anyone (but we can't use HTTPS) cors_dict['origin'] = '*' cors_dict['credentials'] = False app.debug = True # create the cors decorator decorators = [cors.crossdomain(**cors_dict)] if username is not None and password is not None: print('enabling basic auth') # note the we cors is the last decorator -> the first that is hit. This # is what we want as CORS will detect OPTIONS requests and allow them # immediately. All other requests will be sent through the basicauth # decorator. decorators.insert(0, basicauth(username, password)) api = Api(app, decorators=decorators) return api, app
def lmio_api(dev=False, username=None, password=None): r""" Generate a Flask App that will serve meshes landmarks and templates to landmarker.io Parameters ---------- adapter: :class:`LandmarkerIOAdapter` Concrete implementation of the LandmarkerIOAdapter. Will be queried for all data to pass to landmarker.io. dev: `bool`, optional If True, listen to anyone for CORS. username : str, optional If provided basic auth will be applied for this username. Requires password to also be provided. password : str, optional If provided basic auth will be applied for this password. Requires username to also be provided. Returns ------- api, app, api_endpoint """ app = Flask(__name__) # create the flask app # 1. configure CORS decorator cors_dict = { "allowed_origins": Server.allowed_origins, "headers": ["Origin", "X-Requested-With", "Content-Type", "Accept"], "methods": ["HEAD", "GET", "POST", "PATCH", "PUT", "OPTIONS", "DELETE"], "credentials": True, } if dev: # in development mode we can't use basic auth cors_dict["credentials"] = False app.debug = True # create the cors decorator decorators = [cors.crossdomain(**cors_dict)] if username is not None and password is not None: print("enabling basic auth") # note the we cors is the last decorator -> the first that is hit. This # is what we want as CORS will detect OPTIONS requests and allow them # immediately. All other requests will be sent through the basicauth # decorator. decorators.insert(0, basicauth(username, password)) api = Api(app, decorators=decorators) return api, app
from flask import Flask, request from flask.ext import restful from datetime import timedelta from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy.exc import IntegrityError from flask_restful_swagger import swagger from cors import crossdomain import sanitize, serialize # configure the application and the database app = Flask(__name__) api = swagger.docs(restful.Api(app, decorators=[crossdomain('*')]), apiVersion='0.1') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) ############################################################################## class Tag(db.Model): ############################################################################## id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(140), unique=True) def __init__(self, name): self.name = name def __repr__(self): return '<Tag %r>' % self.name ##############################################################################
from flask import Flask, request from flask.ext import restful from datetime import timedelta from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy.exc import IntegrityError from flask_restful_swagger import swagger from cors import crossdomain import sanitize, serialize # configure the application and the database app = Flask(__name__) api = swagger.docs(restful.Api(app, decorators=[crossdomain('*')]), apiVersion='0.1') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) ############################################################################## class Tag(db.Model): ############################################################################## id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(140), unique=True) def __init__(self, name): self.name = name def __repr__(self): return '<Tag %r>' % self.name
import cors, jsonp # create flask application app = Flask(__name__) # load config from the config.api dictionary app.config.from_object('config.api') # initialize the database pool DB.init_pool(app.config['DATABASE']) # create the REST api api = Api(app) # CORS / allow calls from all origins (well, especially pgxn-tester.org, but not only) api.decorators=[cors.crossdomain(origin='*'), jsonp.support_jsonp] import index import distributions import users import machines import results import stats api.add_resource(index.Index, '/') api.add_resource(distributions.DistributionList, '/distributions') api.add_resource(distributions.Distribution, '/distributions/<string:name>') api.add_resource(distributions.Version, '/distributions/<string:name>/<string:version>') api.add_resource(results.Result, '/results/<string:rid>')
from flask.ext import restful from vaux.storage import LibreDB from datetime import datetime from werkzeug import secure_filename from cors import crossdomain app = Flask(__name__) config = ConfigParser.SafeConfigParser() config.read('/etc/vaux.ini') database = LibreDB( config.get('data', 'path'), config.get('database', 'host'), config.getint('database', 'port'), config.get('database', 'database')) from peer import PeerResource, PeerInstance from document import DocumentResource, DocumentInstance from downloads import DownloadInstance api = restful.Api(app) api.decorators=[crossdomain(origin='*')] api.add_resource(PeerResource, '/peers/') api.add_resource(PeerInstance, '/peers/<string:id>/') api.add_resource(DocumentResource, '/documents/') api.add_resource(DocumentInstance, '/documents/<string:id>/') api.add_resource(DownloadInstance, '/download/<string:id>/')