Пример #1
0
def limiter(app):
    limiter = Limiter(app, key_func=get_remote_address, headers_enabled=True)

    limiter.header_mapping = {
        HEADERS.LIMIT: "X-My-Limit",
        HEADERS.RESET: "X-My-Reset",
        HEADERS.REMAINING: "X-My-Remaining"
    }

    return limiter.shared_limit(app.config['GLOBAL_RATE_LIMITS'],
                                scope="salic_api")
Пример #2
0
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.cache import Cache

from config import Production
from hbc import debug_logging, online_logging, access_logging


# create a flask application - this ``app`` object will be used to handle
app = Flask(__name__)
app.config.from_object(Production())
api = Api(app)

db = SQLAlchemy(app)

auth = HTTPBasicAuth()

debug_logging(u'logs/error.log')
access_logging(u'logs/access.log')

logger = logging.getLogger('root')
access_logger = logging.getLogger('access')

limiter = Limiter(app, headers_enabled=True, global_limits=["10/minute"])
limiter.header_mapping = {
    HEADERS.LIMIT: "X-RateLimit-Limit",
    HEADERS.RESET: "X-RateLimit-Reset",
    HEADERS.REMAINING: "X-RateLimit-Remaining"
}

cache = Cache(app, config={'CACHE_TYPE': 'simple'})
Пример #3
0
from flask_limiter.util import get_remote_address
from personalwebpageapi.api.resources import BlogPosts
from personalwebpageapi.api.resources import BlogLatestPosts
from personalwebpageapi.api.resources import BlogPostsWithDrafts

app = Flask(__name__)

limiter = Limiter(
    app,
    key_func=get_remote_address,
    default_limits=["60 per minute"],
)

limiter.header_mapping = {
    HEADERS.LIMIT: "X-My-Limit",
    HEADERS.RESET: "X-My-Reset",
    HEADERS.REMAINING: "X-My-Remaining"
}

api = Api(app)
CORS(app)

api.add_resource(
    BlogPosts,
    '/posts',
    '/posts/<int:post_id>',
)

api.add_resource(
    BlogLatestPosts,
    '/latest-posts',