def decorated(*args, **kwargs): black_ls = api_cfg().get('user_blacklist') white_ls = api_cfg().get('user_whitelist') remote_addr = user_ip_address() # prohibited ip's if black_ls: if remote_addr in black_ls.split(','): return AccessDeniedResponse() # for when were guarding access if white_ls: if remote_addr not in white_ls.split(','): return AccessDeniedResponse() return func(*args, **kwargs)
def decorated(*args, **kwargs): black_ls = api_cfg().get('user_blacklist') white_ls = api_cfg().get('user_whitelist') denied_response = make_response(jsonify({'msg': 'Access Denied'}), 403) if 'X-Forwarded-For' in request.headers: remote_addr = request.headers.getlist('X-Forwarded-For')[0].rpartition(' ')[-1] else: remote_addr = request.remote_addr or 'untrackable' # prohibited ip's if black_ls: if remote_addr in black_ls.split(','): return denied_response # for when were guarding access if white_ls: if remote_addr not in white_ls.split(','): return denied_response return func(*args, **kwargs)
from api.providers.configuration.configuration_provider import ConfigurationProvider from api.util import api_cfg from api.system.logger import ilogger as logger from http_user import Index, VersionInfo, AvailableProducts, ValidationInfo,\ ListOrders, Ordering, UserInfo, ItemStatus, BacklogStats, PublicSystemStatus from http_production import ProductionVersion, ProductionConfiguration, ProductionOperations, ProductionManagement from http_admin import Reports, SystemStatus, OrderResets, ProductionStats from http_json import MessagesResponse, BadRequestResponse, SystemErrorResponse config = ConfigurationProvider() app = Flask(__name__) app.secret_key = api_cfg('config').get('key') @app.errorhandler(404) def page_not_found(e): errors = MessagesResponse(errors=['{} not found on the server' .format(request.path)], code=404) return errors() @app.errorhandler(IndexError) def no_results_found(e): return MessagesResponse(warnings=['No results found.'], code=200)()
def stat_whitelist(): return api_cfg()['stat_whitelist']
def admin_whitelist(): return api_cfg()['admin_whitelist']
def __init__(self): # fetch vars set in api_cfg['config'] for k, v in api_cfg().iteritems(): self.__setattr__(k, v)
def db_instance(): return DBConnect(**api_cfg('db'))
from flask import Flask, request from flask.ext.restful import Api, Resource, reqparse, fields, marshal from api.providers.configuration.configuration_provider import ConfigurationProvider from api.util import api_cfg from http_user import Index, VersionInfo, AvailableProducts, ValidationInfo, ListOrders, Ordering, UserInfo, ItemStatus from http_production import ProductionVersion, ProductionConfiguration, ProductionOperations, ProductionManagement from http_admin import Reports, SystemStatus, OrderResets config = ConfigurationProvider() app = Flask(__name__) app.secret_key = api_cfg("config").get("key") errors = {"NotFound": {"message": "The requested URL was not found on the server.", "status": 404}} transport_api = Api(app, errors=errors, catch_all_404s=True) # USER facing functionality transport_api.add_resource(Index, "/") transport_api.add_resource(VersionInfo, "/api", "/api/", "/api/v<version>") transport_api.add_resource( AvailableProducts, "/api/v<version>/available-products/<prod_id>", "/api/v<version>/available-products" )