- Getting containers ready for the cloud
This commit is contained in:
@@ -1,22 +1,28 @@
|
||||
import logging
|
||||
import logging.config
|
||||
from flask import Flask, jsonify
|
||||
from redis import Redis
|
||||
import os
|
||||
|
||||
from common.extensions import db, socketio, jwt, kms_client, cors, session
|
||||
from common.extensions import db, socketio, jwt, cors, session, simple_encryption
|
||||
from config.logging_config import LOGGING
|
||||
from eveai_chat.socket_handlers import chat_handler
|
||||
from common.utils.cors_utils import create_cors_after_request
|
||||
from common.utils.celery_utils import make_celery, init_celery
|
||||
from config.config import get_config
|
||||
|
||||
|
||||
def create_app(config_file=None):
|
||||
app = Flask(__name__)
|
||||
|
||||
if config_file is None:
|
||||
app.config.from_object('config.config.DevConfig')
|
||||
else:
|
||||
app.config.from_object(config_file)
|
||||
environment = os.getenv('FLASK_ENV', 'development')
|
||||
|
||||
match environment:
|
||||
case 'development':
|
||||
app.config.from_object(get_config('dev'))
|
||||
case 'production':
|
||||
app.config.from_object(get_config('prod'))
|
||||
case _:
|
||||
app.config.from_object(get_config('dev'))
|
||||
|
||||
app.config['SESSION_KEY_PREFIX'] = 'eveai_chat_'
|
||||
|
||||
@@ -55,7 +61,8 @@ def register_extensions(app):
|
||||
ping_interval=app.config.get('SOCKETIO_PING_INTERVAL'),
|
||||
)
|
||||
jwt.init_app(app)
|
||||
kms_client.init_app(app)
|
||||
# kms_client.init_app(app)
|
||||
simple_encryption.init_app(app)
|
||||
|
||||
# Cors setup
|
||||
cors.init_app(app, resources={r"/chat/*": {"origins": "*"}})
|
||||
|
||||
@@ -6,7 +6,7 @@ from flask import current_app, request, session
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from common.extensions import socketio, kms_client, db
|
||||
from common.extensions import socketio, db, simple_encryption
|
||||
from common.models.user import Tenant
|
||||
from common.models.interaction import Interaction
|
||||
from common.utils.celery_utils import current_celery
|
||||
@@ -156,7 +156,7 @@ def handle_feedback(data):
|
||||
|
||||
def validate_api_key(tenant_id, api_key):
|
||||
tenant = Tenant.query.get_or_404(tenant_id)
|
||||
decrypted_api_key = kms_client.decrypt_api_key(tenant.encrypted_chat_api_key)
|
||||
decrypted_api_key = simple_encryption.decrypt_api_key(tenant.encrypted_chat_api_key)
|
||||
|
||||
return decrypted_api_key == api_key
|
||||
|
||||
|
||||
Reference in New Issue
Block a user