def __init__(self, db): self.postman = Postman( **{ 'mailgun_key': settings.get('default', 'mailgun_key'), 'mailgun_domain': settings.get("default", "mailgun_domain"), 'sendgrid_key': settings.get('default', 'sendgrid_key') }) self.db = db
def init_wiki_es(cls): if cls._wiki_es is None: from app import settings wiki_es = settings.get('WIKI_ES') wiki_es_max_retries = settings.get('WIKI_ES_MAX_RETRIES') wiki_es_timeout = settings.get('WIKI_ES_TIMEOUT') if wiki_es is None: raise WikiUndefinedException else: cls._wiki_es = Elasticsearch(wiki_es, max_retries=wiki_es_max_retries, timeout=wiki_es_timeout)
def __init__(self, conn_string=None): logger.info(conn_string) self.engine = create_engine( conn_string or self.conn_string, echo=settings.get("DB", "SQLALCHEMY_ECHO", boolean=True), ) Session = sessionmaker(bind=self.engine) self.session = Session() Base.metadata.create_all(self.engine)
class DataAccessLayer(object): session = None engine = None db_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "..", settings.get("DB", "DB_URI"))) conn_string = "sqlite:///{}".format(db_path) def __init__(self, conn_string=None): logger.info(conn_string) self.engine = create_engine( conn_string or self.conn_string, echo=settings.get("DB", "SQLALCHEMY_ECHO", boolean=True), ) Session = sessionmaker(bind=self.engine) self.session = Session() Base.metadata.create_all(self.engine)
from app import settings from mailing import Postman def match_result(actual_result, expected_result): assert actual_result['status'] == expected_result[ 'status'] and actual_result['result'] == expected_result['result'] postman = Postman( **{ 'mailgun_key': settings.get('default', 'mailgun_key'), 'mailgun_domain': settings.get("default", "mailgun_domain"), 'sendgrid_key': settings.get('default', 'sendgrid_key') }) def init_postman(): return postman
""" Authentication Routes We're not using same client/server domain w cookies, all requests are CORS on JWT. So Oauth here gets tricky. See - https://github.com/discordapp/discord-oauth2-example original workflow - https://github.com/mattupstate/flask-jwt better use of JWT """ from requests_oauthlib import OAuth2Session OAUTH2_CLIENT_ID = settings.DISCORD_ID OAUTH2_CLIENT_SECRET = settings.DISCORD_SECRET OAUTH2_REDIRECT_URI = URL['server'] + '/discord/callback' API_BASE_URL = settings.get('API_BASE_URL', 'https://discordapp.com/api') AUTHORIZATION_BASE_URL = API_BASE_URL + '/oauth2/authorize' TOKEN_URL = API_BASE_URL + '/oauth2/token' if 'http://' in OAUTH2_REDIRECT_URI: settings['OAUTHLIB_INSECURE_TRANSPORT'] = 'true' def token_updater(token): print("Why was this called?!??") # g.discord_tokens['oauth2_token'] = token def make_session(token=None, state=None, scope=None): return OAuth2Session(client_id=OAUTH2_CLIENT_ID, token=token,
def get(settings, var, default): return settings.get(var, default)
def init_max_size(cls): if cls._max_wiki_desc_size is None: from app import settings cls._max_wiki_desc_size = settings.get('WIKI_DESC_MAX_SIZE')