Unverified Commit 7fd64b72 authored by Yeuoly's avatar Yeuoly

rename: enterprise to inner api

parent 62b79cd9
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
EDITION=SELF_HOSTED EDITION=SELF_HOSTED
# Enterprise Options # Enterprise Options
ENTERPRISE= INNER_API=
ENTERPRISE_KEY= INNER_API_KEY=
# Your App secret key will be used for securely signing the session cookie # 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. # Make sure you are changing this key for your deployment with a strong key.
......
...@@ -112,7 +112,7 @@ def initialize_extensions(app): ...@@ -112,7 +112,7 @@ def initialize_extensions(app):
@login_manager.request_loader @login_manager.request_loader
def load_user_from_request(request_from_flask_login): def load_user_from_request(request_from_flask_login):
"""Load user based on the request.""" """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 # Check if the user_id contains a dot, indicating the old format
auth_header = request.headers.get('Authorization', '') auth_header = request.headers.get('Authorization', '')
if not auth_header: if not auth_header:
...@@ -150,7 +150,7 @@ def register_blueprints(app): ...@@ -150,7 +150,7 @@ def register_blueprints(app):
from controllers.files import bp as files_bp from controllers.files import bp as files_bp
from controllers.service_api import bp as service_api_bp from controllers.service_api import bp as service_api_bp
from controllers.web import bp as web_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, CORS(service_api_bp,
allow_headers=['Content-Type', 'Authorization', 'X-App-Code'], allow_headers=['Content-Type', 'Authorization', 'X-App-Code'],
...@@ -186,7 +186,7 @@ def register_blueprints(app): ...@@ -186,7 +186,7 @@ def register_blueprints(app):
) )
app.register_blueprint(files_bp) app.register_blueprint(files_bp)
app.register_blueprint(enterprise_bp) app.register_blueprint(inner_api_bp)
# create app # create app
app = create_app() app = create_app()
......
...@@ -121,9 +121,9 @@ class Config: ...@@ -121,9 +121,9 @@ class Config:
self.SECRET_KEY = get_env('SECRET_KEY') self.SECRET_KEY = get_env('SECRET_KEY')
# Enterprise Edition # Enterprise Edition
# Only the enterprise edition can be set to True # Only the inner_api edition can be set to True
self.ENTERPRISE = get_bool_env('ENTERPRISE') self.INNER_API = get_bool_env('INNER_API')
self.ENTERPRISE_KEY = get_env('ENTERPRISE_KEY') self.INNER_API_KEY = get_env('INNER_API_KEY')
# cors settings # cors settings
self.CONSOLE_CORS_ALLOW_ORIGINS = get_cors_allow_origins( self.CONSOLE_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
......
from flask import Blueprint from flask import Blueprint
from libs.external_api import ExternalApi 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) api = ExternalApi(bp)
from . import authorization from . import authorization
\ No newline at end of file
from flask_login import current_user 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.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 libs.login import login_required
from controllers.enterprise.wraps import enterprise_only
from flask_restful import Resource
class EnterpriseAuthorizationApi(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 @setup_required
@login_required @login_required
@enterprise_only @inner_api_only
def get(self): def get(self):
current_tenant = current_user.current_tenant current_tenant = current_user.current_tenant
return { return {
......
...@@ -2,15 +2,16 @@ from functools import wraps ...@@ -2,15 +2,16 @@ from functools import wraps
from flask import abort, current_app, request from flask import abort, current_app, request
def enterprise_only(view):
def inner_api_only(view):
@wraps(view) @wraps(view)
def decorated(*args, **kwargs): def decorated(*args, **kwargs):
if not current_app.config['ENTERPRISE']: if not current_app.config['INNER_API']:
abort(404) abort(404)
# get header 'X-Enterprise-Key' # get header 'X-Inner-Api-Key'
enterprise_key = request.headers.get('X-Enterprise-Key') inner_api_key = request.headers.get('X-Inner-Api-Key')
if not enterprise_key or enterprise_key != current_app.config['ENTERPRISE_KEY']: if not inner_api_key or inner_api_key != current_app.config['INNER_API_KEY']:
abort(404) abort(404)
return view(*args, **kwargs) return view(*args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment