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
62b79cd9
Unverified
Commit
62b79cd9
authored
Feb 23, 2024
by
Yeuoly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enterprise
parent
52b12ed7
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
1 deletion
+67
-1
.env.example
api/.env.example
+4
-0
app.py
api/app.py
+3
-1
config.py
api/config.py
+5
-0
wraps.py
api/controllers/console/wraps.py
+1
-0
__init__.py
api/controllers/enterprise/__init__.py
+7
-0
authorization.py
api/controllers/enterprise/authorization.py
+29
-0
wraps.py
api/controllers/enterprise/wraps.py
+18
-0
No files found.
api/.env.example
View file @
62b79cd9
# Server Edition
EDITION=SELF_HOSTED
# Enterprise Options
ENTERPRISE=
ENTERPRISE_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.
# You can generate a strong key using `openssl rand -base64 42`.
...
...
api/app.py
View file @
62b79cd9
...
...
@@ -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
==
'console'
:
if
request
.
blueprint
in
[
'console'
,
'enterprise'
]
:
# Check if the user_id contains a dot, indicating the old format
auth_header
=
request
.
headers
.
get
(
'Authorization'
,
''
)
if
not
auth_header
:
...
...
@@ -150,6 +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
CORS
(
service_api_bp
,
allow_headers
=
[
'Content-Type'
,
'Authorization'
,
'X-App-Code'
],
...
...
@@ -185,6 +186,7 @@ def register_blueprints(app):
)
app
.
register_blueprint
(
files_bp
)
app
.
register_blueprint
(
enterprise_bp
)
# create app
app
=
create_app
()
...
...
api/config.py
View file @
62b79cd9
...
...
@@ -120,6 +120,11 @@ class Config:
# Alternatively you can set it with `SECRET_KEY` environment variable.
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'
)
# cors settings
self
.
CONSOLE_CORS_ALLOW_ORIGINS
=
get_cors_allow_origins
(
'CONSOLE_CORS_ALLOW_ORIGINS'
,
self
.
CONSOLE_WEB_URL
)
...
...
api/controllers/console/wraps.py
View file @
62b79cd9
...
...
@@ -92,3 +92,4 @@ def cloud_utm_record(view):
pass
return
view
(
*
args
,
**
kwargs
)
return
decorated
api/controllers/enterprise/__init__.py
0 → 100644
View file @
62b79cd9
from
flask
import
Blueprint
from
libs.external_api
import
ExternalApi
bp
=
Blueprint
(
'enterprise'
,
__name__
,
url_prefix
=
'/enterprise/api'
)
api
=
ExternalApi
(
bp
)
from
.
import
authorization
\ No newline at end of file
api/controllers/enterprise/authorization.py
0 → 100644
View file @
62b79cd9
from
flask_login
import
current_user
from
controllers.enterprise
import
api
from
controllers.console.setup
import
setup_required
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."""
@
setup_required
@
login_required
@
enterprise_only
def
get
(
self
):
current_tenant
=
current_user
.
current_tenant
return
{
'id'
:
current_user
.
id
,
'name'
:
current_user
.
name
,
'avatar'
:
current_user
.
avatar
,
'current_tenant'
:
{
'id'
:
current_tenant
.
id
,
'name'
:
current_tenant
.
name
,
'plan'
:
current_tenant
.
plan
,
},
'current_tenant_role'
:
current_tenant
.
current_role
}
api
.
add_resource
(
EnterpriseAuthorizationApi
,
'/authorization/info'
)
\ No newline at end of file
api/controllers/enterprise/wraps.py
0 → 100644
View file @
62b79cd9
from
functools
import
wraps
from
flask
import
abort
,
current_app
,
request
def
enterprise_only
(
view
):
@
wraps
(
view
)
def
decorated
(
*
args
,
**
kwargs
):
if
not
current_app
.
config
[
'ENTERPRISE'
]:
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'
]:
abort
(
404
)
return
view
(
*
args
,
**
kwargs
)
return
decorated
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