- Add API Key Registration to tenant
This commit is contained in:
@@ -435,6 +435,36 @@ def generate_chat_api_key():
|
||||
tenant.encrypted_chat_api_key = simple_encryption.encrypt_api_key(new_api_key)
|
||||
update_logging_information(tenant, dt.now(tz.utc))
|
||||
|
||||
try:
|
||||
db.session.add(tenant)
|
||||
db.session.commit()
|
||||
except SQLAlchemyError as e:
|
||||
db.session.rollback()
|
||||
current_app.logger.error(f'Unable to store chat api key for tenant {tenant.id}. Error: {str(e)}')
|
||||
|
||||
return jsonify({'api_key': new_api_key}), 200
|
||||
|
||||
|
||||
@user_bp.route('/check_api_api_key', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def check_api_api_key():
|
||||
tenant_id = session['tenant']['id']
|
||||
tenant = Tenant.query.get_or_404(tenant_id)
|
||||
|
||||
if tenant.encrypted_api_key:
|
||||
return jsonify({'api_key_exists': True})
|
||||
return jsonify({'api_key_exists': False})
|
||||
|
||||
|
||||
@user_bp.route('/generate_api_api_key', methods=['POST'])
|
||||
@roles_accepted('Super User', 'Tenant Admin')
|
||||
def generate_api_api_key():
|
||||
tenant = Tenant.query.get_or_404(session['tenant']['id'])
|
||||
|
||||
new_api_key = generate_api_key(prefix="EveAI-API")
|
||||
tenant.encrypted_api_key = simple_encryption.encrypt_api_key(new_api_key)
|
||||
update_logging_information(tenant, dt.now(tz.utc))
|
||||
|
||||
try:
|
||||
db.session.add(tenant)
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user