Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
7fd64b72
Unverified
Commit
7fd64b72
authored
Feb 23, 2024
by
Yeuoly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename: enterprise to inner api
parent
62b79cd9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
13 deletions
+40
-13
.env.example
api/.env.example
+2
-2
app.py
api/app.py
+3
-3
config.py
api/config.py
+3
-3
__init__.py
api/controllers/inner_api/__init__.py
+7
-0
authorization.py
api/controllers/inner_api/authorization.py
+6
-5
wraps.py
api/controllers/inner_api/wraps.py
+19
-0
No files found.
api/.env.example
View file @
7fd64b72
...
...
@@ -2,8 +2,8 @@
EDITION=SELF_HOSTED
# Enterprise Options
ENTERPRISE
=
ENTERPRISE
_KEY=
INNER_API
=
INNER_API
_KEY=
# Your App secret key will be used for securely signing the session cookie
# Make sure you are changing this key for your deployment with a strong key.
...
...
api/app.py
View file @
7fd64b72
...
...
@@ -112,7 +112,7 @@ def initialize_extensions(app):
@
login_manager
.
request_loader
def
load_user_from_request
(
request_from_flask_login
):
"""Load user based on the request."""
if
request
.
blueprint
in
[
'console'
,
'
enterprise
'
]:
if
request
.
blueprint
in
[
'console'
,
'
inner_api
'
]:
# Check if the user_id contains a dot, indicating the old format
auth_header
=
request
.
headers
.
get
(
'Authorization'
,
''
)
if
not
auth_header
:
...
...
@@ -150,7 +150,7 @@ def register_blueprints(app):
from
controllers.files
import
bp
as
files_bp
from
controllers.service_api
import
bp
as
service_api_bp
from
controllers.web
import
bp
as
web_bp
from
controllers.
enterprise
import
bp
as
enterprise
_bp
from
controllers.
inner_api
import
bp
as
inner_api
_bp
CORS
(
service_api_bp
,
allow_headers
=
[
'Content-Type'
,
'Authorization'
,
'X-App-Code'
],
...
...
@@ -186,7 +186,7 @@ def register_blueprints(app):
)
app
.
register_blueprint
(
files_bp
)
app
.
register_blueprint
(
enterprise
_bp
)
app
.
register_blueprint
(
inner_api
_bp
)
# create app
app
=
create_app
()
...
...
api/config.py
View file @
7fd64b72
...
...
@@ -121,9 +121,9 @@ class Config:
self
.
SECRET_KEY
=
get_env
(
'SECRET_KEY'
)
# Enterprise Edition
# Only the
enterprise
edition can be set to True
self
.
ENTERPRISE
=
get_bool_env
(
'ENTERPRISE
'
)
self
.
ENTERPRISE_KEY
=
get_env
(
'ENTERPRISE
_KEY'
)
# Only the
inner_api
edition can be set to True
self
.
INNER_API
=
get_bool_env
(
'INNER_API
'
)
self
.
INNER_API_KEY
=
get_env
(
'INNER_API
_KEY'
)
# cors settings
self
.
CONSOLE_CORS_ALLOW_ORIGINS
=
get_cors_allow_origins
(
...
...
api/controllers/
enterprise
/__init__.py
→
api/controllers/
inner_api
/__init__.py
View file @
7fd64b72
from
flask
import
Blueprint
from
libs.external_api
import
ExternalApi
bp
=
Blueprint
(
'
enterprise'
,
__name__
,
url_prefix
=
'/enterprise
/api'
)
bp
=
Blueprint
(
'
inner_api'
,
__name__
,
url_prefix
=
'/inner
/api'
)
api
=
ExternalApi
(
bp
)
from
.
import
authorization
\ No newline at end of file
api/controllers/
enterprise
/authorization.py
→
api/controllers/
inner_api
/authorization.py
View file @
7fd64b72
from
flask_login
import
current_user
from
flask_restful
import
Resource
from
controllers.enterprise
import
api
from
controllers.console.setup
import
setup_required
from
controllers.inner_api
import
api
from
controllers.inner_api.wraps
import
inner_api_only
from
libs.login
import
login_required
from
controllers.enterprise.wraps
import
enterprise_only
from
flask_restful
import
Resource
class
EnterpriseAuthorizationApi
(
Resource
):
"""Authorization API for
enterprise
edition, share user and tenant info."""
"""Authorization API for
inner_api
edition, share user and tenant info."""
@
setup_required
@
login_required
@
enterprise
_only
@
inner_api
_only
def
get
(
self
):
current_tenant
=
current_user
.
current_tenant
return
{
...
...
api/controllers/
enterprise
/wraps.py
→
api/controllers/
inner_api
/wraps.py
View file @
7fd64b72
...
...
@@ -2,15 +2,16 @@ from functools import wraps
from
flask
import
abort
,
current_app
,
request
def
enterprise_only
(
view
):
def
inner_api_only
(
view
):
@
wraps
(
view
)
def
decorated
(
*
args
,
**
kwargs
):
if
not
current_app
.
config
[
'
ENTERPRISE
'
]:
if
not
current_app
.
config
[
'
INNER_API
'
]:
abort
(
404
)
# get header 'X-
Enterprise
-Key'
enterprise_key
=
request
.
headers
.
get
(
'X-Enterprise
-Key'
)
if
not
enterprise_key
or
enterprise_key
!=
current_app
.
config
[
'ENTERPRISE
_KEY'
]:
# 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
!=
current_app
.
config
[
'INNER_API
_KEY'
]:
abort
(
404
)
return
view
(
*
args
,
**
kwargs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment