Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion iam/api/http.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making
蓝鲸智云-权限中心Python SDK(iam-python-sdk) available.
蓝鲸智云 - 权限中心 Python SDK(iam-python-sdk) 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
Expand All @@ -15,6 +15,10 @@

import curlify
import requests
import urllib3

# no more useless warning
urllib3.disable_warnings()

logger = logging.getLogger("iam")

Expand Down
15 changes: 15 additions & 0 deletions iam/contrib/iam_migration/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ def __init__(self, migration_json):
self._bk_app_code = getattr(settings, "APP_CODE", "")
self._bk_app_secret = settings.SECRET_KEY

def get_tenant_id(self):
"""
获取应用所属的租户 ID
"""
# PaaS 平台上部署运行的应用,会自动内置 BKPAAS_APP_TENANT_ID 环境变量,表示应用是全租户的还是单租户的
tenant_id = os.environ.get("BKPAAS_APP_TENANT_ID")
if tenant_id is not None:
# 空字符串表示全租户应用,则返回 system
return tenant_id or "system"

# 如果从环境变量获取不到,即非 PaaS 平台上运行,则需要从配置中获取
# 注意:对于单租户应用,BK_APP_TENANT_ID 可以不设置
# 对于全租户应用,BK_APP_TENANT_ID 必须设置,建议设置为 system
return getattr(settings, "BK_APP_TENANT_ID", "")

def migrate(self):
iam_host = getattr(settings, "BK_IAM_APIGATEWAY_URL", "")
if iam_host == "":
Expand Down
3 changes: 3 additions & 0 deletions iam/contrib/iam_migration/utils/do_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
import os

import requests
import urllib3

# NOTE: the usage doc https://bk.tencent.com/docs/document/6.0/160/8388

__version__ = "1.0.0"
# no more useless warning
urllib3.disable_warnings()

BK_APIGATEWAY_URL = os.getenv("BK_IAM_APIGATEWAY_URL", "https://bkapi.example.com/api/bk-iam/prod/")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
requires = [
"six>=1.11.0",
"cachetools>=3.1.1,<6.0",
"requests",
"requests>=2.16.0",
"curlify==2.2.1",
]

Expand Down