Repository: TencentBlueKing/bk-user

Issue:
[合并] support-files
二进制出包的support-files目前独立私有仓库维护

放github, 改流水线




Discussion:
adapters没什么内容了, 看下把这个仓库合并到github

-----

放在类似build目录
我这边本周抽空处理

Resolving patch:
diff --git a/src/build/api/manage.py b/src/build/api/manage.py
new file mode 100644
--- /dev/null
+++ b/src/build/api/manage.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bkuser_core.config.overlays.prod")
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError:
+        # The above import may fail for some other reason. Ensure that the
+        # issue is really that Django is missing to avoid masking other
+        # exceptions on Python 2.
+        try:
+            import django  # noqa
+        except ImportError:
+            raise ImportError(
+                "Couldn't import Django. Are you sure it's installed and "
+                "available on your PYTHONPATH environment variable? Did you "
+                "forget to activate a virtual environment?"
+            )
+        raise
+    execute_from_command_line(sys.argv)
diff --git a/src/build/api/support-files/templates/api#bkuser_core#config#overlays#prod.py b/src/build/api/support-files/templates/api#bkuser_core#config#overlays#prod.py
new file mode 100644
--- /dev/null
+++ b/src/build/api/support-files/templates/api#bkuser_core#config#overlays#prod.py
@@ -0,0 +1,146 @@
+# -*- coding: utf-8 -*-
+"""
+正式环境配置
+"""
+import urllib.parse
+
+from bkuser_core.config.common.django_basic import *  # noqa
+from bkuser_core.config.common.logging import *  # noqa
+from bkuser_core.config.common.system import *  # noqa
+
+from bkuser_global.logging import LoggingType, get_logging
+
+DEBUG = False
+
+# use the static root 'static' in production envs
+if not DEBUG:
+    STATIC_ROOT = "static"
+
+APP_ID = "__BK_USERMGR_APP_CODE__"
+APP_TOKEN = "__BK_USERMGR_APP_SECRET__"
+
+# 数据库配置信息
+DATABASES = {
+    "default": {
+        "ENGINE": "django.db.backends.mysql",  # 默认用mysql
+        "NAME": "bk_user",
+        "USER": "__BK_USERMGR_MYSQL_USER__",
+        "PASSWORD": "__BK_USERMGR_MYSQL_PASSWORD__",
+        "HOST": "__BK_USERMGR_MYSQL_HOST__",
+        "PORT": "__BK_USERMGR_MYSQL_PORT__",
+    }
+}
+
+LOGGING_DIR = "__BK_HOME__/logs/usermgr/"
+LOGGING = get_logging(
+    logging_type=LoggingType.FILE,
+    log_level=LOG_LEVEL,
+    package_name="bkuser_core",
+    formatter="verbose",
+    logging_dir=LOGGING_DIR,
+    file_name="api",
+)
+
+# 初始化用户名、密码
+SUPERUSER_USERNAME = "__BK_PAAS_ADMIN_USERNAME__"
+SUPERUSER_PASSWORD = "__BK_PAAS_ADMIN_PASSWORD__"
+
+# domain
+PAAS_DOMAIN = "__BK_PAAS_PUBLIC_ADDR__"
+BK_PAAS_URL = "__BK_PAAS_PUBLIC_URL__"
+BK_COMPONENT_API_URL = "__BK_PAAS_PUBLIC_URL__"
+
+# cookie访问域
+BK_COOKIE_DOMAIN = ".__BK_DOMAIN__"
+
+SECRET_KEY = "__BK_PAAS_ESB_SECRET_KEY__"
+
+# ESB Token
+ESB_TOKEN = "__BK_PAAS_APP_SECRET__"
+
+# license
+CERTIFICATE_DIR = "__BK_CERT_PATH__"
+CERTIFICATE_SERVER_DOMAIN = "__BK_LICENSE_PRIVATE_ADDR__"
+
+CACHES = {
+    "default": {
+        "BACKEND": "bkuser_core.common.cache.DummyRedisCache",
+    },
+    'locmem': {
+        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
+        'LOCATION': 'memory_cache_0',
+    },
+}
+# 全局缓存过期时间，默认为一小时
+GLOBAL_CACHES_TIMEOUT = env.int("GLOBAL_CACHES_TIMEOUT", default=60 * 60)
+
+# 快捷单元测试 dummy cache 标记
+USE_DUMMY_CACHE_FOR_TEST = True
+
+FORCE_JSONP_HEADER = "HTTP_FORCE_JSONP"
+FORCE_NO_CACHE_HEADER = "HTTP_FORCE_NO_CACHE"
+
+##########
+# Celery #
+##########
+REDIS_URL = ""
+REDIS_KEY_PREFIX = env("CACHE_REDIS_KEY_PREFIX", default="bk-user-")
+CELERY_BROKER_URL = "amqp://__BK_USERMGR_RABBITMQ_USERNAME__:__BK_USERMGR_RABBITMQ_PASSWORD__@__BK_USERMGR_RABBITMQ_HOST__:__BK_USERMGR_RABBITMQ_PORT__/__BK_USERMGR_RABBITMQ_VHOST__"
+CELERY_RESULT_BACKEND = "amqp://__BK_USERMGR_RABBITMQ_USERNAME__:__BK_USERMGR_RABBITMQ_PASSWORD__@__BK_USERMGR_RABBITMQ_HOST__:__BK_USERMGR_RABBITMQ_PORT__/__BK_USERMGR_RABBITMQ_VHOST__"
+
+# ==============================================================================
+# IAM
+# ==============================================================================
+def get_iam_config(app_id: str, app_token: str) -> dict:
+    return dict(
+        api_host="__BK_IAM_PRIVATE_URL__",
+        system_id=env("BK_IAM_SYSTEM_ID", default="bk_usermgr"),
+        # iam app 访问 url 用于回调拼接
+        iam_app_host=env(
+            "BK_IAM_SAAS_HOST",
+            default=f"{BK_PAAS_URL}/o/{env('BK_IAM_V3_APP_CODE', default='bk_iam')}",
+        ),
+        apply_path="apply-custom-perm",
+        # 自己的 app_id & app_token
+        own_app_id=app_id,
+        own_app_token=app_token,
+    )
+
+
+IAM_CONFIG = get_iam_config(APP_ID, APP_TOKEN)  # type: ignore
+ENABLE_IAM = True
+
+# 请求 ESB API 默认版本号
+DEFAULT_BK_API_VER = "v2"
+
+# 与 SaaS 约定的权限校验头，未传递时跳过权限校验
+NEED_IAM_HEADER = "HTTP_NEED_IAM"
+ACTION_ID_HEADER = "HTTP_ACTION_ID"
+
+# ===============================================================================
+# API 访问限制（暂未开启）
+# ===============================================================================
+INTERNAL_AUTH_TOKENS = {"TCwCnoiuUgPccj8y0Wx187vJBqzqddfLlm": {"username": "iadmin"}}
+ACCESS_APP_WHITE_LIST = {"bk-iam": "lLP3gabV8M0C9vbwHQwzSYJX3WumcJsDSdVNQtq6FJVCLqJX6o"}
+
+
+# ==============================================================================
+# 登陆相关
+# ==============================================================================
+LOGIN_REDIRECT_TO = f"{BK_PAAS_URL}/login/?c_url={SITE_URL}"
+
+# ==============================================================================
+# SaaS 配置
+# ==============================================================================
+# SaaS 应用 Code
+SAAS_CODE = "bk_user_manage"
+# SaaS 请求地址，用于拼接访问地址(默认支持二进制部署)
+SAAS_URL = env(
+    "SAAS_URL", default=urllib.parse.urljoin(BK_PAAS_URL, f"/o/{SAAS_CODE}/")
+)
+
+# SaaS 偏好 client ip 头
+CLIENT_IP_FROM_SAAS_HEADER = "HTTP_CLIENT_IP_FROM_SAAS"
+
+# 可通过 SaaS 管理的用户目录类型
+CAN_MANUAL_WRITE_LISTS = ["local"]
diff --git a/src/build/saas/manage.py b/src/build/saas/manage.py
new file mode 100644
--- /dev/null
+++ b/src/build/saas/manage.py
@@ -0,0 +1,33 @@
+"""
+TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available.
+Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
+Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
+You may obtain a copy of the License at http://opensource.org/licenses/MIT
+Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License.
+"""
+import os
+import sys
+
+if __name__ == "__main__":
+
+    # manage.py used to work in dev env
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bkuser_shell.config.overlays.prod")
+
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError:
+        # The above import may fail for some other reason. Ensure that the
+        # issue is really that Django is missing to avoid masking other
+        # exceptions on Python 2.
+        try:
+            import django  # noqa
+        except ImportError:
+            raise ImportError(
+                "Couldn't import Django. Are you sure it's installed and "
+                "available on your PYTHONPATH environment variable? Did you "
+                "forget to activate a virtual environment?"
+            )
+        raise
+    execute_from_command_line(sys.argv)


Test patch: