Commit 5d050968 authored by Robin Obůrka's avatar Robin Obůrka

Use app factory and rename v1 API module for better handling in factory

parent 6b0cce2e
from logging.config import dictConfig
from flask import Flask
app = Flask(__name__, instance_relative_config=True)
app.config.from_object("certapi.default_settings")
app.config.from_pyfile("local.cfg", silent=True)
app.config.from_envvar("FLASK_APP_SETTINGS", silent=True)
def setup_logging():
dictConfig({
"version": 1,
"root": {
"level": "INFO",
},
})
def create_app(additional_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_object("certapi.default_settings")
app.config.from_pyfile("local.cfg", silent=True)
app.config.from_envvar("FLASK_APP_SETTINGS", silent=True)
if additional_config:
app.config.from_mapping(additional_config)
setup_logging()
from .apiv1 import apiv1
app.register_blueprint(apiv1, url_prefix="/v1")
from certapi.views import apiv1
app.register_blueprint(apiv1, url_prefix="/v1")
return app
......@@ -8,7 +8,6 @@ from flask import jsonify
from flask import g
from flask import current_app
from certapi import app
from certapi.authentication import process_request
......@@ -18,9 +17,9 @@ apiv1 = Blueprint("apiv1", __name__)
def get_redis():
r = g.get('redis', None)
if r is None:
r = g.redis = redis.StrictRedis(host=app.config["REDIS_HOST"],
port=app.config["REDIS_PORT"],
password=app.config["REDIS_PASSWORD"],
r = g.redis = redis.StrictRedis(host=current_app.config["REDIS_HOST"],
port=current_app.config["REDIS_PORT"],
password=current_app.config["REDIS_PASSWORD"],
db=0)
return r
......
......@@ -2,7 +2,6 @@ import json
from flask import current_app
from certapi import app
from certapi.crypto import create_random_sid, create_random_nonce, key_match
from certapi.exceptions import InvalidAuthStateError, InvalidSessionError, InvalidParamError
from certapi import validators
......@@ -38,7 +37,7 @@ def create_auth_session(sn, sid, csr_str, flags, auth_type, r):
"flags": flags,
}
r.setex(get_session_key(sn, sid),
app.config["REDIS_SESSION_TIMEOUT"],
current_app.config["REDIS_SESSION_TIMEOUT"],
json.dumps(session))
return {
"status": "authenticate",
......@@ -155,7 +154,7 @@ def push_csr(sn, sid, session, digest, r):
pipe = r.pipeline(transaction=True)
pipe.delete(get_session_key(sn, sid))
pipe.setex(get_session_key(sn, sid),
app.config["REDIS_SESSION_TIMEOUT"],
current_app.config["REDIS_SESSION_TIMEOUT"],
json.dumps(session))
request = {
"sn": sn,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment