feat: plugin call dify

This commit is contained in:
Yeuoly
2024-07-08 22:37:20 +08:00
parent 603187393a
commit 364df36ac4
9 changed files with 161 additions and 5 deletions

View File

@ -5,11 +5,12 @@ from hmac import new as hmac_new
from flask import abort, current_app, request
from configs import dify_config
from extensions.ext_database import db
from models.model import EndUser
def inner_api_only(view):
def enterprise_inner_api_only(view):
@wraps(view)
def decorated(*args, **kwargs):
if not current_app.config['INNER_API']:
@ -25,7 +26,7 @@ def inner_api_only(view):
return decorated
def inner_api_user_auth(view):
def enterprise_inner_api_user_auth(view):
@wraps(view)
def decorated(*args, **kwargs):
if not current_app.config['INNER_API']:
@ -59,3 +60,18 @@ def inner_api_user_auth(view):
return view(*args, **kwargs)
return decorated
def plugin_inner_api_only(view):
@wraps(view)
def decorated(*args, **kwargs):
if not dify_config.PLUGIN_INNER_API_KEY:
abort(404)
# get header 'X-Inner-Api-Key'
inner_api_key = request.headers.get('X-Inner-Api-Key')
if not inner_api_key or inner_api_key != dify_config.PLUGIN_INNER_API_KEY:
abort(404)
return view(*args, **kwargs)
return decorated