Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion bk-plugin-framework/bk_plugin_framework/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
specific language governing permissions and limitations under the License.
"""

__version__ = "2.3.5"
__version__ = "2.3.6"
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle(self, *args, **options):
step_start = time.time()
self.stdout.write("[Sync] generate definition.yaml")
try:
call_command("generate_definition_yaml")
call_command("generate_definition_yaml", "--render")
except Exception as e:
self.stderr.write(
self.style.ERROR(
Expand All @@ -66,10 +66,15 @@ def handle(self, *args, **options):
self.stdout.write(f"[Sync] resources.yaml path: {resources_yaml_path}")
step_timings["1.1 复制 support-files/resources.yaml"] = (time.time() - step_start) * 1000

# 2. 计算当前哈希值(仅计算 resources.yaml)
# 2. 计算当前哈希值(计算 resources.yaml 和 definition.yaml)
step_start = time.time()
current_hash = self._calculate_resources_hash()
self.stdout.write(f"[Sync] Current resources.yaml hash: {current_hash[:16]}...")
resources_hash = self._calculate_yaml_hash(resources_yaml_path)
definition_hash = self._calculate_yaml_hash(definition_yaml_path)
self.stdout.write(f"[Sync] resources.yaml hash: {resources_hash[:16] if resources_hash else 'N/A'}...")
self.stdout.write(f"[Sync] definition.yaml hash: {definition_hash[:16] if definition_hash else 'N/A'}...")
# 组合两个哈希值生成最终哈希
current_hash = hashlib.sha256(f"{resources_hash}:{definition_hash}".encode()).hexdigest()
self.stdout.write(f"[Sync] Current combined hash: {current_hash[:16]}...")
step_timings["2. 计算当前哈希值"] = (time.time() - step_start) * 1000

# 3. 获取上次同步的哈希值
Expand Down Expand Up @@ -165,15 +170,14 @@ def _copy_support_files_resources(self):
self.stderr.write(self.style.ERROR(f"[Sync] Failed to copy support-files/resources.yaml: {e}"))
raise SystemExit(1)

def _calculate_resources_hash(self):
def _calculate_yaml_hash(self, filepath):
"""
计算 resources.yaml 的哈希值
计算单个 YAML 文件的哈希值

注意:为了避免 YAML 内容顺序变化导致的 hash 不一致问题,
这里先将 YAML 解析为字典,然后用 sort_keys=True 重新序列化,
确保相同内容的 YAML 文件总是产生相同的 hash 值。
"""
filepath = os.path.join(settings.BASE_DIR, "resources.yaml")
if os.path.exists(filepath):
try:
with open(filepath, encoding="utf-8") as f:
Expand All @@ -190,7 +194,7 @@ def _calculate_resources_hash(self):
except Exception as e:
self.stdout.write(
self.style.WARNING(
f"[Sync] Failed to normalize resources.yaml for hash: {e}, fallback to raw content hash"
f"[Sync] Failed to normalize {filepath} for hash: {e}, fallback to raw content hash"
)
)
# 回退到原始方式
Expand Down
62 changes: 34 additions & 28 deletions bk-plugin-framework/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions bk-plugin-framework/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bk-plugin-framework"
version = "2.3.5"
version = "2.3.6"
description = "bk plugin python framework"
authors = ["Your Name <you@example.com>"]
license = "MIT"
Expand All @@ -9,8 +9,8 @@ license = "MIT"
python = "^3.8.0,<4.0"
pydantic = ">=1.0,<3"
werkzeug = ">=2.0.0, <4.0"
apigw-manager = {version = ">=1.0.6, <4", extras = ["extra"]}
bk-plugin-runtime = "2.1.3"
apigw-manager = {version = ">=4.2.3, <5", python = ">=3.8,<3.13"}
bk-plugin-runtime = "2.1.5"
jsonschema = ">=2.5.0,<5.0.0"
drf-spectacular = "^0.29.0"

Expand Down Expand Up @@ -40,3 +40,8 @@ exclude = '''
| dist
)/
'''

[[tool.poetry.source]]
name = "tencent"
url = "https://mirrors.tencent.com/repository/pypi/tencent_pypi/simple"
priority = "supplemental"
2 changes: 1 addition & 1 deletion runtime/bk-plugin-runtime/bk_plugin_runtime/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
specific language governing permissions and limitations under the License.
"""

__version__ = "2.1.3"
__version__ = "2.1.5"
12 changes: 11 additions & 1 deletion runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import urllib
from urllib.parse import urlparse

from apigw_manager.plugin.config import build_bk_cors, build_stage_plugin_config_for_definition_yaml
from blueapps.conf.default_settings import * # noqa
from blueapps.conf.log import get_logging_config_dict

Expand Down Expand Up @@ -221,6 +222,15 @@ def logging_addition_settings(logging_dict):
break


# plugin configs
apigw_plugin_configs = build_stage_plugin_config_for_definition_yaml(
[
build_bk_cors(
allow_headers="**", allow_methods="**", allow_origins="**", allow_credential=True, expose_headers="--"
),
]
)
BK_APIGW_STAGE_PLUGIN_CONFIGS = apigw_plugin_configs
# drf settings
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
Expand Down Expand Up @@ -292,6 +302,6 @@ def logging_addition_settings(logging_dict):
BK_APIGW_CORS_ALLOW_METHODS = os.getenv("BK_APIGW_CORS_ALLOW_METHODS", "")
BK_APIGW_CORS_ALLOW_HEADERS = os.getenv("BK_APIGW_CORS_ALLOW_HEADERS", "")
BK_APIGW_DEFAULT_TIMEOUT = int(os.getenv("BK_APIGW_DEFAULT_TIMEOUT", "60"))
BK_APIGW_GRANTED_APPS = [BK_APP_CODE] + [
BK_APIGW_GRANT_PERMISSION_DIMENSION_GATEWAY_APP_CODES = [BK_APP_CODE] + [
each.strip() for each in os.getenv("BK_APIGW_GRANTED_APPS", "").split(",") if each.strip()
]
Loading