from functools import wraps
from flask import Flask, request, g, jsonify
import core
import sqlite3

app = Flask(__name__)
app.API_KEY = ''


def require_api_key(route_function):
    """
    authenticate via API key in the request header
    
    :param route_function: the called API endpoint 
    :return: the wrapper authentication function callback
    """

    @wraps(route_function)
    def check_api_key(*args, **kwargs):
        if request.headers.get('X-Api-Key') and request.headers.get('X-Api-Key') == app.API_KEY:
            return route_function(*args, **kwargs)
        else:
            return jsonify(message='unauthorized: wrong or missing api key', code=401)

    return check_api_key


def _get_db():
    """
    get a sqlite3 database handle
    
Ejemplo n.º 2
0
from flask import Flask, request, abort, json
from functools import wraps
from flask_api import status
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import IntegrityError
from wtforms import Form, StringField, validators
from wtforms.validators import (DataRequired, Email)
from flask_cors import CORS
from datadog import DogStatsd

import config

statsd = DogStatsd(config.STATSD_HOST, config.STATSD_PORT, namespace='app-registration')

app = Flask(__name__)
app.API_KEY = config.API_KEY
CORS(app)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://{}:{}@{}:5432/{}'.format(config.DB_ROLE,
                                                                               config.DB_PASSWORD,
                                                                               config.DB_HOST,
                                                                               config.DB_NAME.lower())
app.config['APP_ID'] = config.API_KEY
db = SQLAlchemy(app)

APP_ID_LENGTH = 4
MIN_LENGTH = 2
MAX_LENGTH = 250
PUBLIC_WALLET_LENGTH = 56
APP_ID_PATTERN = r'([a-zA-Z0-9]{4})'
PUBLIC_ADDRESS_PATTERN = r'G([A-Z0-9]{55})'