From e96bdd64a74db53d08f8cb282e649c60194843da Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 15:01:13 +0800 Subject: [PATCH 01/16] feat: update apiserver python version to 3.11.10 --- apiserver/Dockerfile | 7 +- apiserver/Makefile | 2 +- apiserver/README.md | 27 +- .../unittest/Dockerfile.devops.unittest | 7 +- apiserver/paasng/conf.yaml.tpl | 2 +- .../paas_wl/infras/resources/utils/basic.py | 7 +- apiserver/paasng/paas_wl/utils/basic.py | 2 +- .../accessories/servicehub/remote/manager.py | 6 +- apiserver/poetry.lock | 281 ++++++------------ apiserver/pyproject.toml | 23 +- pyproject.toml | 5 +- 11 files changed, 137 insertions(+), 232 deletions(-) diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index fb06ccfaa0..e54395da62 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -22,7 +22,7 @@ ADD ./configs ./configs RUN EDITION=${EDITION} npm run build ################# PaaS ################# -FROM python:3.8.13-slim-buster +FROM python:3.11.10-slim-bullseye USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim @@ -44,7 +44,7 @@ ENV LC_ALL=C.UTF-8 \ RUN pip install --upgrade 'pip<24.1' -RUN pip install poetry==1.3.2 +RUN pip install poetry==1.8.3 # Change security level of openssl to lower value in order to avoid "CA_MD_TOO_WEAK" error # See https://stackoverflow.com/questions/52218876/how-to-fix-ssl-issue-ssl-ctx-use-certificate-ca-md-too-weak-on-python-zeep?rq=1 @@ -56,8 +56,7 @@ ADD ./pyproject.toml . ADD ./poetry.lock . # Install dependecies in system -# Disable "new installer" to fix https://github.com/python-poetry/poetry/issues/6301 -RUN poetry config virtualenvs.create false && poetry config experimental.new-installer false && poetry install --no-dev +RUN poetry config virtualenvs.create false && poetry install --no-dev ARG BKPAAS_BUILD_VERSION="tag: null, commitID: ^HEAD, buildID: null, buildTime: null" ENV BKPAAS_BUILD_VERSION=${BKPAAS_BUILD_VERSION} diff --git a/apiserver/Makefile b/apiserver/Makefile index 0c4c829695..fc13a993cb 100644 --- a/apiserver/Makefile +++ b/apiserver/Makefile @@ -8,7 +8,7 @@ init-pre-commit: ## 初始化 pre-commit pre-commit install init-py-dep: ## 初始化 python 依赖包 - pip install poetry==1.3.2 + pip install poetry==1.8.3 poetry install init-node-dep: ## 初始化 nodejs diff --git a/apiserver/README.md b/apiserver/README.md index c4453afe97..e2992a8e74 100644 --- a/apiserver/README.md +++ b/apiserver/README.md @@ -28,16 +28,16 @@ apiserver 为 blueking-paas 项目的主控模块。 ### 准备 Python 开发环境 -1. 安装 Python 3.8 +1. 安装 Python 3.11 我们推荐使用 [pyenv](https://github.com/pyenv/pyenv) 管理本地的 python 环境 - 依照 [相关指引](https://github.com/pyenv/pyenv#getting-pyenv) 安装 pyenv -- 使用 pyenv 安装 Python 3.8 +- 使用 pyenv 安装 Python 3.11 ```shell -❯ pyenv install 3.8.13 +❯ pyenv install 3.11.10 ``` 2. 安装项目依赖 @@ -62,11 +62,12 @@ apiserver 项目的管理端(Admin42)使用 Nodejs 进行开发, 如需开 1. 安装 [Nodejs](https://github.com/nodejs),推荐使用 v14.21.1 版本 我们推荐使用 [nvm](https://github.com/nvm-sh/nvm) 管理本地的 nodejs 环境 + - 依照 [相关指引](https://github.com/nvm-sh/nvm#installing-and-updating) 安装 nvm - 使用 nvm 安装 nodejs 14 ```shell -❯ nvm install 14 +❯ nvm install 14 ``` 2. 安装项目依赖 @@ -148,9 +149,9 @@ Nodejs 组件开发模式与常规的 Nodejs 项目无异, 但为了更方便地 本项目未使用任何 `JavaScript 模块化技术`, 即所有组件都需要自行往 `window` 对象挂载, 例如: ```javascript -import Vue from 'vue' +import Vue from "vue"; -window.Vue = Vue +window.Vue = Vue; ``` 否则, `Django Template` 将无法直接使用 Nodejs 中的组件。 @@ -158,7 +159,7 @@ window.Vue = Vue #### Template 页面开发指引 Template 页面开发模式与常规的 Django 项目无异, 但是使用了 [Vuejs](https://cn.vuejs.org/) -和 [MagicBox Vue组件库](https://magicbox.bk.tencent.com/static_api/v3/components_vue/2.0/example/index.html#/) +和 [MagicBox Vue 组件库](https://magicbox.bk.tencent.com/static_api/v3/components_vue/2.0/example/index.html#/) 完成前端的功能开发。 在开发新的 Template 模板时应该遵循以下规范: @@ -205,7 +206,7 @@ class SysBkPluginLogsViewset(viewsets.ViewSet): 要点如下: 1. 使用 `@ForceAllowAuthedApp.mark_view_set` 装饰视图类后,如果请求携带了经认证的有效应用身份(经由 API 网关完成认证与权限校验),平台将自动创建一个角色为 `SYSTEM_API_BASIC_READER` 的系统账号,由它完成请求。 - - 后续如需要调整该账号的角色,可在 PaaS Admin 中完成。 + - 后续如需要调整该账号的角色,可在 PaaS Admin 中完成。 2. 使用 `@site_perm_required` 装饰视图函数,以保证请求只允许那些拥有系统级权限的账号访问(**非常重要,因为系统 API 一般都是用户无关,极容易发生越权问题。**) ## FAQ @@ -214,16 +215,6 @@ class SysBkPluginLogsViewset(viewsets.ViewSet): 如果在安装 docker 时, 安装了 docker-compose-plugin, 需要修改'blueking-paas/apiserver/dev_utils/bundle/start.sh' 中的 docker-compose 改为 docker compose -### poetry install 时 hash 值对不上问题 - -先执行 - -```shell -poetry config experimental.new-installer false -``` - -再重新执行 poetry install 即可 - ### admin42 页面 403 问题 需要进入数据库执行以下命令 diff --git a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest index e4e721f194..f9550154a5 100644 --- a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest +++ b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest @@ -22,7 +22,7 @@ ADD ./configs ./configs RUN EDITION=${EDITION} npm run build ################# PaaS ################# -FROM python:3.8.13-slim-buster +FROM python:3.11.10-slim-bullseye USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim @@ -47,15 +47,14 @@ ENV LC_ALL=C.UTF-8 \ RUN sed -i "s/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=0/g" /etc/ssl/openssl.cnf RUN pip install --upgrade pip -RUN pip install poetry==1.3.2 +RUN pip install poetry==1.8.3 WORKDIR /app ADD ./pyproject.toml . ADD ./poetry.lock . -# Disable "new installer" to fix https://github.com/python-poetry/poetry/issues/6301 -RUN poetry config virtualenvs.create false && poetry config experimental.new-installer false && poetry install +RUN poetry config virtualenvs.create false && poetry install WORKDIR /app diff --git a/apiserver/paasng/conf.yaml.tpl b/apiserver/paasng/conf.yaml.tpl index 5240fe6667..1f263bc7b1 100644 --- a/apiserver/paasng/conf.yaml.tpl +++ b/apiserver/paasng/conf.yaml.tpl @@ -3,7 +3,7 @@ ## 用于加密数据库内容的 Secret # BKKRILL_ENCRYPT_SECRET_KEY: '' -## 选择加密数据库内容的算法,可选择:'SHANGMI' , 'CLASSIC',分别对应 'SM4CTR'和'Fernet' 算法 +## 选择加密数据库内容的算法,可选值:'SHANGMI', 'CLASSIC',分别对应 'SM4CTR' 和 'FernetCipher' 算法 # BK_CRYPTO_TYPE : '' ## (Django)特定 Django 安装的密钥。用于提供 加密签名,默认值为:${BKKRILL_ENCRYPT_SECRET_KEY} diff --git a/apiserver/paasng/paas_wl/infras/resources/utils/basic.py b/apiserver/paasng/paas_wl/infras/resources/utils/basic.py index 920d3fad88..b8eed6c418 100644 --- a/apiserver/paasng/paas_wl/infras/resources/utils/basic.py +++ b/apiserver/paasng/paas_wl/infras/resources/utils/basic.py @@ -15,10 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -"""Basic utils for scheduler -""" +"""Basic utils for scheduler""" + import logging -from collections import Callable, OrderedDict +from collections import OrderedDict +from collections.abc import Callable from typing import TYPE_CHECKING, Dict, List, Optional from paas_wl.bk_app.applications.models import WlApp diff --git a/apiserver/paasng/paas_wl/utils/basic.py b/apiserver/paasng/paas_wl/utils/basic.py index f253ad0722..d9bc1e62de 100644 --- a/apiserver/paasng/paas_wl/utils/basic.py +++ b/apiserver/paasng/paas_wl/utils/basic.py @@ -17,7 +17,7 @@ import datetime import hashlib -from collections import MutableMapping +from collections.abc import MutableMapping from typing import Any, Collection, Dict from uuid import UUID diff --git a/apiserver/paasng/paasng/accessories/servicehub/remote/manager.py b/apiserver/paasng/paasng/accessories/servicehub/remote/manager.py index ed4f7e6dd3..4a94add879 100644 --- a/apiserver/paasng/paasng/accessories/servicehub/remote/manager.py +++ b/apiserver/paasng/paasng/accessories/servicehub/remote/manager.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -"""The universal services module, handles both services from database and remote REST API -""" +"""The universal services module, handles both services from database and remote REST API""" + import json import logging import uuid @@ -124,7 +124,7 @@ def from_data(cls, data: Dict): @dataclass class RemoteServiceObj(ServiceObj): plans: List[RemotePlanObj] = field(default_factory=list) - meta_info: MetaInfo = DEFAULT_META_INFO + meta_info: MetaInfo = field(default_factory=lambda: MetaInfo(version=None)) _data = None category_id = None diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index 0e99b72e7b..50c25b61ef 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -2,15 +2,15 @@ [[package]] name = "aenum" -version = "2.1.2" +version = "3.1.15" description = "Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants" category = "main" optional = false python-versions = "*" files = [ - {file = "aenum-2.1.2-py2-none-any.whl", hash = "sha256:7a77c205c4bc9d7fe9bd73b3193002d724aebf5909fa0d297534208953891ec8"}, - {file = "aenum-2.1.2-py3-none-any.whl", hash = "sha256:3df9b84cce5dc9ed77c337079f97b66c44c0053eb87d6f4d46b888dc45801e38"}, - {file = "aenum-2.1.2.tar.gz", hash = "sha256:a3208e4b28db3a7b232ff69b934aef2ea1bf27286d9978e1e597d46f490e4687"}, + {file = "aenum-3.1.15-py2-none-any.whl", hash = "sha256:27b1710b9d084de6e2e695dab78fe9f269de924b51ae2850170ee7e1ca6288a5"}, + {file = "aenum-3.1.15-py3-none-any.whl", hash = "sha256:e0dfaeea4c2bd362144b87377e2c61d91958c5ed0b4daf89cb6f45ae23af6288"}, + {file = "aenum-3.1.15.tar.gz", hash = "sha256:8cbd76cd18c4f870ff39b24284d3ea028fbe8731a58df3aa581e434c575b9559"}, ] [package.source] @@ -136,9 +136,6 @@ files = [ {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, ] -[package.dependencies] -typing-extensions = {version = ">=4", markers = "python_version < \"3.11\""} - [package.extras] tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] @@ -186,43 +183,6 @@ type = "legacy" url = "https://mirrors.tencent.com/pypi/simple" reference = "tencent-mirror" -[[package]] -name = "backports-zoneinfo" -version = "0.2.1" -description = "Backport of the standard library zoneinfo module" -category = "main" -optional = false -python-versions = ">=3.6" -files = [ - {file = "backports.zoneinfo-0.2.1-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:da6013fd84a690242c310d77ddb8441a559e9cb3d3d59ebac9aca1a57b2e18bc"}, - {file = "backports.zoneinfo-0.2.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:89a48c0d158a3cc3f654da4c2de1ceba85263fafb861b98b59040a5086259722"}, - {file = "backports.zoneinfo-0.2.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:1c5742112073a563c81f786e77514969acb58649bcdf6cdf0b4ed31a348d4546"}, - {file = "backports.zoneinfo-0.2.1-cp36-cp36m-win32.whl", hash = "sha256:e8236383a20872c0cdf5a62b554b27538db7fa1bbec52429d8d106effbaeca08"}, - {file = "backports.zoneinfo-0.2.1-cp36-cp36m-win_amd64.whl", hash = "sha256:8439c030a11780786a2002261569bdf362264f605dfa4d65090b64b05c9f79a7"}, - {file = "backports.zoneinfo-0.2.1-cp37-cp37m-macosx_10_14_x86_64.whl", hash = "sha256:f04e857b59d9d1ccc39ce2da1021d196e47234873820cbeaad210724b1ee28ac"}, - {file = "backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:17746bd546106fa389c51dbea67c8b7c8f0d14b5526a579ca6ccf5ed72c526cf"}, - {file = "backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:5c144945a7752ca544b4b78c8c41544cdfaf9786f25fe5ffb10e838e19a27570"}, - {file = "backports.zoneinfo-0.2.1-cp37-cp37m-win32.whl", hash = "sha256:e55b384612d93be96506932a786bbcde5a2db7a9e6a4bb4bffe8b733f5b9036b"}, - {file = "backports.zoneinfo-0.2.1-cp37-cp37m-win_amd64.whl", hash = "sha256:a76b38c52400b762e48131494ba26be363491ac4f9a04c1b7e92483d169f6582"}, - {file = "backports.zoneinfo-0.2.1-cp38-cp38-macosx_10_14_x86_64.whl", hash = "sha256:8961c0f32cd0336fb8e8ead11a1f8cd99ec07145ec2931122faaac1c8f7fd987"}, - {file = "backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:e81b76cace8eda1fca50e345242ba977f9be6ae3945af8d46326d776b4cf78d1"}, - {file = "backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7b0a64cda4145548fed9efc10322770f929b944ce5cee6c0dfe0c87bf4c0c8c9"}, - {file = "backports.zoneinfo-0.2.1-cp38-cp38-win32.whl", hash = "sha256:1b13e654a55cd45672cb54ed12148cd33628f672548f373963b0bff67b217328"}, - {file = "backports.zoneinfo-0.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:4a0f800587060bf8880f954dbef70de6c11bbe59c673c3d818921f042f9954a6"}, - {file = "backports.zoneinfo-0.2.1.tar.gz", hash = "sha256:fadbfe37f74051d024037f223b8e001611eac868b5c5b06144ef4d8b799862f2"}, -] - -[package.dependencies] -tzdata = {version = "*", optional = true, markers = "extra == \"tzdata\""} - -[package.extras] -tzdata = ["tzdata"] - -[package.source] -type = "legacy" -url = "https://mirrors.tencent.com/pypi/simple" -reference = "tencent-mirror" - [[package]] name = "billiard" version = "4.2.1" @@ -283,14 +243,14 @@ reference = "tencent-mirror" [[package]] name = "bk-crypto-python-sdk" -version = "1.1.1" +version = "2.0.0" description = "bk-crypto-python-sdk is a lightweight cryptography toolkit for Python applications based on Cryptodome / tongsuopy and other encryption libraries." category = "main" optional = false -python-versions = ">=3.6.2,<3.11" +python-versions = ">=3.8,<3.12" files = [ - {file = "bk-crypto-python-sdk-1.1.1.tar.gz", hash = "sha256:dee920ca58d402cc203a4cc704993685c626a801ff3c60942ec7c412d6b194b2"}, - {file = "bk_crypto_python_sdk-1.1.1-py3-none-any.whl", hash = "sha256:042f1651a927cbf3e3cae2b3c2688b8151d572032e480bff7aa9d96405632c0a"}, + {file = "bk_crypto_python_sdk-2.0.0-py3-none-any.whl", hash = "sha256:7ae6b83b9ffc708bb8f756e245e69cbc59cca3cb6b942c75a0bf3a9c9cb0918d"}, + {file = "bk_crypto_python_sdk-2.0.0.tar.gz", hash = "sha256:6d76c27678950fa6713b51a42e81063ff3074c2ce5c30057e4f83f10903b9060"}, ] [package.dependencies] @@ -438,26 +398,12 @@ reference = "tencent-mirror" [[package]] name = "bkstorages" -version = "1.1.0" +version = "1.1.1" description = "File storage backends for blueking PaaS platform" category = "main" optional = false -python-versions = ">=3.6.2,<3.11" -files = [ - {file = "bkstorages-1.1.0-py3-none-any.whl", hash = "sha256:24bd939e9e7c0073b23b5fb5a54fd936f50d20dd0e3be2b37cf693ec9b0d3a13"}, - {file = "bkstorages-1.1.0.tar.gz", hash = "sha256:7af8a440520a218c634b6ef0cf3dadcc37016c7db3ea690a146c45970e8be707"}, -] - -[package.dependencies] -boto3 = ">=1.4.1" -curlify = ">=2.2.1,<3.0.0" -requests = "*" -six = "*" - -[package.source] -type = "legacy" -url = "https://mirrors.tencent.com/pypi/simple" -reference = "tencent-mirror" +python-versions = "*" +files = [] [[package]] name = "bleach" @@ -483,29 +429,30 @@ reference = "tencent-mirror" [[package]] name = "blue-krill" -version = "2.0.3" +version = "2.0.6" description = "Tools and common packages for blueking PaaS platform." category = "main" optional = false -python-versions = ">=3.8,<3.11" +python-versions = ">=3.8,<3.12" files = [ - {file = "blue_krill-2.0.3-py3-none-any.whl", hash = "sha256:f30ae9bbce3cc038b0f4a3d092935147a8f58ee18a225d1dbf25daf561fa7304"}, - {file = "blue_krill-2.0.3.tar.gz", hash = "sha256:7c8b1073f687ac4fa84d585a053bb62ce4056f6d0158db2389c1803dfa93994f"}, + {file = "blue_krill-2.0.6-py3-none-any.whl", hash = "sha256:fef55abd4b8f80caf2e7e0a031af3f0b394254763a4fa052c4f138c341852851"}, + {file = "blue_krill-2.0.6.tar.gz", hash = "sha256:953392ab410106bee95caa1a0719cc57d09f5c40144e6b20aa86c211f2bbb2c7"}, ] [package.dependencies] -bk-crypto-python-sdk = ">=1.0.4,<2.0.0" +bk-crypto-python-sdk = ">=2.0.0,<3.0.0" click = "*" cryptography = ">=3.0.0" curlify = ">=2.2.1,<3.0.0" -django-environ = ">=0.8.1,<0.9.0" +django-environ = ">=0.8.1" pydantic = "*" pyjwt = ">=1.7.1" python-editor = ">=1.0.4,<2.0.0" requests = "*" six = "*" toml = "*" -watchdog = ">=1.0.2,<2.0.0" +urllib3 = ">=1.26.16,<2.0.0" +watchdog = "*" [package.source] type = "legacy" @@ -569,10 +516,7 @@ files = [ [package.dependencies] jmespath = ">=0.7.1,<2.0.0" python-dateutil = ">=2.1,<3.0.0" -urllib3 = [ - {version = ">=1.25.4,<1.27", markers = "python_version < \"3.10\""}, - {version = ">=1.25.4,<2.1", markers = "python_version >= \"3.10\""}, -] +urllib3 = {version = ">=1.25.4,<2.1", markers = "python_version >= \"3.10\""} [package.extras] crt = ["awscrt (==0.19.17)"] @@ -632,7 +576,6 @@ files = [ ] [package.dependencies] -"backports.zoneinfo" = {version = ">=0.2.1", markers = "python_version < \"3.9\""} billiard = ">=4.2.0,<5.0" click = ">=8.1.2,<9.0" click-didyoumean = ">=0.3.0" @@ -684,14 +627,14 @@ reference = "tencent-mirror" [[package]] name = "certifi" -version = "2024.2.2" +version = "2024.8.30" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2024.2.2-py3-none-any.whl", hash = "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"}, - {file = "certifi-2024.2.2.tar.gz", hash = "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f"}, + {file = "certifi-2024.8.30-py3-none-any.whl", hash = "sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8"}, + {file = "certifi-2024.8.30.tar.gz", hash = "sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9"}, ] [package.source] @@ -1104,9 +1047,6 @@ files = [ {file = "coverage-7.4.4.tar.gz", hash = "sha256:c901df83d097649e257e803be22592aedfd5182f07b3cc87d640bbb9afd50f49"}, ] -[package.dependencies] -tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} - [package.extras] toml = ["tomli"] @@ -1117,44 +1057,39 @@ reference = "tencent-mirror" [[package]] name = "cryptography" -version = "42.0.5" +version = "43.0.1" description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:a30596bae9403a342c978fb47d9b0ee277699fa53bbafad14706af51fe543d16"}, - {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:b7ffe927ee6531c78f81aa17e684e2ff617daeba7f189f911065b2ea2d526dec"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2424ff4c4ac7f6b8177b53c17ed5d8fa74ae5955656867f5a8affaca36a27abb"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:329906dcc7b20ff3cad13c069a78124ed8247adcac44b10bea1130e36caae0b4"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:b03c2ae5d2f0fc05f9a2c0c997e1bc18c8229f392234e8a0194f202169ccd278"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f8837fe1d6ac4a8052a9a8ddab256bc006242696f03368a4009be7ee3075cdb7"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:0270572b8bd2c833c3981724b8ee9747b3ec96f699a9665470018594301439ee"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:b8cac287fafc4ad485b8a9b67d0ee80c66bf3574f655d3b97ef2e1082360faf1"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:16a48c23a62a2f4a285699dba2e4ff2d1cff3115b9df052cdd976a18856d8e3d"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:2bce03af1ce5a5567ab89bd90d11e7bbdff56b8af3acbbec1faded8f44cb06da"}, - {file = "cryptography-42.0.5-cp37-abi3-win32.whl", hash = "sha256:b6cd2203306b63e41acdf39aa93b86fb566049aeb6dc489b70e34bcd07adca74"}, - {file = "cryptography-42.0.5-cp37-abi3-win_amd64.whl", hash = "sha256:98d8dc6d012b82287f2c3d26ce1d2dd130ec200c8679b6213b3c73c08b2b7940"}, - {file = "cryptography-42.0.5-cp39-abi3-macosx_10_12_universal2.whl", hash = "sha256:5e6275c09d2badf57aea3afa80d975444f4be8d3bc58f7f80d2a484c6f9485c8"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4985a790f921508f36f81831817cbc03b102d643b5fcb81cd33df3fa291a1a1"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7cde5f38e614f55e28d831754e8a3bacf9ace5d1566235e39d91b35502d6936e"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7367d7b2eca6513681127ebad53b2582911d1736dc2ffc19f2c3ae49997496bc"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:cd2030f6650c089aeb304cf093f3244d34745ce0cfcc39f20c6fbfe030102e2a"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a2913c5375154b6ef2e91c10b5720ea6e21007412f6437504ffea2109b5a33d7"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:c41fb5e6a5fe9ebcd58ca3abfeb51dffb5d83d6775405305bfa8715b76521922"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:3eaafe47ec0d0ffcc9349e1708be2aaea4c6dd4978d76bf6eb0cb2c13636c6fc"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1b95b98b0d2af784078fa69f637135e3c317091b615cd0905f8b8a087e86fa30"}, - {file = "cryptography-42.0.5-cp39-abi3-win32.whl", hash = "sha256:1f71c10d1e88467126f0efd484bd44bca5e14c664ec2ede64c32f20875c0d413"}, - {file = "cryptography-42.0.5-cp39-abi3-win_amd64.whl", hash = "sha256:a011a644f6d7d03736214d38832e030d8268bcff4a41f728e6030325fea3e400"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:9481ffe3cf013b71b2428b905c4f7a9a4f76ec03065b05ff499bb5682a8d9ad8"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:ba334e6e4b1d92442b75ddacc615c5476d4ad55cc29b15d590cc6b86efa487e2"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:ba3e4a42397c25b7ff88cdec6e2a16c2be18720f317506ee25210f6d31925f9c"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:111a0d8553afcf8eb02a4fea6ca4f59d48ddb34497aa8706a6cf536f1a5ec576"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:cd65d75953847815962c84a4654a84850b2bb4aed3f26fadcc1c13892e1e29f6"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:e807b3188f9eb0eaa7bbb579b462c5ace579f1cedb28107ce8b48a9f7ad3679e"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:f12764b8fffc7a123f641d7d049d382b73f96a34117e0b637b80643169cec8ac"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:37dd623507659e08be98eec89323469e8c7b4c1407c85112634ae3dbdb926fdd"}, - {file = "cryptography-42.0.5.tar.gz", hash = "sha256:6fe07eec95dfd477eb9530aef5bead34fec819b3aaf6c5bd6d20565da607bfe1"}, + {file = "cryptography-43.0.1-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:8385d98f6a3bf8bb2d65a73e17ed87a3ba84f6991c155691c51112075f9ffc5d"}, + {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:27e613d7077ac613e399270253259d9d53872aaf657471473ebfc9a52935c062"}, + {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68aaecc4178e90719e95298515979814bda0cbada1256a4485414860bd7ab962"}, + {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:de41fd81a41e53267cb020bb3a7212861da53a7d39f863585d13ea11049cf277"}, + {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f98bf604c82c416bc829e490c700ca1553eafdf2912a91e23a79d97d9801372a"}, + {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:61ec41068b7b74268fa86e3e9e12b9f0c21fcf65434571dbb13d954bceb08042"}, + {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:014f58110f53237ace6a408b5beb6c427b64e084eb451ef25a28308270086494"}, + {file = "cryptography-43.0.1-cp37-abi3-win32.whl", hash = "sha256:2bd51274dcd59f09dd952afb696bf9c61a7a49dfc764c04dd33ef7a6b502a1e2"}, + {file = "cryptography-43.0.1-cp37-abi3-win_amd64.whl", hash = "sha256:666ae11966643886c2987b3b721899d250855718d6d9ce41b521252a17985f4d"}, + {file = "cryptography-43.0.1-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:ac119bb76b9faa00f48128b7f5679e1d8d437365c5d26f1c2c3f0da4ce1b553d"}, + {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1bbcce1a551e262dfbafb6e6252f1ae36a248e615ca44ba302df077a846a8806"}, + {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58d4e9129985185a06d849aa6df265bdd5a74ca6e1b736a77959b498e0505b85"}, + {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:d03a475165f3134f773d1388aeb19c2d25ba88b6a9733c5c590b9ff7bbfa2e0c"}, + {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:511f4273808ab590912a93ddb4e3914dfd8a388fed883361b02dea3791f292e1"}, + {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:80eda8b3e173f0f247f711eef62be51b599b5d425c429b5d4ca6a05e9e856baa"}, + {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:38926c50cff6f533f8a2dae3d7f19541432610d114a70808f0926d5aaa7121e4"}, + {file = "cryptography-43.0.1-cp39-abi3-win32.whl", hash = "sha256:a575913fb06e05e6b4b814d7f7468c2c660e8bb16d8d5a1faf9b33ccc569dd47"}, + {file = "cryptography-43.0.1-cp39-abi3-win_amd64.whl", hash = "sha256:d75601ad10b059ec832e78823b348bfa1a59f6b8d545db3a24fd44362a1564cb"}, + {file = "cryptography-43.0.1-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ea25acb556320250756e53f9e20a4177515f012c9eaea17eb7587a8c4d8ae034"}, + {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c1332724be35d23a854994ff0b66530119500b6053d0bd3363265f7e5e77288d"}, + {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:fba1007b3ef89946dbbb515aeeb41e30203b004f0b4b00e5e16078b518563289"}, + {file = "cryptography-43.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:5b43d1ea6b378b54a1dc99dd8a2b5be47658fe9a7ce0a58ff0b55f4b43ef2b84"}, + {file = "cryptography-43.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:88cce104c36870d70c49c7c8fd22885875d950d9ee6ab54df2745f83ba0dc365"}, + {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:9d3cdb25fa98afdd3d0892d132b8d7139e2c087da1712041f6b762e4f807cc96"}, + {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e710bf40870f4db63c3d7d929aa9e09e4e7ee219e703f949ec4073b4294f6172"}, + {file = "cryptography-43.0.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7c05650fe8023c5ed0d46793d4b7d7e6cd9c04e68eabe5b0aeea836e37bdcec2"}, + {file = "cryptography-43.0.1.tar.gz", hash = "sha256:203e92a75716d8cfb491dc47c79e17d0d9207ccffcbcb35f598fbe463ae3444d"}, ] [package.dependencies] @@ -1167,7 +1102,7 @@ nox = ["nox"] pep8test = ["check-sdist", "click", "mypy", "ruff"] sdist = ["build"] ssh = ["bcrypt (>=3.1.5)"] -test = ["certifi", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] +test = ["certifi", "cryptography-vectors (==43.0.1)", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] test-randomorder = ["pytest-randomly"] [package.source] @@ -1559,7 +1494,6 @@ files = [ ] [package.dependencies] -"backports.zoneinfo" = {version = "*", markers = "python_version < \"3.9\""} django = ">=3.0" [package.source] @@ -1833,7 +1767,7 @@ files = [ [package.dependencies] cffi = {version = ">=1.12.2", markers = "platform_python_implementation == \"CPython\" and sys_platform == \"win32\""} -greenlet = {version = ">=2.0.0", markers = "platform_python_implementation == \"CPython\" and python_version < \"3.11\""} +greenlet = {version = ">=3.0rc3", markers = "platform_python_implementation == \"CPython\" and python_version >= \"3.11\""} "zope.event" = "*" "zope.interface" = "*" @@ -2134,23 +2068,24 @@ reference = "tencent-mirror" [[package]] name = "gunicorn" -version = "20.1.0" +version = "22.0.0" description = "WSGI HTTP Server for UNIX" category = "main" optional = false -python-versions = ">=3.5" +python-versions = ">=3.7" files = [ - {file = "gunicorn-20.1.0-py3-none-any.whl", hash = "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e"}, - {file = "gunicorn-20.1.0.tar.gz", hash = "sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"}, + {file = "gunicorn-22.0.0-py3-none-any.whl", hash = "sha256:350679f91b24062c86e386e198a15438d53a7a8207235a78ba1b53df4c4378d9"}, + {file = "gunicorn-22.0.0.tar.gz", hash = "sha256:4a0b436239ff76fb33f11c07a16482c521a7e09c1ce3cc293c2330afe01bec63"}, ] [package.dependencies] -setuptools = ">=3.0" +packaging = "*" [package.extras] -eventlet = ["eventlet (>=0.24.1)"] +eventlet = ["eventlet (>=0.24.1,!=0.36.0)"] gevent = ["gevent (>=1.4.0)"] setproctitle = ["setproctitle"] +testing = ["coverage", "eventlet", "gevent", "pytest", "pytest-cov"] tornado = ["tornado (>=0.2)"] [package.source] @@ -2210,7 +2145,6 @@ files = [ [package.dependencies] click = ">=6" grimp = ">=3.0" -tomli = {version = ">=1.2.1", markers = "python_version < \"3.11\""} typing-extensions = ">=3.10.0.0" [package.source] @@ -2279,14 +2213,14 @@ reference = "tencent-mirror" [[package]] name = "jinja2" -version = "3.1.3" +version = "3.1.4" description = "A very fast and expressive template engine." category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "Jinja2-3.1.3-py3-none-any.whl", hash = "sha256:7d6d50dd97d52cbc355597bd845fabfbac3f551e1f99619e39a35ce8c370b5fa"}, - {file = "Jinja2-3.1.3.tar.gz", hash = "sha256:ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90"}, + {file = "jinja2-3.1.4-py3-none-any.whl", hash = "sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d"}, + {file = "jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369"}, ] [package.dependencies] @@ -2351,8 +2285,6 @@ files = [ [package.dependencies] amqp = ">=5.1.1,<6.0.0" -"backports.zoneinfo" = {version = ">=0.2.1", extras = ["tzdata"], markers = "python_version < \"3.9\""} -typing-extensions = {version = "*", markers = "python_version < \"3.10\""} vine = "*" [package.extras] @@ -2421,9 +2353,6 @@ files = [ {file = "Markdown-3.6.tar.gz", hash = "sha256:ed4f41f6daecbeeb96e576ce414c41d2d876daa9a16cb35fa8ed8c2ddfad0224"}, ] -[package.dependencies] -importlib-metadata = {version = ">=4.4", markers = "python_version < \"3.10\""} - [package.extras] docs = ["mdx-gh-links (>=0.2)", "mkdocs (>=1.5)", "mkdocs-gen-files", "mkdocs-literate-nav", "mkdocs-nature (>=0.6)", "mkdocs-section-index", "mkdocstrings[python]"] testing = ["coverage", "pyyaml"] @@ -2685,7 +2614,6 @@ files = [ [package.dependencies] mypy-extensions = ">=0.4.3" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} typing-extensions = ">=3.10" [package.extras] @@ -4070,14 +3998,14 @@ reference = "tencent-mirror" [[package]] name = "requests" -version = "2.31.0" +version = "2.32.0" description = "Python HTTP for Humans." category = "main" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "requests-2.32.0-py3-none-any.whl", hash = "sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5"}, + {file = "requests-2.32.0.tar.gz", hash = "sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8"}, ] [package.dependencies] @@ -4157,7 +4085,6 @@ files = [ [package.dependencies] markdown-it-py = ">=2.2.0" pygments = ">=2.13.0,<3.0.0" -typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.9\""} [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] @@ -4266,20 +4193,24 @@ reference = "tencent-mirror" [[package]] name = "setuptools" -version = "69.5.1" +version = "75.1.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.5.1-py3-none-any.whl", hash = "sha256:c636ac361bc47580504644275c9ad802c50415c7522212252c033bd15f301f32"}, - {file = "setuptools-69.5.1.tar.gz", hash = "sha256:6c1fccdac05a97e598fb0ae3bbed5904ccb317337a51139dcd51453611bbb987"}, + {file = "setuptools-75.1.0-py3-none-any.whl", hash = "sha256:35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"}, + {file = "setuptools-75.1.0.tar.gz", hash = "sha256:d59a21b17a275fb872a9c3dae73963160ae079f1049ed956880cd7c09b120538"}, ] [package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -testing = ["build[virtualenv]", "filelock (>=3.4.0)", "importlib-metadata", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "mypy (==1.9)", "packaging (>=23.2)", "pip (>=19.1)", "pytest (>=6,!=8.1.1)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist (>=3)", "tomli", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] -testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.2)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)", "ruff (>=0.5.2)"] +core = ["importlib-metadata (>=6)", "importlib-resources (>=5.10.2)", "jaraco.collections", "jaraco.functools", "jaraco.text (>=3.7)", "more-itertools", "more-itertools (>=8.8)", "packaging", "packaging (>=24)", "platformdirs (>=2.6.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"] +cover = ["pytest-cov"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"] +enabler = ["pytest-enabler (>=2.2)"] +test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test", "packaging (>=23.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-home (>=0.5)", "pytest-perf", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"] +type = ["importlib-metadata (>=7.0.2)", "jaraco.develop (>=7.21)", "mypy (>=1.11.0,<1.12.0)", "pytest-mypy"] [package.source] type = "legacy" @@ -4390,20 +4321,19 @@ reference = "tencent-mirror" [[package]] name = "sqlparse" -version = "0.4.4" +version = "0.5.1" description = "A non-validating SQL parser." category = "main" optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "sqlparse-0.4.4-py3-none-any.whl", hash = "sha256:5430a4fe2ac7d0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3"}, - {file = "sqlparse-0.4.4.tar.gz", hash = "sha256:d446183e84b8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c"}, + {file = "sqlparse-0.5.1-py3-none-any.whl", hash = "sha256:773dcbf9a5ab44a090f3441e2180efe2560220203dc2f8c0b0fa141e18b505e4"}, + {file = "sqlparse-0.5.1.tar.gz", hash = "sha256:bb6b4df465655ef332548e24f08e205afc81b9ab86cb1c45657a7ff173a3a00e"}, ] [package.extras] -dev = ["build", "flake8"] +dev = ["build", "hatch"] doc = ["sphinx"] -test = ["pytest", "pytest-cov"] [package.source] type = "legacy" @@ -4505,23 +4435,6 @@ type = "legacy" url = "https://mirrors.tencent.com/pypi/simple" reference = "tencent-mirror" -[[package]] -name = "tomli" -version = "2.0.1" -description = "A lil' TOML parser" -category = "dev" -optional = false -python-versions = ">=3.7" -files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, -] - -[package.source] -type = "legacy" -url = "https://mirrors.tencent.com/pypi/simple" -reference = "tencent-mirror" - [[package]] name = "tongsuopy-crayon" version = "1.0.2b6" @@ -4914,14 +4827,14 @@ reference = "tencent-mirror" [[package]] name = "urllib3" -version = "1.26.18" +version = "1.26.20" description = "HTTP library with thread-safe connection pooling, file post, and more." category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" files = [ - {file = "urllib3-1.26.18-py2.py3-none-any.whl", hash = "sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07"}, - {file = "urllib3-1.26.18.tar.gz", hash = "sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0"}, + {file = "urllib3-1.26.20-py2.py3-none-any.whl", hash = "sha256:0ed14ccfbf1c30a9072c7ca157e4319b70d65f623e91e7b32fadb2853431016e"}, + {file = "urllib3-1.26.20.tar.gz", hash = "sha256:40c2dc0c681e47eb8f90e7e27bf6ff7df2e677421fd46756da1161c39ca70d32"}, ] [package.extras] @@ -5044,14 +4957,14 @@ reference = "tencent-mirror" [[package]] name = "werkzeug" -version = "3.0.2" +version = "3.0.3" description = "The comprehensive WSGI web application library." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "werkzeug-3.0.2-py3-none-any.whl", hash = "sha256:3aac3f5da756f93030740bc235d3e09449efcf65f2f55e3602e1d851b8f48795"}, - {file = "werkzeug-3.0.2.tar.gz", hash = "sha256:e39b645a6ac92822588e7b39a692e7828724ceae0b0d702ef96701f90e70128d"}, + {file = "werkzeug-3.0.3-py3-none-any.whl", hash = "sha256:fc9645dc43e03e4d630d23143a04a7f947a9a3b5727cd535fdfe155a17cc48c8"}, + {file = "werkzeug-3.0.3.tar.gz", hash = "sha256:097e5bfda9f0aba8da6b8545146def481d06aa7d3266e7448e2cccf67dd8bd18"}, ] [package.dependencies] @@ -5210,19 +5123,23 @@ reference = "tencent-mirror" [[package]] name = "zipp" -version = "3.18.1" +version = "3.20.2" description = "Backport of pathlib-compatible object wrapper for zip files" category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "zipp-3.18.1-py3-none-any.whl", hash = "sha256:206f5a15f2af3dbaee80769fb7dc6f249695e940acca08dfb2a4769fe61e538b"}, - {file = "zipp-3.18.1.tar.gz", hash = "sha256:2884ed22e7d8961de1c9a05142eb69a247f120291bc0206a00a7642f09b5b715"}, + {file = "zipp-3.20.2-py3-none-any.whl", hash = "sha256:a817ac80d6cf4b23bf7f2828b7cabf326f15a001bea8b1f9b49631780ba28350"}, + {file = "zipp-3.20.2.tar.gz", hash = "sha256:bc9eb26f4506fda01b81bcde0ca78103b6e62f991b381fec825435c836edbc29"}, ] [package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-ignore-flaky", "pytest-mypy", "pytest-ruff (>=0.2.1)"] +check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"] +cover = ["pytest-cov"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +enabler = ["pytest-enabler (>=2.2)"] +test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"] +type = ["pytest-mypy"] [package.source] type = "legacy" @@ -5314,5 +5231,5 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" -python-versions = ">=3.8.1,<3.11" -content-hash = "561999131f2c6e0873924232a90a425f9b0c42a178ea217146cd0a03a9fafad3" +python-versions = ">=3.11,<3.12" +content-hash = "3210f0b324acb7c5ee241e31c0df56b2be9be5b07f4c26306119b71882212961" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index a07bec9fae..3585486966 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -2,21 +2,21 @@ [tool.poetry] authors = ["blueking "] -description = "bluekign PaaS platform" +description = "blueking PaaS platform" name = "apiserver" version = "0.0.1" [tool.poetry.dependencies] -python = ">=3.8.1,<3.11" -aenum = "2.1.2" +python = ">=3.11,<3.12" +aenum = "3.1.15" apscheduler = "3.6.0" arrow = "0.12.1" bk-iam = "1.1.20" bkpaas-auth = "2.1.0" apigw-manager = "3.0.2" -bkstorages = "1.1.0" +bkstorages = "1.1.1" bleach = "3.3.0" -blue-krill = "2.0.3" +blue-krill = "2.0.6" bkapi-component-open = {version = "1.1.0"} boto = "2.49.0" boto3 = "1.33.13" @@ -24,7 +24,7 @@ botocore = "1.33.13" celery = "5.4.0" chardet = "3.0.4" click = "8.1.7" -cryptography = "42.0.5" +cryptography = "43.0.1" curlify = "2.2.1" dataclasses = {version = "0.7", python = ">=3.6.2,<3.7"} dj-static = "0.0.6" @@ -44,9 +44,9 @@ elasticsearch = "7.5.1" elasticsearch-dsl = "<8.0.0,>=7.0.0" future = "1.0.0" gevent = "24.2.1" -gunicorn = "20.1.0" +gunicorn = "22.0.0" grpcio = "1.55.3" -jinja2 = "3.1.3" +jinja2 = "3.1.4" jsonfield = "3.1.0" markdown = "3.6" msgpack = "1.0.4" @@ -63,16 +63,15 @@ python-logstash = "0.4.6" pyyaml = "6.0.1" packaging = "24.0" redis = "3.5.3" -requests = "2.31.0" +requests = "2.32.0" requests-oauthlib = "1.0.0" sentry-sdk = "0.19.4" sqlalchemy = "1.4.52" -sqlparse = "0.4.4" svn = "0.3.44" typing-extensions = "4.11.0" tzlocal = "2.1" unipath = "1.1" -werkzeug = "3.0.2" +werkzeug = "3.0.3" whitenoise = "5.3.0" wrapt = "1.15.0" xlwt = "1.3.0" @@ -99,7 +98,7 @@ semver = "^2.13.0" protobuf = ">=3.15.0,<4" kubernetes = "24.2.0" bk-notice-sdk = ">=1.2.0" -urllib3 = "1.26.18" +urllib3 = "1.26.20" python-json-logger = "^2.0.7" concurrent-log-handler = "^0.9.25" humanize = "4.9.0" diff --git a/pyproject.toml b/pyproject.toml index 6031122d44..8a27c61a6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,11 +5,10 @@ description = "Tencent Blueking PaaS platform(https://bk.tencent.com/)" authors = ["blueking "] [tool.poetry.dependencies] -python = ">=3.8.1,<3.9" -urllib3 = "1.26.18" +python = ">=3.11,<3.12" [tool.poetry.group.dev.dependencies] -ruff = "^0.5.0" +ruff = "^0.6.9" black = "24.3.0" [tool.ruff] From d827aa62920e4d3f9452fbecdec2ec47e2d94589 Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 15:50:03 +0800 Subject: [PATCH 02/16] feat: update Dockerfile --- apiserver/Dockerfile | 12 +----------- .../dev_utils/unittest/Dockerfile.devops.unittest | 12 +----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index e54395da62..3b219a8e88 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -25,17 +25,7 @@ RUN EDITION=${EDITION} npm run build FROM python:3.11.10-slim-bullseye USER root -RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim - -# Add buster-backports to sources.list -RUN echo "deb http://archive.debian.org/debian buster-backports main" >> /etc/apt/sources.list -# Install git from backports, because the version(git:v2.20.1) in buster will leak usernames from the url -# And this bug is fixed in v2.22.0, so we should install git from buster-backports, which is v2.30.2-1 -# See more info at: https://packages.debian.org/buster-backports/git -# -# Update(2024-05-07): The GitClient class has added a new logic to remove sensitive information -# in the git command output, so a newer git version is no longer required to fix the username leakage. -RUN apt-get update && apt-get -y install -t buster-backports git +RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf diff --git a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest index f9550154a5..8c9a2bacb8 100644 --- a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest +++ b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest @@ -25,17 +25,7 @@ RUN EDITION=${EDITION} npm run build FROM python:3.11.10-slim-bullseye USER root -RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim - -# Add buster-backports to sources.list -RUN echo "deb http://archive.debian.org/debian buster-backports main" >> /etc/apt/sources.list -# Install git from backports, because the version(git:v2.20.1) in buster will leak usernames from the url -# And this bug is fixed in v2.22.0, so we should install git from buster-backports, which is v2.30.2-1 -# See more info at: https://packages.debian.org/buster-backports/git -# -# Update(2024-05-07): The GitClient class has added a new logic to remove sensitive information -# in the git command output, so a newer git version is no longer required to fix the username leakage. -RUN apt-get update && apt-get -y install -t buster-backports git +RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf From 78783b73e4a9ca48a7554e5cc053799c832d2f8d Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 15:59:30 +0800 Subject: [PATCH 03/16] feat: update requests to 2.32.3 --- apiserver/poetry.lock | 8 ++++---- apiserver/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index 50c25b61ef..77e55d5f6e 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -3998,14 +3998,14 @@ reference = "tencent-mirror" [[package]] name = "requests" -version = "2.32.0" +version = "2.32.3" description = "Python HTTP for Humans." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "requests-2.32.0-py3-none-any.whl", hash = "sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5"}, - {file = "requests-2.32.0.tar.gz", hash = "sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8"}, + {file = "requests-2.32.3-py3-none-any.whl", hash = "sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6"}, + {file = "requests-2.32.3.tar.gz", hash = "sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760"}, ] [package.dependencies] @@ -5232,4 +5232,4 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "3210f0b324acb7c5ee241e31c0df56b2be9be5b07f4c26306119b71882212961" +content-hash = "307bdd9f37504a23688f196d7abfb62246f78ba985399bf5079fa7a9f07f7b06" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index 3585486966..aa146c4987 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -63,7 +63,7 @@ python-logstash = "0.4.6" pyyaml = "6.0.1" packaging = "24.0" redis = "3.5.3" -requests = "2.32.0" +requests = "2.32.3" requests-oauthlib = "1.0.0" sentry-sdk = "0.19.4" sqlalchemy = "1.4.52" From d70a95f373eceec48fff3e2ce2714e5346ccecb6 Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 16:06:30 +0800 Subject: [PATCH 04/16] feat: update pyproject.toml --- apiserver/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index aa146c4987..f67a023837 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] authors = ["blueking "] -description = "blueking PaaS platform" +description = "Tencent Blueking PaaS Platform" name = "apiserver" version = "0.0.1" From 41faf76987f61eb2f8d889520293a5bb6ff60ef3 Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 16:37:36 +0800 Subject: [PATCH 05/16] feat: update Dockerfile --- apiserver/Dockerfile | 2 -- apiserver/dev_utils/unittest/Dockerfile.devops.unittest | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index 3b219a8e88..6265f07a56 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -27,8 +27,6 @@ USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git -RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf - ENV LC_ALL=C.UTF-8 \ LANG=C.UTF-8 diff --git a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest index 8c9a2bacb8..096ee0134b 100644 --- a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest +++ b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest @@ -27,18 +27,17 @@ USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git -RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf - ENV LC_ALL=C.UTF-8 \ LANG=C.UTF-8 +RUN pip install --upgrade 'pip<24.1' + +RUN pip install poetry==1.8.3 + # Change security level of openssl to lower value in order to avoid "CA_MD_TOO_WEAK" error # See https://stackoverflow.com/questions/52218876/how-to-fix-ssl-issue-ssl-ctx-use-certificate-ca-md-too-weak-on-python-zeep?rq=1 RUN sed -i "s/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=0/g" /etc/ssl/openssl.cnf -RUN pip install --upgrade pip -RUN pip install poetry==1.8.3 - WORKDIR /app ADD ./pyproject.toml . From 4aefe451ff4c3b6d3db5666212ac6194a27e071c Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 17:23:07 +0800 Subject: [PATCH 06/16] feat: lock cryptography to 42.0.5 --- apiserver/poetry.lock | 83 ++++++++++++++++++++++++---------------- apiserver/pyproject.toml | 2 +- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index 77e55d5f6e..286f143bc4 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -402,8 +402,22 @@ version = "1.1.1" description = "File storage backends for blueking PaaS platform" category = "main" optional = false -python-versions = "*" -files = [] +python-versions = ">=3.6.2,<3.12" +files = [ + {file = "bkstorages-1.1.1-py3-none-any.whl", hash = "sha256:2b617a3519cb63013fd85a581201cdf9daf4ab7b6e9d61fb4314f4463b736cd8"}, + {file = "bkstorages-1.1.1.tar.gz", hash = "sha256:8ad9431857636f4c4576dec9deb8ee0dcab267ace943076c4cbf27b357022274"}, +] + +[package.dependencies] +boto3 = ">=1.4.1" +curlify = ">=2.2.1,<3.0.0" +requests = "*" +six = "*" + +[package.source] +type = "legacy" +url = "https://mirrors.tencent.com/pypi/simple" +reference = "tencent-mirror" [[package]] name = "bleach" @@ -1057,39 +1071,44 @@ reference = "tencent-mirror" [[package]] name = "cryptography" -version = "43.0.1" +version = "42.0.5" description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "cryptography-43.0.1-cp37-abi3-macosx_10_9_universal2.whl", hash = "sha256:8385d98f6a3bf8bb2d65a73e17ed87a3ba84f6991c155691c51112075f9ffc5d"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:27e613d7077ac613e399270253259d9d53872aaf657471473ebfc9a52935c062"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68aaecc4178e90719e95298515979814bda0cbada1256a4485414860bd7ab962"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:de41fd81a41e53267cb020bb3a7212861da53a7d39f863585d13ea11049cf277"}, - {file = "cryptography-43.0.1-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f98bf604c82c416bc829e490c700ca1553eafdf2912a91e23a79d97d9801372a"}, - {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:61ec41068b7b74268fa86e3e9e12b9f0c21fcf65434571dbb13d954bceb08042"}, - {file = "cryptography-43.0.1-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:014f58110f53237ace6a408b5beb6c427b64e084eb451ef25a28308270086494"}, - {file = "cryptography-43.0.1-cp37-abi3-win32.whl", hash = "sha256:2bd51274dcd59f09dd952afb696bf9c61a7a49dfc764c04dd33ef7a6b502a1e2"}, - {file = "cryptography-43.0.1-cp37-abi3-win_amd64.whl", hash = "sha256:666ae11966643886c2987b3b721899d250855718d6d9ce41b521252a17985f4d"}, - {file = "cryptography-43.0.1-cp39-abi3-macosx_10_9_universal2.whl", hash = "sha256:ac119bb76b9faa00f48128b7f5679e1d8d437365c5d26f1c2c3f0da4ce1b553d"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1bbcce1a551e262dfbafb6e6252f1ae36a248e615ca44ba302df077a846a8806"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:58d4e9129985185a06d849aa6df265bdd5a74ca6e1b736a77959b498e0505b85"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:d03a475165f3134f773d1388aeb19c2d25ba88b6a9733c5c590b9ff7bbfa2e0c"}, - {file = "cryptography-43.0.1-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:511f4273808ab590912a93ddb4e3914dfd8a388fed883361b02dea3791f292e1"}, - {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:80eda8b3e173f0f247f711eef62be51b599b5d425c429b5d4ca6a05e9e856baa"}, - {file = "cryptography-43.0.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:38926c50cff6f533f8a2dae3d7f19541432610d114a70808f0926d5aaa7121e4"}, - {file = "cryptography-43.0.1-cp39-abi3-win32.whl", hash = "sha256:a575913fb06e05e6b4b814d7f7468c2c660e8bb16d8d5a1faf9b33ccc569dd47"}, - {file = "cryptography-43.0.1-cp39-abi3-win_amd64.whl", hash = "sha256:d75601ad10b059ec832e78823b348bfa1a59f6b8d545db3a24fd44362a1564cb"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ea25acb556320250756e53f9e20a4177515f012c9eaea17eb7587a8c4d8ae034"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c1332724be35d23a854994ff0b66530119500b6053d0bd3363265f7e5e77288d"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:fba1007b3ef89946dbbb515aeeb41e30203b004f0b4b00e5e16078b518563289"}, - {file = "cryptography-43.0.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:5b43d1ea6b378b54a1dc99dd8a2b5be47658fe9a7ce0a58ff0b55f4b43ef2b84"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:88cce104c36870d70c49c7c8fd22885875d950d9ee6ab54df2745f83ba0dc365"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:9d3cdb25fa98afdd3d0892d132b8d7139e2c087da1712041f6b762e4f807cc96"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:e710bf40870f4db63c3d7d929aa9e09e4e7ee219e703f949ec4073b4294f6172"}, - {file = "cryptography-43.0.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7c05650fe8023c5ed0d46793d4b7d7e6cd9c04e68eabe5b0aeea836e37bdcec2"}, - {file = "cryptography-43.0.1.tar.gz", hash = "sha256:203e92a75716d8cfb491dc47c79e17d0d9207ccffcbcb35f598fbe463ae3444d"}, + {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:a30596bae9403a342c978fb47d9b0ee277699fa53bbafad14706af51fe543d16"}, + {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:b7ffe927ee6531c78f81aa17e684e2ff617daeba7f189f911065b2ea2d526dec"}, + {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2424ff4c4ac7f6b8177b53c17ed5d8fa74ae5955656867f5a8affaca36a27abb"}, + {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:329906dcc7b20ff3cad13c069a78124ed8247adcac44b10bea1130e36caae0b4"}, + {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:b03c2ae5d2f0fc05f9a2c0c997e1bc18c8229f392234e8a0194f202169ccd278"}, + {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f8837fe1d6ac4a8052a9a8ddab256bc006242696f03368a4009be7ee3075cdb7"}, + {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:0270572b8bd2c833c3981724b8ee9747b3ec96f699a9665470018594301439ee"}, + {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:b8cac287fafc4ad485b8a9b67d0ee80c66bf3574f655d3b97ef2e1082360faf1"}, + {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:16a48c23a62a2f4a285699dba2e4ff2d1cff3115b9df052cdd976a18856d8e3d"}, + {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:2bce03af1ce5a5567ab89bd90d11e7bbdff56b8af3acbbec1faded8f44cb06da"}, + {file = "cryptography-42.0.5-cp37-abi3-win32.whl", hash = "sha256:b6cd2203306b63e41acdf39aa93b86fb566049aeb6dc489b70e34bcd07adca74"}, + {file = "cryptography-42.0.5-cp37-abi3-win_amd64.whl", hash = "sha256:98d8dc6d012b82287f2c3d26ce1d2dd130ec200c8679b6213b3c73c08b2b7940"}, + {file = "cryptography-42.0.5-cp39-abi3-macosx_10_12_universal2.whl", hash = "sha256:5e6275c09d2badf57aea3afa80d975444f4be8d3bc58f7f80d2a484c6f9485c8"}, + {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4985a790f921508f36f81831817cbc03b102d643b5fcb81cd33df3fa291a1a1"}, + {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7cde5f38e614f55e28d831754e8a3bacf9ace5d1566235e39d91b35502d6936e"}, + {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7367d7b2eca6513681127ebad53b2582911d1736dc2ffc19f2c3ae49997496bc"}, + {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:cd2030f6650c089aeb304cf093f3244d34745ce0cfcc39f20c6fbfe030102e2a"}, + {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a2913c5375154b6ef2e91c10b5720ea6e21007412f6437504ffea2109b5a33d7"}, + {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:c41fb5e6a5fe9ebcd58ca3abfeb51dffb5d83d6775405305bfa8715b76521922"}, + {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:3eaafe47ec0d0ffcc9349e1708be2aaea4c6dd4978d76bf6eb0cb2c13636c6fc"}, + {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1b95b98b0d2af784078fa69f637135e3c317091b615cd0905f8b8a087e86fa30"}, + {file = "cryptography-42.0.5-cp39-abi3-win32.whl", hash = "sha256:1f71c10d1e88467126f0efd484bd44bca5e14c664ec2ede64c32f20875c0d413"}, + {file = "cryptography-42.0.5-cp39-abi3-win_amd64.whl", hash = "sha256:a011a644f6d7d03736214d38832e030d8268bcff4a41f728e6030325fea3e400"}, + {file = "cryptography-42.0.5-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:9481ffe3cf013b71b2428b905c4f7a9a4f76ec03065b05ff499bb5682a8d9ad8"}, + {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:ba334e6e4b1d92442b75ddacc615c5476d4ad55cc29b15d590cc6b86efa487e2"}, + {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:ba3e4a42397c25b7ff88cdec6e2a16c2be18720f317506ee25210f6d31925f9c"}, + {file = "cryptography-42.0.5-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:111a0d8553afcf8eb02a4fea6ca4f59d48ddb34497aa8706a6cf536f1a5ec576"}, + {file = "cryptography-42.0.5-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:cd65d75953847815962c84a4654a84850b2bb4aed3f26fadcc1c13892e1e29f6"}, + {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:e807b3188f9eb0eaa7bbb579b462c5ace579f1cedb28107ce8b48a9f7ad3679e"}, + {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:f12764b8fffc7a123f641d7d049d382b73f96a34117e0b637b80643169cec8ac"}, + {file = "cryptography-42.0.5-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:37dd623507659e08be98eec89323469e8c7b4c1407c85112634ae3dbdb926fdd"}, + {file = "cryptography-42.0.5.tar.gz", hash = "sha256:6fe07eec95dfd477eb9530aef5bead34fec819b3aaf6c5bd6d20565da607bfe1"}, ] [package.dependencies] @@ -1102,7 +1121,7 @@ nox = ["nox"] pep8test = ["check-sdist", "click", "mypy", "ruff"] sdist = ["build"] ssh = ["bcrypt (>=3.1.5)"] -test = ["certifi", "cryptography-vectors (==43.0.1)", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] +test = ["certifi", "pretend", "pytest (>=6.2.0)", "pytest-benchmark", "pytest-cov", "pytest-xdist"] test-randomorder = ["pytest-randomly"] [package.source] @@ -5232,4 +5251,4 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "307bdd9f37504a23688f196d7abfb62246f78ba985399bf5079fa7a9f07f7b06" +content-hash = "c78ad5bb482b6c691bd4266065b8cb00ac5dc4cff1f7ed478e740b327becf28f" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index f67a023837..7aefec76c3 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -24,7 +24,7 @@ botocore = "1.33.13" celery = "5.4.0" chardet = "3.0.4" click = "8.1.7" -cryptography = "43.0.1" +cryptography = "42.0.5" curlify = "2.2.1" dataclasses = {version = "0.7", python = ">=3.6.2,<3.7"} dj-static = "0.0.6" From 56b1d160adecd395425390cc650518d90856349a Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 17:31:37 +0800 Subject: [PATCH 07/16] feat: update elasticsearch to 7.17.12 --- apiserver/poetry.lock | 16 +++++++++------- apiserver/pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index 286f143bc4..793b322e50 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -1626,21 +1626,23 @@ reference = "tencent-mirror" [[package]] name = "elasticsearch" -version = "7.5.1" +version = "7.17.12" description = "Python client for Elasticsearch" category = "main" optional = false -python-versions = "*" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4" files = [ - {file = "elasticsearch-7.5.1-py2.py3-none-any.whl", hash = "sha256:1815ee1377e7d3cf32770738a70785fe4ab1f05be28336a330ed71cb295a7c6c"}, - {file = "elasticsearch-7.5.1.tar.gz", hash = "sha256:2a0ca516378ae9b87ac840e7bb529ec508f3010360dd9feed605dff2a898aff5"}, + {file = "elasticsearch-7.17.12-py2.py3-none-any.whl", hash = "sha256:468fd5eef703c0d9238e29bcaf3a6fe4d6b092f917959fbf41f48f8fea3df2f8"}, + {file = "elasticsearch-7.17.12.tar.gz", hash = "sha256:a1f5733ae8cf1dbf0a78593389f2503c87dd97429976099832bf0626cdfaac8b"}, ] [package.dependencies] -urllib3 = ">=1.21.1" +certifi = "*" +urllib3 = ">=1.21.1,<2" [package.extras] -develop = ["black", "coverage", "jinja2", "mock", "nose", "nosexcover", "pyaml", "requests (>=2.0.0,<3.0.0)", "sphinx (<1.7)", "sphinx-rtd-theme"] +async = ["aiohttp (>=3,<4)"] +develop = ["black", "coverage", "jinja2", "mock", "pytest", "pytest-cov", "pyyaml", "requests (>=2.0.0,<3.0.0)", "sphinx (<1.7)", "sphinx-rtd-theme"] docs = ["sphinx (<1.7)", "sphinx-rtd-theme"] requests = ["requests (>=2.4.0,<3.0.0)"] @@ -5251,4 +5253,4 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "c78ad5bb482b6c691bd4266065b8cb00ac5dc4cff1f7ed478e740b327becf28f" +content-hash = "7c42776b00b29e603ed5a98c5eabb41dc4d19f61a69c0bc6dac3e063de55af8e" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index 7aefec76c3..0ce8d86392 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -40,7 +40,7 @@ djangorestframework = "3.15.1" django-prometheus = "2.2.0" "dogpile.cache" = "1.1.6" drf-yasg = "1.21.7" -elasticsearch = "7.5.1" +elasticsearch = "7.17.12" elasticsearch-dsl = "<8.0.0,>=7.0.0" future = "1.0.0" gevent = "24.2.1" From 831691baf2ce58e5ec063d11ffb21db5937a8bca Mon Sep 17 00:00:00 2001 From: narasux Date: Sat, 12 Oct 2024 18:08:56 +0800 Subject: [PATCH 08/16] fix: aenum's stricter checks causing extend_enum to fail --- apiserver/paasng/paasng/accessories/log/client.py | 6 ++++-- .../paasng/paasng/bk_plugins/pluginscenter/log/client.py | 2 +- apiserver/paasng/paasng/infras/accounts/constants.py | 7 +++++-- apiserver/paasng/paasng/platform/sourcectl/constants.py | 2 +- apiserver/paasng/paasng/platform/sourcectl/source_types.py | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apiserver/paasng/paasng/accessories/log/client.py b/apiserver/paasng/paasng/accessories/log/client.py index db91355391..4b39eedb1e 100644 --- a/apiserver/paasng/paasng/accessories/log/client.py +++ b/apiserver/paasng/paasng/accessories/log/client.py @@ -107,6 +107,7 @@ def execute_scroll_search( if not resp["result"]: # 有可能是 scroll id 失效了, 反正抛异常就对了 + scroll_id = scroll_id or "none" raise ScanError(scroll_id, "Scroll request has failed on `{}`".format(resp["message"])) response = Response(search.search, resp["data"]) @@ -223,6 +224,7 @@ def execute_scroll_search( if not response.success(): failed = response._shards.failed total = response._shards.total + scroll_id = scroll_id or "none" raise ScanError( scroll_id, "Scroll request has failed on %d shards out of %d." % (failed, total), @@ -272,7 +274,7 @@ def get_mappings(self, index: str, time_range: SmartTimeRange, timeout: int) -> # 当前假设同一批次的 index(类似 aa-2021.04.20,aa-2021.04.19) 拥有相同的 mapping, 因此直接获取最新的 mapping # 如果同一批次 index mapping 发生变化,可能会导致日志查询为空 es_index = self._get_indexes(index, time_range, timeout) - all_mappings = self._client.indices.get_mapping(es_index, params={"request_timeout": timeout}) + all_mappings = self._client.indices.get_mapping(index=es_index, params={"request_timeout": timeout}) # 由于手动创建会没有 properties, 需要将无 properties 的 mappings 过滤掉 all_not_empty_mappings = { key: mapping for key, mapping in all_mappings.items() if mapping["mappings"].get("properties") @@ -290,7 +292,7 @@ def _get_indexes(self, index: str, time_range: SmartTimeRange, timeout: int) -> # Note: 使用 stats 接口优化查询性能 all_indexes = list( self._client.indices.stats( - index, metric="fielddata", params={"request_timeout": timeout, "level": "indices"} + index=index, metric="fielddata", params={"request_timeout": timeout, "level": "indices"} )["indices"].keys() ) if filtered_indexes := filter_indexes_by_time_range(all_indexes, time_range=time_range): diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/log/client.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/log/client.py index 3045046484..ee91ded503 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/log/client.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/log/client.py @@ -182,7 +182,7 @@ def _get_properties_filters(self, index: str, timeout: int) -> Dict[str, FieldFi """获取属性映射""" # 当前假设同一批次的 index(类似 aa-2021.04.20,aa-2021.04.19) 拥有相同的 mapping, 因此直接获取最新的 mapping # 如果同一批次 index mapping 发生变化,可能会导致日志查询为空 - all_mappings = self._client.indices.get_mapping(index, params={"request_timeout": timeout}) + all_mappings = self._client.indices.get_mapping(index=index, params={"request_timeout": timeout}) if not all_mappings: raise error_codes.QUERY_ES_ERROR.f( _("No mappings available, maybe index does not exist or no logs at all") diff --git a/apiserver/paasng/paasng/infras/accounts/constants.py b/apiserver/paasng/paasng/infras/accounts/constants.py index e107a1b212..0e7c73e587 100644 --- a/apiserver/paasng/paasng/infras/accounts/constants.py +++ b/apiserver/paasng/paasng/infras/accounts/constants.py @@ -90,13 +90,16 @@ def get_default_flags(cls) -> Dict[str, bool]: return flags.copy() @classmethod - def register_ext_feature_flag(cls, feature_flag: FeatureFlagField): + def register_ext_feature_flag(cls, feature_flag: FeatureFlagField) -> None: """注册额外的用户特性到枚举类中""" name, label, default = feature_flag.name, feature_flag.label, feature_flag.default + # 已经注册过的,需要跳过 + if getattr(cls, name, None): + return + extend_enum(cls, name, name) cls._choices_labels.value.append((name, label)) cls._defaults[name] = default # type: ignore - return name class FunctionType(ChoicesEnum): diff --git a/apiserver/paasng/paasng/platform/sourcectl/constants.py b/apiserver/paasng/paasng/platform/sourcectl/constants.py index 76cb29482a..02b88aaad8 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/constants.py +++ b/apiserver/paasng/paasng/platform/sourcectl/constants.py @@ -35,7 +35,7 @@ class BasicSourceType(str, StructuredEnum): PACKAGE = "package" -def register_new_sourcectl_type(name: str, feature_flag: FeatureFlagField): +def register_new_sourcectl_type(feature_flag: FeatureFlagField): """暴露给 TE 版本的注册 SourcectlType 的方法 :param name: 源码类型名称 diff --git a/apiserver/paasng/paasng/platform/sourcectl/source_types.py b/apiserver/paasng/paasng/platform/sourcectl/source_types.py index f41bf8c423..d0bc6460f7 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/source_types.py +++ b/apiserver/paasng/paasng/platform/sourcectl/source_types.py @@ -16,6 +16,7 @@ # to the current version of the project delivered to anyone in the future. """Sourcectl type specifications""" + import logging from collections import OrderedDict, defaultdict from dataclasses import dataclass @@ -227,7 +228,7 @@ def load_from_configs(self, configs: List): type_specs = cls(**conf["attrs"]) self.data[type_specs.name] = type_specs - register_new_sourcectl_type(type_specs.name, type_specs.make_feature_flag_field()) + register_new_sourcectl_type(type_specs.make_feature_flag_field()) self.initialized = True From f7476576439f4d2bcc02f97f32f4d771cf8405f7 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 14 Oct 2024 11:32:50 +0800 Subject: [PATCH 09/16] fix: update attrs to 22.1.0 --- apiserver/poetry.lock | 16 ++++++++-------- apiserver/pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index 793b322e50..d4a19ca30a 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -162,21 +162,21 @@ reference = "tencent-mirror" [[package]] name = "attrs" -version = "21.4.0" +version = "22.1.0" description = "Classes Without Boilerplate" category = "main" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.5" files = [ - {file = "attrs-21.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, - {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, + {file = "attrs-22.1.0-py2.py3-none-any.whl", hash = "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"}, + {file = "attrs-22.1.0.tar.gz", hash = "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6"}, ] [package.extras] -dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "sphinx", "sphinx-notfound-page", "zope.interface"] +dev = ["cloudpickle", "coverage[toml] (>=5.0.2)", "furo", "hypothesis", "mypy (>=0.900,!=0.940)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "sphinx", "sphinx-notfound-page", "zope.interface"] docs = ["furo", "sphinx", "sphinx-notfound-page", "zope.interface"] -tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six", "zope.interface"] -tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "six"] +tests = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "zope.interface"] +tests-no-zope = ["cloudpickle", "coverage[toml] (>=5.0.2)", "hypothesis", "mypy (>=0.900,!=0.940)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins"] [package.source] type = "legacy" @@ -5253,4 +5253,4 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "7c42776b00b29e603ed5a98c5eabb41dc4d19f61a69c0bc6dac3e063de55af8e" +content-hash = "07a6d82d5b02d1b39441578e795ebe1c272f5ba8a2beb26330d07fa0774d7ad7" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index 0ce8d86392..3aa85e05c7 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -81,7 +81,7 @@ bkapi-bk-apigateway = {version = "1.0.11"} moby-distribution = "0.8.2" pillow = "10.3.0" cattrs = "1.10.0" -attrs = "21.4.0" +attrs = "22.1.0" django-translated-fields = "^0.12.0" dynaconf = "^3.1.8" opentelemetry-api = "1.24.0" From 4da0ef0a3bec72d739868c84c6d38087fcd93d45 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 14 Oct 2024 15:51:47 +0800 Subject: [PATCH 10/16] refactor: add StrEnum & IntEnum --- .../paas_wl/bk_app/applications/constants.py | 6 +-- .../paas_wl/bk_app/cnative/specs/constants.py | 25 +++++------ .../paas_wl/bk_app/dev_sandbox/entities.py | 5 +-- .../bk_app/monitoring/bklog/constants.py | 4 +- .../paas_wl/bk_app/processes/constants.py | 8 ++-- .../paas_wl/infras/cluster/constants.py | 8 ++-- .../infras/resource_templates/constants.py | 4 +- apiserver/paasng/paas_wl/utils/blobstore.py | 9 ++-- apiserver/paasng/paas_wl/utils/constants.py | 11 +++-- apiserver/paasng/paas_wl/utils/kubestatus.py | 5 ++- .../workloads/autoscaling/constants.py | 13 +++--- .../paas_wl/workloads/networking/constants.py | 6 +-- .../networking/entrance/allocator/domains.py | 6 +-- .../networking/entrance/allocator/subpaths.py | 5 ++- .../networking/entrance/constants.py | 8 ++-- .../workloads/networking/ingress/constants.py | 6 +-- .../workloads/release_controller/constants.py | 6 +-- .../paasng/paasng/accessories/ci/constants.py | 4 +- .../paasng/accessories/cloudapi/constants.py | 14 +++---- .../paasng/accessories/log/constants.py | 8 ++-- .../accessories/paas_analysis/constants.py | 10 ++--- .../accessories/publish/market/constant.py | 8 ++-- .../accessories/servicehub/constants.py | 9 ++-- .../services/providers/mysql/constants.py | 3 +- .../paasng/bk_plugins/bk_plugins/constants.py | 4 +- .../pluginscenter/bk_devops/constants.py | 4 +- .../bk_plugins/pluginscenter/constants.py | 37 +++++++++-------- .../pluginscenter/iam_adaptor/constants.py | 6 +-- .../pluginscenter/itsm_adaptor/constants.py | 7 ++-- .../infras/accounts/permissions/constants.py | 5 ++- .../paasng/paasng/infras/bk_ci/constants.py | 5 ++- .../paasng/paasng/infras/bk_log/constatns.py | 8 ++-- .../paasng/infras/bkmonitorv3/constants.py | 5 ++- .../paasng/paasng/infras/iam/constants.py | 7 ++-- apiserver/paasng/paasng/infras/iam/legacy.py | 5 ++- .../paasng/infras/iam/open_apis/constants.py | 4 +- .../iam/permissions/resources/application.py | 4 +- .../paasng/paasng/misc/audit/constants.py | 13 +++--- .../misc/monitoring/metrics/constants.py | 9 ++-- .../monitor/alert_rules/config/entities.py | 4 +- .../paasng/paasng/plat_admin/numbers/app.py | 2 +- .../paasng/plat_admin/system/constants.py | 3 +- .../paasng/platform/applications/constants.py | 16 ++++---- .../management/commands/force_del_app.py | 4 +- .../paasng/platform/bkapp_model/constants.py | 12 +++--- .../paasng/platform/bkapp_model/utils.py | 5 +-- .../paasng/platform/declarative/constants.py | 8 ++-- .../paasng/platform/engine/constants.py | 20 ++++----- .../paasng/platform/engine/models/phases.py | 4 +- .../platform/engine/processes/events.py | 3 +- .../paasng/platform/engine/utils/output.py | 4 +- .../paasng/platform/evaluation/constants.py | 11 ++--- .../paasng/platform/mgrlegacy/constants.py | 5 +-- .../paasng/platform/modules/constants.py | 15 ++++--- .../paasng/platform/sourcectl/client.py | 6 +-- .../paasng/platform/sourcectl/constants.py | 10 ++--- .../paasng/platform/templates/constants.py | 5 ++- apiserver/paasng/paasng/utils/blobstore.py | 5 ++- apiserver/paasng/paasng/utils/enum.py | 41 +++++++++++++++++++ .../paasng/paasng/utils/patternmatcher.py | 4 +- .../paasng/utils/rate_limit/constants.py | 4 +- 61 files changed, 279 insertions(+), 226 deletions(-) create mode 100644 apiserver/paasng/paasng/utils/enum.py diff --git a/apiserver/paasng/paas_wl/bk_app/applications/constants.py b/apiserver/paasng/paas_wl/bk_app/applications/constants.py index 2c21040431..d4f34b3536 100644 --- a/apiserver/paasng/paas_wl/bk_app/applications/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/applications/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class WlAppType(str, StructuredEnum): +class WlAppType(StrEnum): """type of workloads app""" DEFAULT = EnumField("default") # 默认类型:无任何定制逻辑 @@ -28,7 +28,7 @@ class WlAppType(str, StructuredEnum): CLOUD_NATIVE = EnumField("cloud_native") -class ArtifactType(str, StructuredEnum): +class ArtifactType(StrEnum): """type of build artifact""" SLUG = EnumField("slug") diff --git a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py index f84835fdd3..f6c0d98cb1 100644 --- a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py @@ -15,9 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum + # Default resource limitations for each process DEFAULT_PROC_CPU = "4000m" DEFAULT_PROC_MEM = "1024Mi" @@ -66,14 +67,14 @@ PROC_SERVICES_ENABLED_ANNOTATION_KEY = "bkapp.paas.bk.tencent.com/proc-services-feature-enabled" -class ApiVersion(str, StructuredEnum): +class ApiVersion(StrEnum): """Kubernetes CRD API versions""" V1ALPHA1 = "paas.bk.tencent.com/v1alpha1" V1ALPHA2 = "paas.bk.tencent.com/v1alpha2" -class DeployStatus(str, StructuredEnum): +class DeployStatus(StrEnum): """Cloud-native app's deployment statuses""" PENDING = EnumField("pending", label=_("待实施")) @@ -90,7 +91,7 @@ def is_stable(cls, val: "DeployStatus") -> bool: return val in [DeployStatus.READY, DeployStatus.ERROR] -class DomainGroupSource(str, StructuredEnum): +class DomainGroupSource(StrEnum): """The source types for DomainGroup data""" SUBDOMAIN = "subdomain" @@ -98,14 +99,14 @@ class DomainGroupSource(str, StructuredEnum): CUSTOM = "custom" -class MResConditionType(str, StructuredEnum): +class MResConditionType(StrEnum): APP_AVAILABLE = EnumField("AppAvailable") APP_PROGRESSING = EnumField("AppProgressing") ADDONS_PROVISIONED = EnumField("AddOnsProvisioned") HOOKS_FINISHED = EnumField("HooksFinished") -class ConditionStatus(str, StructuredEnum): +class ConditionStatus(StrEnum): """k8s metav1.ConditionStatus""" TRUE = EnumField("True") @@ -113,7 +114,7 @@ class ConditionStatus(str, StructuredEnum): UNKNOWN = EnumField("Unknown") -class MResPhaseType(str, StructuredEnum): +class MResPhaseType(StrEnum): """a label for the condition of a BkApp at the current time.""" AppPending = EnumField("Pending") @@ -121,7 +122,7 @@ class MResPhaseType(str, StructuredEnum): AppFailed = EnumField("Failed") -class ScalingPolicy(str, StructuredEnum): +class ScalingPolicy(StrEnum): """ScalingPolicy is used to specify which policy should be used while scaling""" # the default autoscaling policy (cpu utilization 85%) @@ -134,7 +135,7 @@ class ScalingPolicy(str, StructuredEnum): __str__ = str.__str__ -class ResQuotaPlan(str, StructuredEnum): +class ResQuotaPlan(StrEnum): """ResQuotaPlan is used to specify process resource quota""" P_DEFAULT = EnumField("default", label="default") @@ -149,7 +150,7 @@ class ResQuotaPlan(str, StructuredEnum): __str__ = str.__str__ -class MountEnvName(str, StructuredEnum): +class MountEnvName(StrEnum): """Environment name for managing mount volume""" STAG = EnumField("stag", label="仅测试环境") @@ -157,12 +158,12 @@ class MountEnvName(str, StructuredEnum): GLOBAL = EnumField("_global_", label="所有环境") -class VolumeSourceType(str, StructuredEnum): +class VolumeSourceType(StrEnum): ConfigMap = EnumField("ConfigMap") PersistentStorage = EnumField("PersistentStorage") -class PersistentStorageSize(str, StructuredEnum): +class PersistentStorageSize(StrEnum): P_1G = EnumField("1Gi") P_2G = EnumField("2Gi") P_4G = EnumField("4Gi") diff --git a/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py b/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py index 80454b62f9..531f6018f7 100644 --- a/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py +++ b/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py @@ -18,12 +18,11 @@ from dataclasses import dataclass, field from typing import Dict, List, Optional -from blue_krill.data_types.enum import EnumField, StructuredEnum - from paas_wl.workloads.release_controller.constants import ImagePullPolicy +from paasng.utils.enum import EnumField, StrEnum -class HealthPhase(str, StructuredEnum): +class HealthPhase(StrEnum): HEALTHY = EnumField("Healthy") PROGRESSING = EnumField("Progressing") UNHEALTHY = EnumField("Unhealthy") diff --git a/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py b/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py index 605b340db9..2ac237dbfb 100644 --- a/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum # 注解或标签中存储应用名称的键名 BKAPP_NAME_ANNO_KEY = "bkapp.paas.bk.tencent.com/name" @@ -29,7 +29,7 @@ WLAPP_NAME_ANNO_KEY = "bkapp.paas.bk.tencent.com/wl-app-name" -class BkLogConfigType(str, StructuredEnum): +class BkLogConfigType(StrEnum): STD_LOG = EnumField("std_log_config", label="标准输出日志") CONTAINER_LOG = EnumField("container_log_config", label="容器日志") NODE_LOG = EnumField("node_log_config", label="节点日志") diff --git a/apiserver/paasng/paas_wl/bk_app/processes/constants.py b/apiserver/paasng/paas_wl/bk_app/processes/constants.py index deb48535d0..3a8c41464d 100644 --- a/apiserver/paasng/paas_wl/bk_app/processes/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/processes/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum # 注解或标签中存储进程名称的键名 PROCESS_NAME_KEY = "bkapp.paas.bk.tencent.com/process-name" @@ -26,7 +26,7 @@ DEFAULT_CNATIVE_MAX_REPLICAS = 10 -class ProcessUpdateType(str, StructuredEnum): +class ProcessUpdateType(StrEnum): """Type of updating processes""" START = EnumField("start") @@ -35,14 +35,14 @@ class ProcessUpdateType(str, StructuredEnum): SCALE = EnumField("scale") -class ProcessTargetStatus(str, StructuredEnum): +class ProcessTargetStatus(StrEnum): """Choices of process status""" START = EnumField("start") STOP = EnumField("stop") -class ProbeType(str, StructuredEnum): +class ProbeType(StrEnum): """Choices of probe type""" READINESS = EnumField("readiness", label="readinessProbe") diff --git a/apiserver/paasng/paas_wl/infras/cluster/constants.py b/apiserver/paasng/paas_wl/infras/cluster/constants.py index 8ffe67514f..736a700d29 100644 --- a/apiserver/paasng/paas_wl/infras/cluster/constants.py +++ b/apiserver/paasng/paas_wl/infras/cluster/constants.py @@ -17,16 +17,18 @@ from typing import Dict -from blue_krill.data_types.enum import EnumField, FeatureFlag, FeatureFlagField, StructuredEnum +from blue_krill.data_types.enum import FeatureFlag, FeatureFlagField from django.conf import settings from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class ClusterTokenType(int, StructuredEnum): + +class ClusterTokenType(IntEnum): SERVICE_ACCOUNT = 1 -class ClusterType(str, StructuredEnum): +class ClusterType(StrEnum): """集群类别""" NORMAL = EnumField("normal", label=_("普通集群")) diff --git a/apiserver/paasng/paas_wl/infras/resource_templates/constants.py b/apiserver/paasng/paas_wl/infras/resource_templates/constants.py index b348c728e5..49dffc00dd 100644 --- a/apiserver/paasng/paas_wl/infras/resource_templates/constants.py +++ b/apiserver/paasng/paas_wl/infras/resource_templates/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, IntEnum -class AppAddOnType(int, StructuredEnum): +class AppAddOnType(IntEnum): SIMPLE_SIDECAR = EnumField(1, label="SideCar Container") READINESS_PROBE = EnumField(2, label="Readiness Probe") VOLUME_MOUNT = EnumField(3, label="Volume Mount Point") diff --git a/apiserver/paasng/paas_wl/utils/blobstore.py b/apiserver/paasng/paas_wl/utils/blobstore.py index 615cc1daea..39e45e9cfb 100644 --- a/apiserver/paasng/paas_wl/utils/blobstore.py +++ b/apiserver/paasng/paas_wl/utils/blobstore.py @@ -15,21 +15,22 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -"""BlobStore client -""" +"""BlobStore client""" + import logging from typing import Optional -from blue_krill.data_types.enum import EnumField, StructuredEnum from blue_krill.storages.blobstore.base import BlobStore from blue_krill.storages.blobstore.bkrepo import BKGenericRepo from blue_krill.storages.blobstore.s3 import S3Store from django.conf import settings +from paasng.utils.enum import EnumField, StrEnum + logger = logging.getLogger(__name__) -class StoreType(str, StructuredEnum): +class StoreType(StrEnum): S3 = EnumField("s3") BKREPO = EnumField("bkrepo") diff --git a/apiserver/paasng/paas_wl/utils/constants.py b/apiserver/paasng/paas_wl/utils/constants.py index e7165bb82c..2017873622 100644 --- a/apiserver/paasng/paas_wl/utils/constants.py +++ b/apiserver/paasng/paas_wl/utils/constants.py @@ -17,12 +17,11 @@ from typing import List -from blue_krill.data_types.enum import EnumField, StructuredEnum - from paasng.platform.engine.constants import JobStatus +from paasng.utils.enum import EnumField, StrEnum -class BuildStatus(str, StructuredEnum): +class BuildStatus(StrEnum): SUCCESSFUL = EnumField("successful", "成功") FAILED = EnumField("failed", "失败") PENDING = EnumField("pending", "等待") @@ -34,7 +33,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class CommandStatus(str, StructuredEnum): +class CommandStatus(StrEnum): SCHEDULED = EnumField("scheduled", label="已调度") SUCCESSFUL = EnumField("successful", "成功") FAILED = EnumField("failed", "失败") @@ -55,7 +54,7 @@ def to_job_status(self) -> JobStatus: return JobStatus(self.value) -class CommandType(str, StructuredEnum): +class CommandType(StrEnum): PRE_RELEASE_HOOK = EnumField("pre-release-hook", label="发布前置指令") def get_step_name(self): @@ -77,7 +76,7 @@ def make_enum_choices(obj): return [(member.value, name) for name, member in obj.__members__.items()] -class PodPhase(str, StructuredEnum): +class PodPhase(StrEnum): SUCCEEDED = EnumField("Succeeded", "成功") FAILED = EnumField("Failed", "失败") RUNNING = EnumField("Running", "运行中") diff --git a/apiserver/paasng/paas_wl/utils/kubestatus.py b/apiserver/paasng/paas_wl/utils/kubestatus.py index b2a1daef44..f2a83c1e29 100644 --- a/apiserver/paasng/paas_wl/utils/kubestatus.py +++ b/apiserver/paasng/paas_wl/utils/kubestatus.py @@ -20,13 +20,14 @@ import kubernetes.client.models as kmodels from attrs import define -from blue_krill.data_types.enum import StructuredEnum from blue_krill.text import remove_prefix from kubernetes.client import ApiClient from kubernetes.dynamic.resource import ResourceField, ResourceInstance +from paasng.utils.enum import StrEnum -class HealthStatusType(StructuredEnum): + +class HealthStatusType(StrEnum): HEALTHY = "Healthy" UNHEALTHY = "Unhealthy" PROGRESSING = "progressing" diff --git a/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py b/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py index 1d812b3dac..4da50ae686 100644 --- a/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py +++ b/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py @@ -15,22 +15,23 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext as _ +from paasng.utils.enum import EnumField, StrEnum + # 添加注解 compute-by-limits=true 后,CPU 计算 Utilization 时 # 将根据当前使用量 & limits 来计算目标副本数,否则默认使用 requests 来计算 GPA_COMPUTE_BY_LIMITS_ANNO_KEY = "compute-by-limits" -class ScalingMetricName(str, StructuredEnum): +class ScalingMetricName(StrEnum): """扩缩容指标名称(用于组装 CPA 的指标)""" CPU = EnumField("cpu") MEMORY = EnumField("memory") -class ScalingMetricSourceType(str, StructuredEnum): +class ScalingMetricSourceType(StrEnum): """扩缩容指标类型""" RESOURCE = EnumField("Resource") @@ -38,14 +39,14 @@ class ScalingMetricSourceType(str, StructuredEnum): OBJECT = EnumField("Object") -class ScalingMetricTargetType(str, StructuredEnum): +class ScalingMetricTargetType(StrEnum): """扩缩容指标计量类型(用于组装 CPA 的指标类型)""" UTILIZATION = EnumField("Utilization") AVERAGE_VALUE = EnumField("AverageValue") -class ScalingEnvName(str, StructuredEnum): +class ScalingEnvName(StrEnum): """扩缩容生效环境""" STAG = EnumField("stag", label="仅测试环境") @@ -53,7 +54,7 @@ class ScalingEnvName(str, StructuredEnum): GLOBAL = EnumField("_global_", label="所有环境") -class ScalingMetric(str, StructuredEnum): +class ScalingMetric(StrEnum): """扩缩容指标(用户可选指标)""" CPU_UTILIZATION = EnumField("cpuUtilization", label=_("CPU 使用率")) diff --git a/apiserver/paasng/paas_wl/workloads/networking/constants.py b/apiserver/paasng/paas_wl/workloads/networking/constants.py index ab9b34fa2f..e7f3d85722 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/constants.py @@ -14,13 +14,13 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class NetworkProtocol(str, StructuredEnum): +class NetworkProtocol(StrEnum): TCP = EnumField("TCP", label="TCP") UDP = EnumField("UDP", label="UDP") -class ExposedTypeName(str, StructuredEnum): +class ExposedTypeName(StrEnum): BK_HTTP = "bk/http" diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py index 072f77ee07..df9509a2cd 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py @@ -16,12 +16,11 @@ # to the current version of the project delivered to anyone in the future. """Domain management""" + from dataclasses import dataclass, field from operator import attrgetter from typing import Dict, List, Optional -from blue_krill.data_types.enum import EnumField, StructuredEnum - from paas_wl.infras.cluster.models import Domain as DomainCfg from paas_wl.infras.cluster.models import IngressConfig, PortMap from paas_wl.infras.cluster.shim import EnvClusterService @@ -29,9 +28,10 @@ from paas_wl.workloads.networking.entrance.utils import to_dns_safe from paasng.platform.applications.models import ModuleEnvironment from paasng.platform.engine.constants import AppEnvName +from paasng.utils.enum import EnumField, IntEnum -class DomainPriorityType(int, StructuredEnum): +class DomainPriorityType(IntEnum): STABLE = EnumField(1, label="无缩写,完整域名") WITHOUT_MODULE = EnumField(2, label="无模块,指向主模块") ONLY_CODE = EnumField(3, label="无模块无环境,指向主模块生产环境") diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py index 2d82305041..5b2279f665 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py @@ -16,11 +16,11 @@ # to the current version of the project delivered to anyone in the future. """Subpaths management""" + from dataclasses import dataclass, field from operator import attrgetter from typing import Dict, List, Optional -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.conf import settings from paas_wl.infras.cluster.models import Domain as DomainCfg @@ -30,9 +30,10 @@ from paas_wl.workloads.networking.entrance.utils import to_dns_safe from paasng.platform.applications.models import ModuleEnvironment from paasng.platform.engine.constants import AppEnvName +from paasng.utils.enum import EnumField, IntEnum -class SubpathPriorityType(int, StructuredEnum): +class SubpathPriorityType(IntEnum): STABLE = EnumField(1, label="无缩写") WITHOUT_MODULE = EnumField(2, label="无模块,指向主模块") ONLY_CODE = EnumField(3, label="无模块无环境,指向主模块生产环境") diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py index 1408c683ad..0631185b7d 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import IntEnum, StrEnum -class AppDomainSource(int, StructuredEnum): +class AppDomainSource(IntEnum): # "BUILT_IN" is reserved for the default ingress's domain, it looks like '{engine_app_name}.apps.com' BUILT_IN = 1 # Auto-generated sub-domains @@ -26,11 +26,11 @@ class AppDomainSource(int, StructuredEnum): INDEPENDENT = 3 -class AppSubpathSource(int, StructuredEnum): +class AppSubpathSource(IntEnum): DEFAULT = 1 -class AddressType(str, StructuredEnum): +class AddressType(StrEnum): """Address types, different value means different source. For example, "custom" means the address was provided by a custom domain created by user. """ diff --git a/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py b/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py index 8d6df30e98..ee71280205 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import IntEnum ANNOT_SERVER_SNIPPET = "nginx.ingress.kubernetes.io/server-snippet" ANNOT_CONFIGURATION_SNIPPET = "nginx.ingress.kubernetes.io/configuration-snippet" @@ -37,7 +37,7 @@ } -class AppDomainSource(int, StructuredEnum): +class AppDomainSource(IntEnum): # "BUILT_IN" is reserved for the default ingress's domain, it looks like '{engine_app_name}.apps.com' BUILT_IN = 1 # Auto-generated sub-domains @@ -45,5 +45,5 @@ class AppDomainSource(int, StructuredEnum): INDEPENDENT = 3 -class AppSubpathSource(int, StructuredEnum): +class AppSubpathSource(IntEnum): DEFAULT = 1 diff --git a/apiserver/paasng/paas_wl/workloads/release_controller/constants.py b/apiserver/paasng/paas_wl/workloads/release_controller/constants.py index e23488a79d..ff16c8e0d1 100644 --- a/apiserver/paasng/paas_wl/workloads/release_controller/constants.py +++ b/apiserver/paasng/paas_wl/workloads/release_controller/constants.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class RuntimeType(str, StructuredEnum): +class RuntimeType(StrEnum): BUILDPACK = EnumField("buildpack", label="Runtime for buildpack") CUSTOM_IMAGE = EnumField("custom_image", label="Custom Image") BK_SMART = EnumField("bk-smart", label="Runtime for buildpack, but build as image") DOCKERFILE = EnumField("dockerfile", label="Runtime for dockerfile") -class ImagePullPolicy(str, StructuredEnum): +class ImagePullPolicy(StrEnum): ALWAYS = EnumField("Always") IF_NOT_PRESENT = EnumField("IfNotPresent") NEVER = EnumField("Never") diff --git a/apiserver/paasng/paasng/accessories/ci/constants.py b/apiserver/paasng/paasng/accessories/ci/constants.py index 4bb0e2db54..c7db3a820a 100644 --- a/apiserver/paasng/paasng/accessories/ci/constants.py +++ b/apiserver/paasng/paasng/accessories/ci/constants.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class CIBackend(str, StructuredEnum): +class CIBackend(StrEnum): CODECC = EnumField("codecc", label="CodeCC") diff --git a/apiserver/paasng/paasng/accessories/cloudapi/constants.py b/apiserver/paasng/paasng/accessories/cloudapi/constants.py index 2c96de1e8d..d600a5c14f 100644 --- a/apiserver/paasng/paasng/accessories/cloudapi/constants.py +++ b/apiserver/paasng/paasng/accessories/cloudapi/constants.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class ApplyStatusEnum(StructuredEnum): +class ApplyStatusEnum(StrEnum): PARTIAL_APPROVED = EnumField("partial_approved", label="部分通过") APPROVED = EnumField("approved", label="通过") REJECTED = EnumField("rejected", label="驳回") PENDING = EnumField("pending", label="待审批") -class PermissionStatusEnum(StructuredEnum): +class PermissionStatusEnum(StrEnum): OWNED = EnumField("owned", label="已拥有") REJECTED = EnumField("rejected", label="已拒绝") EXPIRED = EnumField("expired", label="已过期") @@ -33,24 +33,24 @@ class PermissionStatusEnum(StructuredEnum): NEED_APPLY = EnumField("need_apply", label="未申请") -class PermissionLevelEnum(StructuredEnum): +class PermissionLevelEnum(StrEnum): UNLIMITED = EnumField("unlimited", label="无限制") NORMAL = EnumField("normal", label="普通") SENSITIVE = EnumField("sensitive", label="敏感") SPECIAL = EnumField("special", label="特殊") -class PermissionActionEnum(StructuredEnum): +class PermissionActionEnum(StrEnum): APPLY = EnumField("apply", label="申请") RENEW = EnumField("renew", label="续期") -class PermissionApplyExpireDaysEnum(StructuredEnum): +class PermissionApplyExpireDaysEnum(StrEnum): PERMANENT = EnumField(0, label="永久") SIX_MONTH = EnumField(180, label="6个月") TWELVE_MONTH = EnumField(360, label="12个月") -class GrantDimensionEnum(StructuredEnum): +class GrantDimensionEnum(StrEnum): API = EnumField("api", label="按网关") RESOURCE = EnumField("resource", label="按资源") diff --git a/apiserver/paasng/paasng/accessories/log/constants.py b/apiserver/paasng/paasng/accessories/log/constants.py index f84d2c92e9..14fc1dc8e7 100644 --- a/apiserver/paasng/paasng/accessories/log/constants.py +++ b/apiserver/paasng/paasng/accessories/log/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum # 如果日志配置是所有进程通用的, process_type 填充为 "-" DEFAULT_LOG_CONFIG_PLACEHOLDER = "-" @@ -27,7 +27,7 @@ MAX_RESULT_WINDOW = 10000 -class LogTimeChoices(str, StructuredEnum): +class LogTimeChoices(StrEnum): """日志搜索-日期范围可选值""" FIVE_MINUTES = EnumField("5m", label="5分钟") @@ -41,7 +41,7 @@ class LogTimeChoices(str, StructuredEnum): CUSTOMIZED = EnumField("customized", label="自定义") -class LogType(str, StructuredEnum): +class LogType(StrEnum): """ 日志类型 """ @@ -51,7 +51,7 @@ class LogType(str, StructuredEnum): INGRESS = EnumField("INGRESS", label="接入层日志") -class LogCollectorType(str, StructuredEnum): +class LogCollectorType(StrEnum): """日志采集器类型""" BK_LOG = EnumField("BK_LOG", label="蓝鲸日志平台采集器") diff --git a/apiserver/paasng/paasng/accessories/paas_analysis/constants.py b/apiserver/paasng/paasng/accessories/paas_analysis/constants.py index 1b64a378c8..b470535e93 100644 --- a/apiserver/paasng/paasng/accessories/paas_analysis/constants.py +++ b/apiserver/paasng/paasng/accessories/paas_analysis/constants.py @@ -14,25 +14,25 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class PAMetadataKey(str, StructuredEnum): +class PAMetadataKey(StrEnum): SITE_ID = "bkpa_site_id" -class MetricSourceType(int, StructuredEnum): +class MetricSourceType(IntEnum): INGRESS = EnumField(1, label="ingress") USER_TRACKER = EnumField(2, label="user_tracker") -class MetricsDimensionType(str, StructuredEnum): +class MetricsDimensionType(StrEnum): PATH = EnumField("path", label="path") USER = EnumField("user", label="user") ACTION = EnumField("action", label="action") -class MetricsInterval(str, StructuredEnum): +class MetricsInterval(StrEnum): """Available interval for metrics""" FIVE_MINUTES = EnumField("5m", label="5m") diff --git a/apiserver/paasng/paasng/accessories/publish/market/constant.py b/apiserver/paasng/paasng/accessories/publish/market/constant.py index 4523cc6ba7..5148cb9d52 100644 --- a/apiserver/paasng/paasng/accessories/publish/market/constant.py +++ b/apiserver/paasng/paasng/accessories/publish/market/constant.py @@ -17,13 +17,13 @@ from enum import Enum -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.core.region.states import RegionType +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class ProductSourceUrlType(int, StructuredEnum): +class ProductSourceUrlType(IntEnum): """访问地址类型""" DISABLED = EnumField(1, label="未开启") @@ -63,14 +63,14 @@ def get_choices(cls): TAG_REGION_CHOICES = list(RegionType.get_choices()) + [("all", "所有版本")] -class OpenMode(str, StructuredEnum): +class OpenMode(StrEnum): """应用在桌面的打开方式""" DESKTOP = EnumField(real_value="desktop", label="桌面") NEW_TAB = EnumField(real_value="new_tab", label="新标签页") -class TagName(str, StructuredEnum): +class TagName(StrEnum): """应用分类名称""" OPSTOOlS = EnumField("OpsTools", label=_("运维工具")) diff --git a/apiserver/paasng/paasng/accessories/servicehub/constants.py b/apiserver/paasng/paasng/accessories/servicehub/constants.py index e5974841d0..03f8e208e6 100644 --- a/apiserver/paasng/paasng/accessories/servicehub/constants.py +++ b/apiserver/paasng/paasng/accessories/servicehub/constants.py @@ -16,9 +16,8 @@ # to the current version of the project delivered to anyone in the future. import uuid -from enum import Enum -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import IntEnum, StrEnum # 需要在平台侧完全隐藏的字段名称,用户无法在产品上查看该字段内容,只能通过环境变量查看 SERVICE_SENSITIVE_FIELDS: dict = {} @@ -42,19 +41,19 @@ ) -class Category(int, Enum): +class Category(IntEnum): """Paas service categories""" DATA_STORAGE = 1 MONITORING_HEALTHY = 2 -class ServiceType(str, StructuredEnum): +class ServiceType(StrEnum): LOCAL = "local" REMOTE = "remote" -class ServiceBindingType(int, Enum): +class ServiceBindingType(IntEnum): """Type of service binding relationship""" NORMAL = 1 diff --git a/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py b/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py index aad78cf2ee..d5557323b1 100644 --- a/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py +++ b/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py @@ -14,8 +14,7 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. - -from enum import IntEnum +from paasng.utils.enum import IntEnum class MySQLAuthTypeEnum(IntEnum): diff --git a/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py b/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py index 7aac464d78..346c76f572 100644 --- a/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, IntEnum -class PluginTagIdType(int, StructuredEnum): +class PluginTagIdType(IntEnum): UNTAGGED = EnumField(-1, label="未分类") diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py index d65b3f4ec9..62d7436385 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class PipelineBuildStatus(str, StructuredEnum): +class PipelineBuildStatus(StrEnum): """蓝盾流水线构建状态""" # 由于蓝盾接口文档未提供所有枚举值, 因此这里只列举目前已知的状态 diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py index 1daa88d257..589cd70482 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py @@ -15,11 +15,12 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class PluginReleaseMethod(str, StructuredEnum): + +class PluginReleaseMethod(StrEnum): """插件发布方式""" CODE = EnumField("code", label="源码发布") @@ -27,14 +28,14 @@ class PluginReleaseMethod(str, StructuredEnum): IMAGE = EnumField("image", label="镜像发布") -class PluginBasicInfoAccessMode(str, StructuredEnum): +class PluginBasicInfoAccessMode(StrEnum): """插件基本信息查看模式""" READONLY = EnumField("readonly", label="只读") READWRITE = EnumField("readwrite", label="读写") -class PluginReleaseVersionRule(str, StructuredEnum): +class PluginReleaseVersionRule(StrEnum): """插件发布版本号规则""" AUTOMATIC = EnumField("automatic", label="自动生成 semver") @@ -44,7 +45,7 @@ class PluginReleaseVersionRule(str, StructuredEnum): SELF_FILL = EnumField("self-fill", label="用户自助填写") -class SemverAutomaticType(str, StructuredEnum): +class SemverAutomaticType(StrEnum): """语义化版本生成规则""" MAJOR = EnumField("major", label="重大版本") @@ -52,7 +53,7 @@ class SemverAutomaticType(str, StructuredEnum): PATCH = EnumField("patch", label="修正版本") -class ReleaseStageInvokeMethod(str, StructuredEnum): +class ReleaseStageInvokeMethod(StrEnum): """发布步骤触发方式""" DEPLOY_API = EnumField("deployAPI", label="部署接口") @@ -63,7 +64,7 @@ class ReleaseStageInvokeMethod(str, StructuredEnum): BUILTIN = EnumField("builtin", label="内置功能(完善市场信息market, 灰度grayScale, 上线online)") -class PluginStatus(str, StructuredEnum): +class PluginStatus(StrEnum): """插件状态""" WAITING_APPROVAL = EnumField("waiting-approval", label="创建审批中") @@ -84,14 +85,14 @@ def approval_status(cls): return [cls.APPROVAL_FAILED, cls.WAITING_APPROVAL] -class PluginRole(int, StructuredEnum): +class PluginRole(IntEnum): """插件角色""" ADMINISTRATOR = EnumField(2, label="管理员") DEVELOPER = EnumField(3, label="开发者") -class MarketInfoStorageType(str, StructuredEnum): +class MarketInfoStorageType(StrEnum): """市场信息存储类型""" THIRD_PARTY = EnumField("third-party", label="仅存储在第三方系统") @@ -99,7 +100,7 @@ class MarketInfoStorageType(str, StructuredEnum): BOTH = EnumField("both", label="同时存储在插件开发中心和第三方系统") -class PluginReleaseStatus(str, StructuredEnum): +class PluginReleaseStatus(StrEnum): """插件发布状态""" SUCCESSFUL = EnumField("successful", label="成功") @@ -121,7 +122,7 @@ def terminated_status(cls): return [cls.FAILED, cls.INTERRUPTED, cls.SUCCESSFUL] -class LogTimeChoices(str, StructuredEnum): +class LogTimeChoices(StrEnum): """日志搜索-日期范围可选值""" FIVE_MINUTES = EnumField("5m", label="5分钟") @@ -135,7 +136,7 @@ class LogTimeChoices(str, StructuredEnum): CUSTOMIZED = EnumField("customized", label="自定义") -class ActionTypes(str, StructuredEnum): +class ActionTypes(StrEnum): """操作记录-动作类型""" CREATE = EnumField("create", label=_("创建")) @@ -149,7 +150,7 @@ class ActionTypes(str, StructuredEnum): ROLLBACK = EnumField("rollback", label=_("回滚")) -class SubjectTypes(str, StructuredEnum): +class SubjectTypes(StrEnum): """操作记录-主体""" PLUGIN = EnumField("plugin", label=_("插件")) @@ -164,28 +165,28 @@ class SubjectTypes(str, StructuredEnum): RELEASE_STRATEGY = EnumField("release_strategy", label=_("发布策略")) -class PluginReleaseType(str, StructuredEnum): +class PluginReleaseType(StrEnum): """插件版本发布类型""" PROD = EnumField("prod", label=_("正式发布")) TEST = EnumField("test", label=_("测试发布")) -class ReleaseStrategy(str, StructuredEnum): +class ReleaseStrategy(StrEnum): """插件发布策略""" GRAY = EnumField("gray", label=_("灰度发布")) FULL = EnumField("full", label=_("全量发布")) -class StatusPollingMethod(str, StructuredEnum): +class StatusPollingMethod(StrEnum): """发布阶段的状态轮询方式""" API = EnumField("api", label=_("后台 API 轮询")) FRONTEND = EnumField("frontend", label=_("前端轮询,如通过 Iframe message 通信等")) -class PluginRevisionType(str, StructuredEnum): +class PluginRevisionType(StrEnum): """代码版本类型""" ALL = EnumField("all", label=_("不限制")) @@ -194,7 +195,7 @@ class PluginRevisionType(str, StructuredEnum): TESTED_VERSION = EnumField("tested_version", label=_("已经测试通过的版本")) -class GrayReleaseStatus(str, StructuredEnum): +class GrayReleaseStatus(StrEnum): """插件灰度发布展示的状态,提供给前端展示的字段不需要国际化标记""" GRAY_APPROVAL_IN_PROGRESS = EnumField("gray_approval_in_progress", label="灰度发布审批中") diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py index 3d69b0f932..a8f7547e84 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py @@ -17,10 +17,10 @@ from typing import List -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.bk_plugins.pluginscenter.constants import PluginRole +from paasng.utils.enum import EnumField, StrEnum # 永不过期的时间(伪,其实是 2100.01.01 08:00:00,与权限中心保持一致) NEVER_EXPIRE_TIMESTAMP = 4102444800 @@ -41,7 +41,7 @@ NEVER_EXPIRE_DAYS = -1 -class PluginPermissionActions(str, StructuredEnum): +class PluginPermissionActions(StrEnum): """插件相关的操作权限""" BASIC_DEVELOPMENT = EnumField("basic_development", label=_("基础开发")) @@ -75,5 +75,5 @@ def get_choices_by_role(cls, role: PluginRole) -> List["PluginPermissionActions" raise NotImplementedError -class ResourceType(str, StructuredEnum): +class ResourceType(StrEnum): PLUGIN = EnumField("plugin", label=_("蓝鲸插件")) diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py index 4dfdbbfbbd..060360f3e1 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py @@ -15,11 +15,12 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class ApprovalServiceName(str, StructuredEnum): + +class ApprovalServiceName(StrEnum): """审批流程服务名""" CREATE_APPROVAL = EnumField("create_approval", label=_("插件上线审批")) @@ -35,7 +36,7 @@ class ApprovalServiceName(str, StructuredEnum): ) -class ItsmTicketStatus(str, StructuredEnum): +class ItsmTicketStatus(StrEnum): """ITSM 流程状态""" RUNNING = EnumField("RUNNING", label=_("处理中")) diff --git a/apiserver/paasng/paasng/infras/accounts/permissions/constants.py b/apiserver/paasng/paasng/infras/accounts/permissions/constants.py index 16cac8e04e..e37a982398 100644 --- a/apiserver/paasng/paasng/infras/accounts/permissions/constants.py +++ b/apiserver/paasng/paasng/infras/accounts/permissions/constants.py @@ -15,11 +15,12 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class SiteAction(str, StructuredEnum): + +class SiteAction(StrEnum): """蓝鲸 PaaS 平台全局功能相关权限""" VISIT_SITE = EnumField("visit_site", label=_("平台页面查看")) diff --git a/apiserver/paasng/paasng/infras/bk_ci/constants.py b/apiserver/paasng/paasng/infras/bk_ci/constants.py index c15298cfd1..5f1be5b59e 100644 --- a/apiserver/paasng/paasng/infras/bk_ci/constants.py +++ b/apiserver/paasng/paasng/infras/bk_ci/constants.py @@ -15,11 +15,12 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class PipelineBuildStatus(str, StructuredEnum): + +class PipelineBuildStatus(StrEnum): """蓝盾流水线构建状态""" SUCCEED = EnumField("SUCCEED", label=_("成功")) diff --git a/apiserver/paasng/paasng/infras/bk_log/constatns.py b/apiserver/paasng/paasng/infras/bk_log/constatns.py index 6612d552c8..6c77d8801f 100644 --- a/apiserver/paasng/paasng/infras/bk_log/constatns.py +++ b/apiserver/paasng/paasng/infras/bk_log/constatns.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class ETLType(str, StructuredEnum): +class ETLType(StrEnum): DELIMITER = EnumField("bk_log_delimiter") REGEXP = EnumField("bk_log_regexp") JSON = EnumField("bk_log_json") TEXT = EnumField("bk_log_text") -class FieldType(str, StructuredEnum): +class FieldType(StrEnum): INT = EnumField("int") LONG = EnumField("long") DOUBLE = EnumField("double") @@ -34,6 +34,6 @@ class FieldType(str, StructuredEnum): NESTED = EnumField("nested") -class BkLogType(str, StructuredEnum): +class BkLogType(StrEnum): JSON = EnumField("json") STDOUT = EnumField("stdout") diff --git a/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py b/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py index 17bbc92d2f..8ae3c9ce9f 100644 --- a/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py +++ b/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py @@ -15,10 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class SpaceType(str, StructuredEnum): + +class SpaceType(StrEnum): SAAS = EnumField("bksaas", label=_("蓝鲸应用")) BKCC = EnumField("bkcc", label=_("业务")) diff --git a/apiserver/paasng/paasng/infras/iam/constants.py b/apiserver/paasng/paasng/infras/iam/constants.py index 655442a6b6..ed00331dc6 100644 --- a/apiserver/paasng/paasng/infras/iam/constants.py +++ b/apiserver/paasng/paasng/infras/iam/constants.py @@ -15,9 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum - from paasng.platform.applications.constants import ApplicationRole +from paasng.utils.enum import IntEnum, StrEnum # 使用 -1 表示永不过期 NEVER_EXPIRE_DAYS = -1 @@ -41,7 +40,7 @@ LIST_GRADE_MANAGERS_LIMIT = 15000 -class ResourceType(str, StructuredEnum): +class ResourceType(StrEnum): """ iam 上注册的资源类型 """ @@ -61,7 +60,7 @@ class ResourceType(str, StructuredEnum): BkLogEsSource = "es_source" -class IAMErrorCodes(int, StructuredEnum): +class IAMErrorCodes(IntEnum): """ iam api 返回错误码 https://bk.tencent.com/docs/document/7.0/236/39801 diff --git a/apiserver/paasng/paasng/infras/iam/legacy.py b/apiserver/paasng/paasng/infras/iam/legacy.py index d2c197afea..b0bbb9bfc6 100644 --- a/apiserver/paasng/paasng/infras/iam/legacy.py +++ b/apiserver/paasng/paasng/infras/iam/legacy.py @@ -18,16 +18,17 @@ # PaaS 2.0 相关权限 import logging -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.conf import settings from iam import IAM, Action, Request, Subject from iam.contrib.converter.sql import SQLConverter from iam.exceptions import AuthAPIError +from paasng.utils.enum import EnumField, StrEnum + logger = logging.getLogger(__name__) -class LegacyAction(str, StructuredEnum): +class LegacyAction(StrEnum): DEVELOP_APP = EnumField("develop_app", label="开发 SaaS 应用及外链应用") MANAGE_SMART = EnumField("manage_smart", label="管理 S-mart 应用") diff --git a/apiserver/paasng/paasng/infras/iam/open_apis/constants.py b/apiserver/paasng/paasng/infras/iam/open_apis/constants.py index d846736645..23a76012cb 100644 --- a/apiserver/paasng/paasng/infras/iam/open_apis/constants.py +++ b/apiserver/paasng/paasng/infras/iam/open_apis/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import StrEnum -class MethodType(str, StructuredEnum): +class MethodType(StrEnum): """ 权限中心拉取资源的 method 参数值 字段协议说明 https://bk.tencent.com/docs/document/6.0/160/8427?r=1 diff --git a/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py b/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py index 45dae4137a..5c9df950d3 100644 --- a/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py +++ b/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py @@ -21,7 +21,6 @@ from attrs import define, field, validators from bkpaas_auth.core.encoder import user_id_encoder -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.conf import settings from django.db.models import Q from django.utils.translation import gettext_lazy as _ @@ -30,11 +29,12 @@ from paasng.infras.iam.constants import ResourceType from paasng.infras.iam.permissions.perm import PermCtx, Permission, ResCreatorAction, validate_empty from paasng.infras.iam.permissions.request import ResourceRequest +from paasng.utils.enum import EnumField, StrEnum logger = logging.getLogger(__name__) -class AppAction(str, StructuredEnum): +class AppAction(StrEnum): """蓝鲸 PaaS 应用相关权限""" # 应用基础信息查看 diff --git a/apiserver/paasng/paasng/misc/audit/constants.py b/apiserver/paasng/paasng/misc/audit/constants.py index 519be9744c..2756f9cef0 100644 --- a/apiserver/paasng/paasng/misc/audit/constants.py +++ b/apiserver/paasng/paasng/misc/audit/constants.py @@ -15,18 +15,19 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class AccessType(int, StructuredEnum): + +class AccessType(IntEnum): """访问方式""" WEB = EnumField(0, label=_("网页")) API = EnumField(1, label="API") -class ResultCode(int, StructuredEnum): +class ResultCode(IntEnum): """操作结果""" SUCCESS = EnumField(0, label=_("成功")) @@ -39,7 +40,7 @@ def get_terminated_codes(cls): return [cls.SUCCESS, cls.FAILURE, cls.INTERRUPT] -class DataType(str, StructuredEnum): +class DataType(StrEnum): """记录操作前后数据的数据类型,前端会根据该字段做不同的展示 前端不需要展示相关的 label, 故不用做国际化标记 """ @@ -54,7 +55,7 @@ class DataType(str, StructuredEnum): ) -class OperationTarget(str, StructuredEnum): +class OperationTarget(StrEnum): """操作对象""" APP = EnumField("app", label=_("应用")) @@ -92,7 +93,7 @@ class OperationTarget(str, StructuredEnum): SLUGRUNNER = EnumField("slugrunner", label="Slugrunner") -class OperationEnum(str, StructuredEnum): +class OperationEnum(StrEnum): """操作类型""" CREATE = EnumField("create", label=_("新建")) diff --git a/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py b/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py index 61b71a77bd..4027f2f3ac 100644 --- a/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py +++ b/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py @@ -15,16 +15,16 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum -class MetricsSeriesType(str, StructuredEnum): +class MetricsSeriesType(StrEnum): CURRENT = EnumField("current", "使用量") REQUEST = EnumField("request", "保留量") LIMIT = EnumField("limit", "配额上限") -class MetricsResourceType(str, StructuredEnum): +class MetricsResourceType(StrEnum): MEM = EnumField("mem") CPU = EnumField("cpu") @@ -41,7 +41,8 @@ def choices(cls): "current": "sum by(container_name)(container_memory_working_set_bytes{{" 'pod_name="{instance_name}", container_name!="POD", cluster_id="{cluster_id}"}})', # 内存预留值 - "request": 'kube_pod_container_resource_requests_memory_bytes{{pod="{instance_name}", cluster_id="{cluster_id}"}}', + "request": "kube_pod_container_resource_requests_memory_bytes" + + '{{pod="{instance_name}", cluster_id="{cluster_id}"}}', # 内存上限值 "limit": 'kube_pod_container_resource_limits_memory_bytes{{pod="{instance_name}", cluster_id="{cluster_id}"}}', }, diff --git a/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py b/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py index 9fdcac4086..4572b006db 100644 --- a/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py +++ b/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import StrEnum -class AlertCode(str, StructuredEnum): +class AlertCode(StrEnum): HIGH_CPU_USAGE = "high_cpu_usage" HIGH_MEM_USAGE = "high_mem_usage" POD_RESTART = "pod_restart" diff --git a/apiserver/paasng/paasng/plat_admin/numbers/app.py b/apiserver/paasng/paasng/plat_admin/numbers/app.py index b04de5c864..c50085cafc 100644 --- a/apiserver/paasng/paasng/plat_admin/numbers/app.py +++ b/apiserver/paasng/paasng/plat_admin/numbers/app.py @@ -23,7 +23,6 @@ from collections import Counter, defaultdict from dataclasses import dataclass from datetime import date, datetime, timedelta -from enum import IntEnum from functools import lru_cache, reduce from typing import Any, Collection, Dict, Generator, Iterable, List, Optional, Set, Tuple, Type, Union, cast @@ -50,6 +49,7 @@ from paasng.platform.sourcectl.repo_controller import BaseGitRepoController from paasng.platform.sourcectl.source_types import get_sourcectl_names, get_sourcectl_type from paasng.platform.sourcectl.svn.server_config import get_bksvn_config +from paasng.utils.enum import IntEnum try: from paasng.infras.legacydb_te.models import LApplication, LApplicationUseRecord diff --git a/apiserver/paasng/paasng/plat_admin/system/constants.py b/apiserver/paasng/paasng/plat_admin/system/constants.py index cf780ea838..4cc617326d 100644 --- a/apiserver/paasng/paasng/plat_admin/system/constants.py +++ b/apiserver/paasng/paasng/plat_admin/system/constants.py @@ -14,8 +14,7 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. - -from enum import IntEnum +from paasng.utils.enum import IntEnum class SimpleAppSource(IntEnum): diff --git a/apiserver/paasng/paasng/platform/applications/constants.py b/apiserver/paasng/paasng/platform/applications/constants.py index 7013ac72c6..8ab43aa721 100644 --- a/apiserver/paasng/paasng/platform/applications/constants.py +++ b/apiserver/paasng/paasng/platform/applications/constants.py @@ -17,11 +17,13 @@ from typing import Type -from blue_krill.data_types.enum import EnumField, FeatureFlag, FeatureFlagField, StructuredEnum +from blue_krill.data_types.enum import FeatureFlag, FeatureFlagField from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, IntEnum, StrEnum -class ApplicationType(str, StructuredEnum): + +class ApplicationType(StrEnum): DEFAULT = EnumField("default", label="普通应用") # 默认类型:无任何定制逻辑 ENGINELESS_APP = EnumField( "engineless_app", label="外链应用" @@ -31,7 +33,7 @@ class ApplicationType(str, StructuredEnum): CLOUD_NATIVE = EnumField("cloud_native", label="云原生应用") -class ApplicationRole(int, StructuredEnum): +class ApplicationRole(IntEnum): NOBODY = EnumField(-1, label="无身份用户") COLLABORATOR = EnumField(1, label="协作者") ADMINISTRATOR = EnumField(2, label="管理员") @@ -39,7 +41,7 @@ class ApplicationRole(int, StructuredEnum): OPERATOR = EnumField(4, label="运营") @classmethod - def get_roles(cls: Type[StructuredEnum]): + def get_roles(cls: Type[IntEnum]): return [ {"id": role.value, "name": role.name.lower()} for role in cls @@ -47,7 +49,7 @@ def get_roles(cls: Type[StructuredEnum]): ] -class AppLanguage(str, StructuredEnum): +class AppLanguage(StrEnum): PYTHON = EnumField("Python", label="Python") PHP = EnumField("PHP", label="PHP") GO = EnumField("Go", label="Go") @@ -74,7 +76,7 @@ def __str__(self): } -class AppEnvironment(str, StructuredEnum): +class AppEnvironment(StrEnum): STAGING = EnumField("stag", label="预发布环境") PRODUCTION = EnumField("prod", label="生产环境") @@ -102,7 +104,7 @@ class AppFeatureFlag(FeatureFlag): # type: ignore ENABLE_PERSISTENT_STORAGE = FeatureFlagField(label=_("开启持久存储挂载卷"), default=False) -class LightApplicationViewSetErrorCode(str, StructuredEnum): +class LightApplicationViewSetErrorCode(StrEnum): SUCCESS = 0 PARAM_NOT_VALID = 1301100 CREATE_APP_ERROR = 1301101 diff --git a/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py b/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py index c127a240ea..f3d84a9036 100644 --- a/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py +++ b/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py @@ -17,18 +17,18 @@ import logging -from blue_krill.data_types.enum import StructuredEnum from django.core.management.base import BaseCommand from paasng.accessories.publish.sync_market.managers import AppManger from paasng.core.core.storages.sqlalchemy import console_db from paasng.infras.iam.helpers import delete_builtin_user_groups, delete_grade_manager from paasng.platform.applications.models import Application +from paasng.utils.enum import StrEnum logger = logging.getLogger(__name__) -class DelKeyType(str, StructuredEnum): +class DelKeyType(StrEnum): """Source origin defines the origin of module's source code""" CODE = "code" diff --git a/apiserver/paasng/paasng/platform/bkapp_model/constants.py b/apiserver/paasng/paasng/platform/bkapp_model/constants.py index bdf8e840a7..c0fcacb483 100644 --- a/apiserver/paasng/paasng/platform/bkapp_model/constants.py +++ b/apiserver/paasng/paasng/platform/bkapp_model/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, StrEnum # legacy: Slug runner 默认的 entrypoint, 平台所有 slug runner 镜像都以该值作为入口 # TODO: 需验证存量所有镜像是否都设置了默认的 entrypoint, 如是, 即可移除所有 DEFAULT_SLUG_RUNNER_ENTRYPOINT @@ -25,7 +25,7 @@ PORT_PLACEHOLDER = "${PORT}" -class ExposedTypeName(str, StructuredEnum): +class ExposedTypeName(StrEnum): """与 paas_wl.workloads.networking.constants.ExposedTypeName 重复定义 # TODO 将 paasng 和 paas_wl 中重复定义的一些常量, 合并放到更底层的模块中, 避免破坏当前 importlinter 的依赖规则? """ @@ -33,7 +33,7 @@ class ExposedTypeName(str, StructuredEnum): BK_HTTP = "bk/http" -class NetworkProtocol(str, StructuredEnum): +class NetworkProtocol(StrEnum): """与 paas_wl.workloads.networking.constants.NetworkProtocol 重复定义 # TODO 将 paasng 和 paas_wl 中重复定义的一些常量, 合并放到更底层的模块中, 避免破坏当前 importlinter 的依赖规则? """ @@ -42,7 +42,7 @@ class NetworkProtocol(str, StructuredEnum): UDP = EnumField("UDP", label="UDP") -class ImagePullPolicy(str, StructuredEnum): +class ImagePullPolicy(StrEnum): """duplicated from paas_wl.workloads.release_controller.constants.ImagePullPolicy to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ @@ -52,7 +52,7 @@ class ImagePullPolicy(str, StructuredEnum): NEVER = EnumField("Never") -class ResQuotaPlan(str, StructuredEnum): +class ResQuotaPlan(StrEnum): """duplicated from paas_wl.bk_app.cnative.specs.constants.ResQuotaPlan to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ @@ -69,7 +69,7 @@ class ResQuotaPlan(str, StructuredEnum): __str__ = str.__str__ -class ScalingPolicy(str, StructuredEnum): +class ScalingPolicy(StrEnum): """duplicated from paas_wl.bk_app.cnative.specs.constants.ScalingPolicy to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ diff --git a/apiserver/paasng/paasng/platform/bkapp_model/utils.py b/apiserver/paasng/paasng/platform/bkapp_model/utils.py index f7d95b06c8..6c50dcc8d9 100644 --- a/apiserver/paasng/paasng/platform/bkapp_model/utils.py +++ b/apiserver/paasng/paasng/platform/bkapp_model/utils.py @@ -17,17 +17,16 @@ import copy from typing import List, Optional, Tuple -from blue_krill.data_types.enum import StructuredEnum - from paas_wl.bk_app.cnative.specs.crd.bk_app import EnvVar, EnvVarOverlay from paasng.platform.applications.constants import ApplicationType from paasng.platform.engine.configurations.image import generate_image_repository from paasng.platform.engine.constants import RuntimeType from paasng.platform.modules.helpers import ModuleRuntimeManager from paasng.platform.modules.models import BuildConfig, Module +from paasng.utils.enum import StrEnum -class MergeStrategy(str, StructuredEnum): +class MergeStrategy(StrEnum): """Different strategy when merging env vars""" OVERRIDE = "Override" diff --git a/apiserver/paasng/paasng/platform/declarative/constants.py b/apiserver/paasng/paasng/platform/declarative/constants.py index 4436b13870..a70f8282f9 100644 --- a/apiserver/paasng/paasng/platform/declarative/constants.py +++ b/apiserver/paasng/paasng/platform/declarative/constants.py @@ -17,7 +17,7 @@ from typing import Any, TypeVar -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, IntEnum, StrEnum T = TypeVar("T") @@ -43,7 +43,7 @@ def dict(self, *args, **kwargs): OMITTED_VALUE = OmittedType() -class AppSpecVersion(StructuredEnum): +class AppSpecVersion(IntEnum): # VER_1 meaning app.yaml is provided by S-Mart App VER_1 = 1 VER_2 = 2 @@ -51,12 +51,12 @@ class AppSpecVersion(StructuredEnum): VER_3 = 3 -class AppDescPluginType(str, StructuredEnum): +class AppDescPluginType(StrEnum): APP_VERSION = EnumField("app_version", label="应用版本") APP_LIBRARIES = EnumField("app_libraries", label="应用依赖库") -class DiffType(str, StructuredEnum): +class DiffType(StrEnum): ADDED = EnumField("added", label="新增") DELETED = EnumField("deleted", label="删除") NOT_MODIFIED = EnumField("not_modified", label="未改动") diff --git a/apiserver/paasng/paasng/platform/engine/constants.py b/apiserver/paasng/paasng/platform/engine/constants.py index 62a4bb325b..dd3137b642 100644 --- a/apiserver/paasng/paasng/platform/engine/constants.py +++ b/apiserver/paasng/paasng/platform/engine/constants.py @@ -17,31 +17,31 @@ from typing import List -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.utils.basic import ChoicesEnum +from paasng.utils.enum import EnumField, StrEnum PROC_DEFAULT_REPLICAS = 1 DOCKER_BUILD_STEPSET_NAME = "docker-build" IMAGE_RELEASE_STEPSET_NAME = "image-release" -class ClusterType(str, StructuredEnum): +class ClusterType(StrEnum): """集群类别""" NORMAL = EnumField("normal", label=_("普通集群")) VIRTUAL = EnumField("virtual", label=_("虚拟集群")) -class AppEnvName(str, StructuredEnum): +class AppEnvName(StrEnum): """The default environment names""" STAG = EnumField("stag", label=_("预发布环境")) PROD = EnumField("prod", label=_("生产环境")) -class JobStatus(str, StructuredEnum): +class JobStatus(StrEnum): SUCCESSFUL = EnumField("successful", label="成功") FAILED = EnumField("failed", label="失败") PENDING = EnumField("pending", label="等待") @@ -53,7 +53,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class BuildStatus(str, StructuredEnum): +class BuildStatus(StrEnum): """While `BuildStatus` has same members with `JobStatus`, different statuses might be added in the future""" SUCCESSFUL = "successful" @@ -67,7 +67,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class ReleaseStatus(str, StructuredEnum): +class ReleaseStatus(StrEnum): """While `ReleaseStatus` has same members with `JobStatus`, different statuses might be added in the future""" SUCCESSFUL = "successful" @@ -109,7 +109,7 @@ class MetricsType(ChoicesEnum): _choices_labels = ((MEM, "mem"), (CPU, "cpu"), (__ALL__, "__all__")) -class ConfigVarEnvName(str, StructuredEnum): +class ConfigVarEnvName(StrEnum): """Environment name for managing config var""" STAG = EnumField("stag", label="仅测试环境") @@ -141,20 +141,20 @@ class DeployConditions(ChoicesEnum): ) -class RuntimeType(str, StructuredEnum): +class RuntimeType(StrEnum): BUILDPACK = EnumField("buildpack", label=_("使用 Buildpacks 构建")) DOCKERFILE = EnumField("dockerfile", label=_("使用 Dockerfile 构建")) CUSTOM_IMAGE = EnumField("custom_image", label="Custom Image(云原生和旧镜像应用)") -class AppInfoBuiltinEnv(str, StructuredEnum): +class AppInfoBuiltinEnv(StrEnum): """应用基本信息的内置环境变量built-in""" APP_ID = EnumField("APP_ID", label=_("蓝鲸应用ID")) APP_SECRET = EnumField("APP_SECRET", label=_("蓝鲸应用密钥")) -class AppRunTimeBuiltinEnv(str, StructuredEnum): +class AppRunTimeBuiltinEnv(StrEnum): """Built-in envs in the app runtime""" APP_MODULE_NAME = EnumField("APP_MODULE_NAME", label=_("应用当前模块名")) diff --git a/apiserver/paasng/paasng/platform/engine/models/phases.py b/apiserver/paasng/paasng/platform/engine/models/phases.py index 85d953625f..335c635fb0 100644 --- a/apiserver/paasng/paasng/platform/engine/models/phases.py +++ b/apiserver/paasng/paasng/platform/engine/models/phases.py @@ -17,7 +17,6 @@ from typing import TYPE_CHECKING, Dict -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.db import models from django.utils.translation import gettext_lazy as _ @@ -26,13 +25,14 @@ from paasng.platform.engine.constants import JobStatus from paasng.platform.engine.exceptions import DuplicateNameInSamePhaseError, StepNotInPresetListError from paasng.platform.engine.models import Deployment, EngineApp, MarkStatusMixin +from paasng.utils.enum import EnumField, StrEnum from paasng.utils.models import UuidAuditedModel if TYPE_CHECKING: from paasng.platform.engine.models.steps import DeployStep -class DeployPhaseTypes(str, StructuredEnum): +class DeployPhaseTypes(StrEnum): """部署阶段""" PREPARATION = EnumField("preparation", label=_("准备阶段")) diff --git a/apiserver/paasng/paasng/platform/engine/processes/events.py b/apiserver/paasng/paasng/platform/engine/processes/events.py index 882520209c..d3807e14e7 100644 --- a/apiserver/paasng/paasng/platform/engine/processes/events.py +++ b/apiserver/paasng/paasng/platform/engine/processes/events.py @@ -16,13 +16,14 @@ # to the current version of the project delivered to anyone in the future. """Process events related functions""" + import logging from dataclasses import dataclass -from enum import IntEnum from typing import Any, Dict, Iterator, List, Tuple from paas_wl.bk_app.processes.processes import PlainInstance, PlainProcess from paasng.platform.engine.processes.utils import diff_list +from paasng.utils.enum import IntEnum logger = logging.getLogger(__name__) diff --git a/apiserver/paasng/paasng/platform/engine/utils/output.py b/apiserver/paasng/paasng/platform/engine/utils/output.py index 3b4c583b6c..1a8459361a 100644 --- a/apiserver/paasng/paasng/platform/engine/utils/output.py +++ b/apiserver/paasng/paasng/platform/engine/utils/output.py @@ -17,7 +17,6 @@ import abc import json import sys -from enum import Enum from typing import Optional, Protocol from blue_krill.redis_tools.messaging import StreamChannel @@ -26,6 +25,7 @@ from paasng.core.core.storages.redisdb import get_default_redis from paasng.platform.engine.models import Deployment from paasng.utils import termcolors +from paasng.utils.enum import StrEnum def make_style(*args, **kwargs): @@ -67,7 +67,7 @@ class Style: White = make_style(fg="white", opts=("bold",)) -class StreamType(str, Enum): +class StreamType(StrEnum): STDOUT = "STDOUT" STDERR = "STDERR" diff --git a/apiserver/paasng/paasng/platform/evaluation/constants.py b/apiserver/paasng/paasng/platform/evaluation/constants.py index 3e1ffad489..4ccf6e1b15 100644 --- a/apiserver/paasng/paasng/platform/evaluation/constants.py +++ b/apiserver/paasng/paasng/platform/evaluation/constants.py @@ -15,31 +15,32 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class BatchTaskStatus(str, StructuredEnum): + +class BatchTaskStatus(StrEnum): """任务状态""" RUNNING = EnumField("running", label=_("运行中")) FINISHED = EnumField("finished", label=_("已完成")) -class EmailNotificationType(str, StructuredEnum): +class EmailNotificationType(StrEnum): """邮件通知类型""" IDLE_APP_MODULE_ENVS = EnumField("idle_app_module_envs", label=_("闲置应用模块")) -class EmailReceiverType(str, StructuredEnum): +class EmailReceiverType(StrEnum): """邮件接收者类型""" PLAT_ADMIN = EnumField("plat_admin", label=_("平台管理员")) APP_DEVELOPER = EnumField("app_developer", label=_("应用开发者")) -class OperationIssueType(str, StructuredEnum): +class OperationIssueType(StrEnum): """应用运营问题类型""" NONE = EnumField("none", label=_("无")) diff --git a/apiserver/paasng/paasng/platform/mgrlegacy/constants.py b/apiserver/paasng/paasng/platform/mgrlegacy/constants.py index 6db8b1ad02..73ea1a5493 100644 --- a/apiserver/paasng/paasng/platform/mgrlegacy/constants.py +++ b/apiserver/paasng/paasng/platform/mgrlegacy/constants.py @@ -17,9 +17,8 @@ from dataclasses import dataclass -from blue_krill.data_types.enum import StructuredEnum - from paasng.utils.basic import ChoicesEnum +from paasng.utils.enum import StrEnum class MigrationStatus(ChoicesEnum): @@ -121,7 +120,7 @@ class AppMember: role: int -class CNativeMigrationStatus(str, StructuredEnum): +class CNativeMigrationStatus(StrEnum): DEFAULT = "default" ON_MIGRATION = "on_migration" MIGRATION_SUCCEEDED = "migration_succeeded" diff --git a/apiserver/paasng/paasng/platform/modules/constants.py b/apiserver/paasng/paasng/platform/modules/constants.py index 43f8228d13..f6e5b16a2b 100644 --- a/apiserver/paasng/paasng/platform/modules/constants.py +++ b/apiserver/paasng/paasng/platform/modules/constants.py @@ -15,15 +15,14 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from enum import Enum, IntEnum from typing import Dict, List -from blue_krill.data_types.enum import EnumField, StructuredEnum +from paasng.utils.enum import EnumField, IntEnum, StrEnum DEFAULT_ENGINE_APP_PREFIX = "bkapp" -class ModuleName(str, Enum): +class ModuleName(StrEnum): DEFAULT = "default" @@ -34,7 +33,7 @@ class ExposedURLType(IntEnum): SUBDOMAIN = 2 -class SourceOrigin(int, StructuredEnum): +class SourceOrigin(IntEnum): """Source origin defines the origin of module's source code""" AUTHORIZED_VCS = EnumField(1, "Authorized VCS") @@ -58,7 +57,7 @@ def get_package_origins(cls) -> List["SourceOrigin"]: return [SourceOrigin.BK_LESS_CODE, SourceOrigin.S_MART, SourceOrigin.AI_AGENT] -class APP_CATEGORY(str, StructuredEnum): +class APP_CATEGORY(StrEnum): """Application category, used when setting label to images""" NORMAL_APP = "normal_app" @@ -67,7 +66,7 @@ class APP_CATEGORY(str, StructuredEnum): LEGACY_APP = "legacy_app" -class DeployHookType(str, StructuredEnum): +class DeployHookType(StrEnum): """DeployHook Type""" PRE_RELEASE_HOOK = EnumField("pre-release-hook", label="部署前置钩子") @@ -80,7 +79,7 @@ def _missing_(cls, value): return super()._missing_(value) -class BuildPackType(str, StructuredEnum): +class BuildPackType(StrEnum): # legacy heroku buildpack format, just a tarball TAR = EnumField("tar", label="tar") @@ -102,7 +101,7 @@ def get_buildpack_builder_type_map(cls) -> Dict["BuildPackType", "AppImageType"] } -class AppImageType(str, StructuredEnum): +class AppImageType(StrEnum): LEGACY = EnumField("legacy", label="legacy") CNB = EnumField("cnb", label="cnb") diff --git a/apiserver/paasng/paasng/platform/sourcectl/client.py b/apiserver/paasng/paasng/platform/sourcectl/client.py index f7f7dedb54..b54d810780 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/client.py +++ b/apiserver/paasng/paasng/platform/sourcectl/client.py @@ -21,13 +21,13 @@ from typing import Any, Dict, Generator, List, Optional import requests -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ from oauthlib.oauth2.rfc6749.errors import OAuth2Error from paasng.infras.accounts.models import Oauth2TokenHolder from paasng.platform.sourcectl import exceptions from paasng.platform.sourcectl.models import GitProject +from paasng.utils.enum import EnumField, StrEnum logger = logging.getLogger(__name__) @@ -43,7 +43,7 @@ RETRY_TIME = 3 -class GitRepoProvider(str, StructuredEnum): +class GitRepoProvider(StrEnum): """Git 仓库服务提供方""" GitHub = EnumField("github", label="GitHub") @@ -70,7 +70,7 @@ def __init__(self, api_url: str, **kwargs): raise exceptions.AccessTokenMissingError("oauth_token required") self.session.headers.update(headers) - self.__token_holder: Oauth2TokenHolder = kwargs.get("__token_holder", None) + self.__token_holder: Optional[Oauth2TokenHolder] = kwargs.get("__token_holder") @abc.abstractmethod def list_repo(self, **kwargs) -> List[Dict]: diff --git a/apiserver/paasng/paasng/platform/sourcectl/constants.py b/apiserver/paasng/paasng/platform/sourcectl/constants.py index 02b88aaad8..5589da505f 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/constants.py +++ b/apiserver/paasng/paasng/platform/sourcectl/constants.py @@ -14,20 +14,20 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. - -from blue_krill.data_types.enum import EnumField, FeatureFlagField, StructuredEnum +from blue_krill.data_types.enum import FeatureFlagField from paasng.infras.accounts.constants import AccountFeatureFlag +from paasng.utils.enum import EnumField, StrEnum -class DiffFeatureType(str, StructuredEnum): +class DiffFeatureType(StrEnum): """代码对比类型""" INTERNAL = "internal" EXTERNAL = "external" -class BasicSourceType(str, StructuredEnum): +class BasicSourceType(StrEnum): """基础源码类型""" GIT = "git" @@ -44,7 +44,7 @@ def register_new_sourcectl_type(feature_flag: FeatureFlagField): AccountFeatureFlag.register_ext_feature_flag(feature_flag) -class VersionType(str, StructuredEnum): +class VersionType(StrEnum): """版本类型. 对应 VersionInfo.version_type""" TAG = EnumField("tag", label="用于 Git 仓库、云原生镜像应用、旧镜像应用、镜像模式的 S-Mart 应用") diff --git a/apiserver/paasng/paasng/platform/templates/constants.py b/apiserver/paasng/paasng/platform/templates/constants.py index ef5813774b..7a06189803 100644 --- a/apiserver/paasng/paasng/platform/templates/constants.py +++ b/apiserver/paasng/paasng/platform/templates/constants.py @@ -15,11 +15,12 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StructuredEnum from django.utils.translation import gettext_lazy as _ +from paasng.utils.enum import EnumField, StrEnum -class TemplateType(str, StructuredEnum): + +class TemplateType(StrEnum): """模板类型""" NORMAL = EnumField("normal", _("普通应用")) diff --git a/apiserver/paasng/paasng/utils/blobstore.py b/apiserver/paasng/paasng/utils/blobstore.py index b2212d48b5..d448b0a81c 100644 --- a/apiserver/paasng/paasng/utils/blobstore.py +++ b/apiserver/paasng/paasng/utils/blobstore.py @@ -27,7 +27,6 @@ import boto3 from bkstorages.backends.bkrepo import BKRepoStorage from bkstorages.backends.rgw import RGWBoto3Storage -from blue_krill.data_types.enum import EnumField, StructuredEnum from blue_krill.storages.blobstore.base import BlobStore from blue_krill.storages.blobstore.bkrepo import BKGenericRepo from blue_krill.storages.blobstore.s3 import S3Store @@ -36,10 +35,12 @@ from django.conf import settings from django.utils.encoding import force_bytes, force_text +from paasng.utils.enum import EnumField, StrEnum + logger = logging.getLogger(__name__) -class StoreType(str, StructuredEnum): +class StoreType(StrEnum): S3 = EnumField("s3") BKREPO = EnumField("bkrepo") # 向前兼容, 支持 http/https 协议 diff --git a/apiserver/paasng/paasng/utils/enum.py b/apiserver/paasng/paasng/utils/enum.py new file mode 100644 index 0000000000..416a4ba34a --- /dev/null +++ b/apiserver/paasng/paasng/utils/enum.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# TencentBlueKing is pleased to support the open source community by making +# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available. +# Copyright (C) 2017 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. +# +# We undertake not to change the open source license (MIT license) applicable +# to the current version of the project delivered to anyone in the future. + +# Q: 为什么需要这个包,而不是之前直接从 blue_krill 引入的方式? +# A: Python 3.11 中改变了枚举类的一些行为,且 blue_krill 不好做兼容,因此先由 apiserver 自行处理: +# https://github.com/python/cpython/issues/100458 +# + +# Q: 为什么这里 import EnumField 且忽略 F401 +# A: 统一枚举 import 入口,避免业务逻辑中需要从 utils.enum & blue_krill 中分别导入 +from blue_krill.data_types.enum import ( + EnumField, # noqa: F401 + StructuredEnum, +) + + +class StrEnum(str, StructuredEnum): + """Py3.11+ 中替换 (str, StructuredEnum) 的枚举基类""" + + __str__ = str.__str__ + + +class IntEnum(int, StructuredEnum): + """Py3.11+ 中替换 (int. StructuredEnum) 的枚举基类""" + + def __str__(self): + return "{}".format(self.value) diff --git a/apiserver/paasng/paasng/utils/patternmatcher.py b/apiserver/paasng/paasng/utils/patternmatcher.py index c840d78c41..62861f8bb3 100644 --- a/apiserver/paasng/paasng/utils/patternmatcher.py +++ b/apiserver/paasng/paasng/utils/patternmatcher.py @@ -21,10 +21,10 @@ from dataclasses import dataclass from typing import Optional -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import IntEnum -class MatchType(int, StructuredEnum): +class MatchType(IntEnum): Unknown = 0 Excat = 1 Prefix = 2 diff --git a/apiserver/paasng/paasng/utils/rate_limit/constants.py b/apiserver/paasng/paasng/utils/rate_limit/constants.py index a8a0b07422..fb34699d62 100644 --- a/apiserver/paasng/paasng/utils/rate_limit/constants.py +++ b/apiserver/paasng/paasng/utils/rate_limit/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import StructuredEnum +from paasng.utils.enum import IntEnum -class UserAction(int, StructuredEnum): +class UserAction(IntEnum): """ 用于频率限制的用户操作 From 12907a88b71719550f706f94919713bff2a0a782 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 14 Oct 2024 16:08:29 +0800 Subject: [PATCH 11/16] fix: add AccessTokenHolderError --- apiserver/paasng/paasng/platform/sourcectl/exceptions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apiserver/paasng/paasng/platform/sourcectl/exceptions.py b/apiserver/paasng/paasng/platform/sourcectl/exceptions.py index a5d8ed05dc..1306eb9999 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/exceptions.py +++ b/apiserver/paasng/paasng/platform/sourcectl/exceptions.py @@ -45,6 +45,10 @@ class AccessTokenError(Exception): """access token 校验失败""" +class AccessTokenHolderError(Exception): + """token holder 异常(如:未提供)""" + + class RequestError(Exception): """请求异常""" From 80221bbd6cbff1cbe6e1ff859a89aa7b625c9cbb Mon Sep 17 00:00:00 2001 From: narasux Date: Tue, 15 Oct 2024 12:07:55 +0800 Subject: [PATCH 12/16] fix: update enum classes --- apiserver/paasng/paasng/infras/accounts/constants.py | 4 ++++ apiserver/paasng/paasng/platform/environments/constants.py | 5 +++-- apiserver/paasng/paasng/utils/enum.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apiserver/paasng/paasng/infras/accounts/constants.py b/apiserver/paasng/paasng/infras/accounts/constants.py index 0e7c73e587..6043e93ac0 100644 --- a/apiserver/paasng/paasng/infras/accounts/constants.py +++ b/apiserver/paasng/paasng/infras/accounts/constants.py @@ -93,6 +93,10 @@ def get_default_flags(cls) -> Dict[str, bool]: def register_ext_feature_flag(cls, feature_flag: FeatureFlagField) -> None: """注册额外的用户特性到枚举类中""" name, label, default = feature_flag.name, feature_flag.label, feature_flag.default + # 无名的不允许注册 + if not name: + raise ValueError("feature flag's name can not be empty.") + # 已经注册过的,需要跳过 if getattr(cls, name, None): return diff --git a/apiserver/paasng/paasng/platform/environments/constants.py b/apiserver/paasng/paasng/platform/environments/constants.py index ad9964db7c..a65f5e7179 100644 --- a/apiserver/paasng/paasng/platform/environments/constants.py +++ b/apiserver/paasng/paasng/platform/environments/constants.py @@ -14,6 +14,7 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from typing import List from paasng.platform.applications.constants import ApplicationRole from paasng.utils.basic import ChoicesEnum @@ -29,5 +30,5 @@ class EnvRoleOperation(ChoicesEnum): } @classmethod - def get_default_role(cls, operation: str): - return cls.__default.value[operation] + def get_default_role(cls, operation: str) -> List[int]: + return cls.__default[operation] # type: ignore diff --git a/apiserver/paasng/paasng/utils/enum.py b/apiserver/paasng/paasng/utils/enum.py index 416a4ba34a..b1d84d7bbf 100644 --- a/apiserver/paasng/paasng/utils/enum.py +++ b/apiserver/paasng/paasng/utils/enum.py @@ -18,7 +18,7 @@ # Q: 为什么需要这个包,而不是之前直接从 blue_krill 引入的方式? # A: Python 3.11 中改变了枚举类的一些行为,且 blue_krill 不好做兼容,因此先由 apiserver 自行处理: # https://github.com/python/cpython/issues/100458 -# +# https://github.com/TencentBlueKing/bkpaas-python-sdk/issues/190 # Q: 为什么这里 import EnumField 且忽略 F401 # A: 统一枚举 import 入口,避免业务逻辑中需要从 utils.enum & blue_krill 中分别导入 From 251747d24075df9c3e88236a77794a4b12a1ce9d Mon Sep 17 00:00:00 2001 From: narasux Date: Thu, 17 Oct 2024 10:17:16 +0800 Subject: [PATCH 13/16] fix: resolve #1655 conversations --- apiserver/Dockerfile | 3 ++- .../dev_utils/unittest/Dockerfile.devops.unittest | 3 ++- .../paasng/paas_wl/bk_app/cnative/specs/constants.py | 12 ------------ apiserver/paasng/paasng/accessories/log/client.py | 5 +++-- .../paasng/paasng/platform/bkapp_model/constants.py | 12 ------------ .../paasng/paasng/platform/sourcectl/constants.py | 1 - 6 files changed, 7 insertions(+), 29 deletions(-) diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index 6265f07a56..6f016d0969 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -27,6 +27,8 @@ USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git +RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf + ENV LC_ALL=C.UTF-8 \ LANG=C.UTF-8 @@ -54,7 +56,6 @@ RUN mkdir -p ./public COPY --from=admin42 /build/paasng/public ./public ADD ./paasng . - # Add extra files: static assets & I18N .mo translation file. # "gettext" package is required for running "compilemessages" diff --git a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest index 096ee0134b..342f1d44bc 100644 --- a/apiserver/dev_utils/unittest/Dockerfile.devops.unittest +++ b/apiserver/dev_utils/unittest/Dockerfile.devops.unittest @@ -27,6 +27,8 @@ USER root RUN apt-get update && apt-get install -y gcc subversion ssh default-libmysqlclient-dev pkg-config vim git +RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.cloud.tencent.com/pypi/simple/\n' > ~/.pip/pip.conf + ENV LC_ALL=C.UTF-8 \ LANG=C.UTF-8 @@ -45,7 +47,6 @@ ADD ./poetry.lock . RUN poetry config virtualenvs.create false && poetry install - WORKDIR /app ADD ./paasng ./paasng RUN mkdir -p ./public diff --git a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py index f6c0d98cb1..74e039d8e3 100644 --- a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py @@ -128,12 +128,6 @@ class ScalingPolicy(StrEnum): # the default autoscaling policy (cpu utilization 85%) DEFAULT = EnumField("default") - # simulate `ReprEnum` behavior to work well with DRF serializer - # see also: - # - https://docs.python.org/3/library/enum.html#enum.ReprEnum - # - https://docs.python.org/3/library/enum.html#enum.Enum.__str__ - __str__ = str.__str__ - class ResQuotaPlan(StrEnum): """ResQuotaPlan is used to specify process resource quota""" @@ -143,12 +137,6 @@ class ResQuotaPlan(StrEnum): P_4C2G = EnumField("4C2G", label="4C2G") P_4C4G = EnumField("4C4G", label="4C4G") - # simulate `ReprEnum` behavior to work well with DRF serializer - # see also: - # - https://docs.python.org/3/library/enum.html#enum.ReprEnum - # - https://docs.python.org/3/library/enum.html#enum.Enum.__str__ - __str__ = str.__str__ - class MountEnvName(StrEnum): """Environment name for managing mount volume""" diff --git a/apiserver/paasng/paasng/accessories/log/client.py b/apiserver/paasng/paasng/accessories/log/client.py index 4b39eedb1e..bce2ffd0aa 100644 --- a/apiserver/paasng/paasng/accessories/log/client.py +++ b/apiserver/paasng/paasng/accessories/log/client.py @@ -106,7 +106,7 @@ def execute_scroll_search( resp = self._call_api(self._esclient.esquery_dsl, data=data, timeout=timeout) if not resp["result"]: - # 有可能是 scroll id 失效了, 反正抛异常就对了 + # API 返回异常可能原因:scroll 失效,这里统一返回 ScanError,如果为空则设置为 none 防止类型异常 scroll_id = scroll_id or "none" raise ScanError(scroll_id, "Scroll request has failed on `{}`".format(resp["message"])) @@ -222,9 +222,10 @@ def execute_scroll_search( ), ) if not response.success(): + # API 返回异常可能原因:scroll 失效,这里统一返回 ScanError,如果为空则设置为 none 防止类型异常 + scroll_id = scroll_id or "none" failed = response._shards.failed total = response._shards.total - scroll_id = scroll_id or "none" raise ScanError( scroll_id, "Scroll request has failed on %d shards out of %d." % (failed, total), diff --git a/apiserver/paasng/paasng/platform/bkapp_model/constants.py b/apiserver/paasng/paasng/platform/bkapp_model/constants.py index c0fcacb483..1782c3f8bb 100644 --- a/apiserver/paasng/paasng/platform/bkapp_model/constants.py +++ b/apiserver/paasng/paasng/platform/bkapp_model/constants.py @@ -62,12 +62,6 @@ class ResQuotaPlan(StrEnum): P_4C2G = EnumField("4C2G", label="4C2G") P_4C4G = EnumField("4C4G", label="4C4G") - # simulate `ReprEnum` behavior to work well with DRF serializer - # see also: - # - https://docs.python.org/3/library/enum.html#enum.ReprEnum - # - https://docs.python.org/3/library/enum.html#enum.Enum.__str__ - __str__ = str.__str__ - class ScalingPolicy(StrEnum): """duplicated from paas_wl.bk_app.cnative.specs.constants.ScalingPolicy to decouple dependencies @@ -76,9 +70,3 @@ class ScalingPolicy(StrEnum): # the default autoscaling policy (cpu utilization 85%) DEFAULT = EnumField("default") - - # simulate `ReprEnum` behavior to work well with DRF serializer - # see also: - # - https://docs.python.org/3/library/enum.html#enum.ReprEnum - # - https://docs.python.org/3/library/enum.html#enum.Enum.__str__ - __str__ = str.__str__ diff --git a/apiserver/paasng/paasng/platform/sourcectl/constants.py b/apiserver/paasng/paasng/platform/sourcectl/constants.py index 5589da505f..9549eea827 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/constants.py +++ b/apiserver/paasng/paasng/platform/sourcectl/constants.py @@ -38,7 +38,6 @@ class BasicSourceType(StrEnum): def register_new_sourcectl_type(feature_flag: FeatureFlagField): """暴露给 TE 版本的注册 SourcectlType 的方法 - :param name: 源码类型名称 :param feature_flag: 用于控制该源码系统的黑/白名单 """ AccountFeatureFlag.register_ext_feature_flag(feature_flag) From 7a75f138e4a648ebee4b01404ac209f68def1ad4 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 21 Oct 2024 11:56:22 +0800 Subject: [PATCH 14/16] feat: update blue_krill to 2.0.7 --- .../paas_wl/bk_app/applications/constants.py | 6 +-- .../paas_wl/bk_app/cnative/specs/constants.py | 25 ++++++----- .../paas_wl/bk_app/dev_sandbox/entities.py | 5 ++- .../bk_app/monitoring/bklog/constants.py | 4 +- .../paas_wl/bk_app/processes/constants.py | 8 ++-- .../paas_wl/infras/cluster/constants.py | 8 ++-- .../infras/resource_templates/constants.py | 4 +- apiserver/paasng/paas_wl/utils/blobstore.py | 5 +-- apiserver/paasng/paas_wl/utils/constants.py | 11 ++--- apiserver/paasng/paas_wl/utils/kubestatus.py | 5 +-- .../workloads/autoscaling/constants.py | 13 +++--- .../paas_wl/workloads/networking/constants.py | 6 +-- .../networking/entrance/allocator/domains.py | 5 ++- .../networking/entrance/allocator/subpaths.py | 4 +- .../networking/entrance/constants.py | 8 ++-- .../workloads/networking/ingress/constants.py | 6 +-- .../workloads/release_controller/constants.py | 6 +-- .../paasng/paasng/accessories/ci/constants.py | 4 +- .../paasng/accessories/cloudapi/constants.py | 14 +++---- .../paasng/accessories/log/constants.py | 8 ++-- .../accessories/paas_analysis/constants.py | 10 ++--- .../accessories/publish/market/constant.py | 8 ++-- .../accessories/servicehub/constants.py | 8 ++-- .../services/providers/mysql/constants.py | 4 +- .../paasng/bk_plugins/bk_plugins/constants.py | 4 +- .../pluginscenter/bk_devops/constants.py | 4 +- .../bk_plugins/pluginscenter/constants.py | 37 ++++++++--------- .../pluginscenter/iam_adaptor/constants.py | 6 +-- .../pluginscenter/itsm_adaptor/constants.py | 7 ++-- .../infras/accounts/permissions/constants.py | 5 +-- .../paasng/paasng/infras/bk_ci/constants.py | 5 +-- .../paasng/paasng/infras/bk_log/constatns.py | 8 ++-- .../paasng/infras/bkmonitorv3/constants.py | 5 +-- .../paasng/paasng/infras/iam/constants.py | 7 ++-- apiserver/paasng/paasng/infras/iam/legacy.py | 5 +-- .../paasng/infras/iam/open_apis/constants.py | 4 +- .../iam/permissions/resources/application.py | 4 +- .../paasng/paasng/misc/audit/constants.py | 13 +++--- .../misc/monitoring/metrics/constants.py | 6 +-- .../monitor/alert_rules/config/entities.py | 4 +- .../paasng/paasng/misc/operations/models.py | 2 +- .../paasng/paasng/plat_admin/numbers/app.py | 4 +- .../paasng/plat_admin/system/constants.py | 4 +- .../paasng/platform/applications/constants.py | 16 ++++---- .../management/commands/force_del_app.py | 4 +- .../paasng/platform/bkapp_model/constants.py | 12 +++--- .../paasng/platform/bkapp_model/utils.py | 5 ++- .../paasng/platform/declarative/constants.py | 8 ++-- .../paasng/platform/engine/constants.py | 20 ++++----- .../paasng/platform/engine/models/phases.py | 4 +- .../platform/engine/processes/events.py | 9 ++-- .../paasng/platform/engine/utils/output.py | 4 +- .../paasng/platform/evaluation/constants.py | 11 +++-- .../paasng/platform/mgrlegacy/constants.py | 5 ++- .../paasng/platform/modules/constants.py | 16 ++++---- .../paasng/platform/sourcectl/client.py | 4 +- .../paasng/platform/sourcectl/constants.py | 9 ++-- .../paasng/platform/templates/constants.py | 5 +-- apiserver/paasng/paasng/utils/blobstore.py | 5 +-- apiserver/paasng/paasng/utils/enum.py | 41 ------------------- .../paasng/paasng/utils/patternmatcher.py | 4 +- .../paasng/utils/rate_limit/constants.py | 4 +- apiserver/poetry.lock | 8 ++-- apiserver/pyproject.toml | 2 +- 64 files changed, 231 insertions(+), 284 deletions(-) delete mode 100644 apiserver/paasng/paasng/utils/enum.py diff --git a/apiserver/paasng/paas_wl/bk_app/applications/constants.py b/apiserver/paasng/paas_wl/bk_app/applications/constants.py index d4f34b3536..55dda7edf4 100644 --- a/apiserver/paasng/paas_wl/bk_app/applications/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/applications/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class WlAppType(StrEnum): +class WlAppType(StrStructuredEnum): """type of workloads app""" DEFAULT = EnumField("default") # 默认类型:无任何定制逻辑 @@ -28,7 +28,7 @@ class WlAppType(StrEnum): CLOUD_NATIVE = EnumField("cloud_native") -class ArtifactType(StrEnum): +class ArtifactType(StrStructuredEnum): """type of build artifact""" SLUG = EnumField("slug") diff --git a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py index 74e039d8e3..1141e816ce 100644 --- a/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/cnative/specs/constants.py @@ -15,10 +15,9 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - # Default resource limitations for each process DEFAULT_PROC_CPU = "4000m" DEFAULT_PROC_MEM = "1024Mi" @@ -67,14 +66,14 @@ PROC_SERVICES_ENABLED_ANNOTATION_KEY = "bkapp.paas.bk.tencent.com/proc-services-feature-enabled" -class ApiVersion(StrEnum): +class ApiVersion(StrStructuredEnum): """Kubernetes CRD API versions""" V1ALPHA1 = "paas.bk.tencent.com/v1alpha1" V1ALPHA2 = "paas.bk.tencent.com/v1alpha2" -class DeployStatus(StrEnum): +class DeployStatus(StrStructuredEnum): """Cloud-native app's deployment statuses""" PENDING = EnumField("pending", label=_("待实施")) @@ -91,7 +90,7 @@ def is_stable(cls, val: "DeployStatus") -> bool: return val in [DeployStatus.READY, DeployStatus.ERROR] -class DomainGroupSource(StrEnum): +class DomainGroupSource(StrStructuredEnum): """The source types for DomainGroup data""" SUBDOMAIN = "subdomain" @@ -99,14 +98,14 @@ class DomainGroupSource(StrEnum): CUSTOM = "custom" -class MResConditionType(StrEnum): +class MResConditionType(StrStructuredEnum): APP_AVAILABLE = EnumField("AppAvailable") APP_PROGRESSING = EnumField("AppProgressing") ADDONS_PROVISIONED = EnumField("AddOnsProvisioned") HOOKS_FINISHED = EnumField("HooksFinished") -class ConditionStatus(StrEnum): +class ConditionStatus(StrStructuredEnum): """k8s metav1.ConditionStatus""" TRUE = EnumField("True") @@ -114,7 +113,7 @@ class ConditionStatus(StrEnum): UNKNOWN = EnumField("Unknown") -class MResPhaseType(StrEnum): +class MResPhaseType(StrStructuredEnum): """a label for the condition of a BkApp at the current time.""" AppPending = EnumField("Pending") @@ -122,14 +121,14 @@ class MResPhaseType(StrEnum): AppFailed = EnumField("Failed") -class ScalingPolicy(StrEnum): +class ScalingPolicy(StrStructuredEnum): """ScalingPolicy is used to specify which policy should be used while scaling""" # the default autoscaling policy (cpu utilization 85%) DEFAULT = EnumField("default") -class ResQuotaPlan(StrEnum): +class ResQuotaPlan(StrStructuredEnum): """ResQuotaPlan is used to specify process resource quota""" P_DEFAULT = EnumField("default", label="default") @@ -138,7 +137,7 @@ class ResQuotaPlan(StrEnum): P_4C4G = EnumField("4C4G", label="4C4G") -class MountEnvName(StrEnum): +class MountEnvName(StrStructuredEnum): """Environment name for managing mount volume""" STAG = EnumField("stag", label="仅测试环境") @@ -146,12 +145,12 @@ class MountEnvName(StrEnum): GLOBAL = EnumField("_global_", label="所有环境") -class VolumeSourceType(StrEnum): +class VolumeSourceType(StrStructuredEnum): ConfigMap = EnumField("ConfigMap") PersistentStorage = EnumField("PersistentStorage") -class PersistentStorageSize(StrEnum): +class PersistentStorageSize(StrStructuredEnum): P_1G = EnumField("1Gi") P_2G = EnumField("2Gi") P_4G = EnumField("4Gi") diff --git a/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py b/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py index 531f6018f7..88a52b4fee 100644 --- a/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py +++ b/apiserver/paasng/paas_wl/bk_app/dev_sandbox/entities.py @@ -18,11 +18,12 @@ from dataclasses import dataclass, field from typing import Dict, List, Optional +from blue_krill.data_types.enum import EnumField, StrStructuredEnum + from paas_wl.workloads.release_controller.constants import ImagePullPolicy -from paasng.utils.enum import EnumField, StrEnum -class HealthPhase(StrEnum): +class HealthPhase(StrStructuredEnum): HEALTHY = EnumField("Healthy") PROGRESSING = EnumField("Progressing") UNHEALTHY = EnumField("Unhealthy") diff --git a/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py b/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py index 2ac237dbfb..1b3dbc0c9d 100644 --- a/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/monitoring/bklog/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum # 注解或标签中存储应用名称的键名 BKAPP_NAME_ANNO_KEY = "bkapp.paas.bk.tencent.com/name" @@ -29,7 +29,7 @@ WLAPP_NAME_ANNO_KEY = "bkapp.paas.bk.tencent.com/wl-app-name" -class BkLogConfigType(StrEnum): +class BkLogConfigType(StrStructuredEnum): STD_LOG = EnumField("std_log_config", label="标准输出日志") CONTAINER_LOG = EnumField("container_log_config", label="容器日志") NODE_LOG = EnumField("node_log_config", label="节点日志") diff --git a/apiserver/paasng/paas_wl/bk_app/processes/constants.py b/apiserver/paasng/paas_wl/bk_app/processes/constants.py index 3a8c41464d..fc140d0810 100644 --- a/apiserver/paasng/paas_wl/bk_app/processes/constants.py +++ b/apiserver/paasng/paas_wl/bk_app/processes/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum # 注解或标签中存储进程名称的键名 PROCESS_NAME_KEY = "bkapp.paas.bk.tencent.com/process-name" @@ -26,7 +26,7 @@ DEFAULT_CNATIVE_MAX_REPLICAS = 10 -class ProcessUpdateType(StrEnum): +class ProcessUpdateType(StrStructuredEnum): """Type of updating processes""" START = EnumField("start") @@ -35,14 +35,14 @@ class ProcessUpdateType(StrEnum): SCALE = EnumField("scale") -class ProcessTargetStatus(StrEnum): +class ProcessTargetStatus(StrStructuredEnum): """Choices of process status""" START = EnumField("start") STOP = EnumField("stop") -class ProbeType(StrEnum): +class ProbeType(StrStructuredEnum): """Choices of probe type""" READINESS = EnumField("readiness", label="readinessProbe") diff --git a/apiserver/paasng/paas_wl/infras/cluster/constants.py b/apiserver/paasng/paas_wl/infras/cluster/constants.py index 736a700d29..13252f5173 100644 --- a/apiserver/paasng/paas_wl/infras/cluster/constants.py +++ b/apiserver/paasng/paas_wl/infras/cluster/constants.py @@ -17,18 +17,16 @@ from typing import Dict -from blue_krill.data_types.enum import FeatureFlag, FeatureFlagField +from blue_krill.data_types.enum import EnumField, FeatureFlag, FeatureFlagField, IntStructuredEnum, StrStructuredEnum from django.conf import settings from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, IntEnum, StrEnum - -class ClusterTokenType(IntEnum): +class ClusterTokenType(IntStructuredEnum): SERVICE_ACCOUNT = 1 -class ClusterType(StrEnum): +class ClusterType(StrStructuredEnum): """集群类别""" NORMAL = EnumField("normal", label=_("普通集群")) diff --git a/apiserver/paasng/paas_wl/infras/resource_templates/constants.py b/apiserver/paasng/paas_wl/infras/resource_templates/constants.py index 49dffc00dd..64012cda32 100644 --- a/apiserver/paasng/paas_wl/infras/resource_templates/constants.py +++ b/apiserver/paasng/paas_wl/infras/resource_templates/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, IntEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum -class AppAddOnType(IntEnum): +class AppAddOnType(IntStructuredEnum): SIMPLE_SIDECAR = EnumField(1, label="SideCar Container") READINESS_PROBE = EnumField(2, label="Readiness Probe") VOLUME_MOUNT = EnumField(3, label="Volume Mount Point") diff --git a/apiserver/paasng/paas_wl/utils/blobstore.py b/apiserver/paasng/paas_wl/utils/blobstore.py index 39e45e9cfb..aeb327b8d0 100644 --- a/apiserver/paasng/paas_wl/utils/blobstore.py +++ b/apiserver/paasng/paas_wl/utils/blobstore.py @@ -20,17 +20,16 @@ import logging from typing import Optional +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from blue_krill.storages.blobstore.base import BlobStore from blue_krill.storages.blobstore.bkrepo import BKGenericRepo from blue_krill.storages.blobstore.s3 import S3Store from django.conf import settings -from paasng.utils.enum import EnumField, StrEnum - logger = logging.getLogger(__name__) -class StoreType(StrEnum): +class StoreType(StrStructuredEnum): S3 = EnumField("s3") BKREPO = EnumField("bkrepo") diff --git a/apiserver/paasng/paas_wl/utils/constants.py b/apiserver/paasng/paas_wl/utils/constants.py index 2017873622..939a97902e 100644 --- a/apiserver/paasng/paas_wl/utils/constants.py +++ b/apiserver/paasng/paas_wl/utils/constants.py @@ -17,11 +17,12 @@ from typing import List +from blue_krill.data_types.enum import EnumField, StrStructuredEnum + from paasng.platform.engine.constants import JobStatus -from paasng.utils.enum import EnumField, StrEnum -class BuildStatus(StrEnum): +class BuildStatus(StrStructuredEnum): SUCCESSFUL = EnumField("successful", "成功") FAILED = EnumField("failed", "失败") PENDING = EnumField("pending", "等待") @@ -33,7 +34,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class CommandStatus(StrEnum): +class CommandStatus(StrStructuredEnum): SCHEDULED = EnumField("scheduled", label="已调度") SUCCESSFUL = EnumField("successful", "成功") FAILED = EnumField("failed", "失败") @@ -54,7 +55,7 @@ def to_job_status(self) -> JobStatus: return JobStatus(self.value) -class CommandType(StrEnum): +class CommandType(StrStructuredEnum): PRE_RELEASE_HOOK = EnumField("pre-release-hook", label="发布前置指令") def get_step_name(self): @@ -76,7 +77,7 @@ def make_enum_choices(obj): return [(member.value, name) for name, member in obj.__members__.items()] -class PodPhase(StrEnum): +class PodPhase(StrStructuredEnum): SUCCEEDED = EnumField("Succeeded", "成功") FAILED = EnumField("Failed", "失败") RUNNING = EnumField("Running", "运行中") diff --git a/apiserver/paasng/paas_wl/utils/kubestatus.py b/apiserver/paasng/paas_wl/utils/kubestatus.py index f2a83c1e29..f76d393a3e 100644 --- a/apiserver/paasng/paas_wl/utils/kubestatus.py +++ b/apiserver/paasng/paas_wl/utils/kubestatus.py @@ -20,14 +20,13 @@ import kubernetes.client.models as kmodels from attrs import define +from blue_krill.data_types.enum import StrStructuredEnum from blue_krill.text import remove_prefix from kubernetes.client import ApiClient from kubernetes.dynamic.resource import ResourceField, ResourceInstance -from paasng.utils.enum import StrEnum - -class HealthStatusType(StrEnum): +class HealthStatusType(StrStructuredEnum): HEALTHY = "Healthy" UNHEALTHY = "Unhealthy" PROGRESSING = "progressing" diff --git a/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py b/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py index 4da50ae686..aafc4ec994 100644 --- a/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py +++ b/apiserver/paasng/paas_wl/workloads/autoscaling/constants.py @@ -15,23 +15,22 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext as _ -from paasng.utils.enum import EnumField, StrEnum - # 添加注解 compute-by-limits=true 后,CPU 计算 Utilization 时 # 将根据当前使用量 & limits 来计算目标副本数,否则默认使用 requests 来计算 GPA_COMPUTE_BY_LIMITS_ANNO_KEY = "compute-by-limits" -class ScalingMetricName(StrEnum): +class ScalingMetricName(StrStructuredEnum): """扩缩容指标名称(用于组装 CPA 的指标)""" CPU = EnumField("cpu") MEMORY = EnumField("memory") -class ScalingMetricSourceType(StrEnum): +class ScalingMetricSourceType(StrStructuredEnum): """扩缩容指标类型""" RESOURCE = EnumField("Resource") @@ -39,14 +38,14 @@ class ScalingMetricSourceType(StrEnum): OBJECT = EnumField("Object") -class ScalingMetricTargetType(StrEnum): +class ScalingMetricTargetType(StrStructuredEnum): """扩缩容指标计量类型(用于组装 CPA 的指标类型)""" UTILIZATION = EnumField("Utilization") AVERAGE_VALUE = EnumField("AverageValue") -class ScalingEnvName(StrEnum): +class ScalingEnvName(StrStructuredEnum): """扩缩容生效环境""" STAG = EnumField("stag", label="仅测试环境") @@ -54,7 +53,7 @@ class ScalingEnvName(StrEnum): GLOBAL = EnumField("_global_", label="所有环境") -class ScalingMetric(StrEnum): +class ScalingMetric(StrStructuredEnum): """扩缩容指标(用户可选指标)""" CPU_UTILIZATION = EnumField("cpuUtilization", label=_("CPU 使用率")) diff --git a/apiserver/paasng/paas_wl/workloads/networking/constants.py b/apiserver/paasng/paas_wl/workloads/networking/constants.py index e7f3d85722..ad0114aebd 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/constants.py @@ -14,13 +14,13 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class NetworkProtocol(StrEnum): +class NetworkProtocol(StrStructuredEnum): TCP = EnumField("TCP", label="TCP") UDP = EnumField("UDP", label="UDP") -class ExposedTypeName(StrEnum): +class ExposedTypeName(StrStructuredEnum): BK_HTTP = "bk/http" diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py index df9509a2cd..4ab966a441 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/domains.py @@ -21,6 +21,8 @@ from operator import attrgetter from typing import Dict, List, Optional +from blue_krill.data_types.enum import EnumField, IntStructuredEnum + from paas_wl.infras.cluster.models import Domain as DomainCfg from paas_wl.infras.cluster.models import IngressConfig, PortMap from paas_wl.infras.cluster.shim import EnvClusterService @@ -28,10 +30,9 @@ from paas_wl.workloads.networking.entrance.utils import to_dns_safe from paasng.platform.applications.models import ModuleEnvironment from paasng.platform.engine.constants import AppEnvName -from paasng.utils.enum import EnumField, IntEnum -class DomainPriorityType(IntEnum): +class DomainPriorityType(IntStructuredEnum): STABLE = EnumField(1, label="无缩写,完整域名") WITHOUT_MODULE = EnumField(2, label="无模块,指向主模块") ONLY_CODE = EnumField(3, label="无模块无环境,指向主模块生产环境") diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py index 5b2279f665..012ae65d32 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/allocator/subpaths.py @@ -21,6 +21,7 @@ from operator import attrgetter from typing import Dict, List, Optional +from blue_krill.data_types.enum import EnumField, IntStructuredEnum from django.conf import settings from paas_wl.infras.cluster.models import Domain as DomainCfg @@ -30,10 +31,9 @@ from paas_wl.workloads.networking.entrance.utils import to_dns_safe from paasng.platform.applications.models import ModuleEnvironment from paasng.platform.engine.constants import AppEnvName -from paasng.utils.enum import EnumField, IntEnum -class SubpathPriorityType(IntEnum): +class SubpathPriorityType(IntStructuredEnum): STABLE = EnumField(1, label="无缩写") WITHOUT_MODULE = EnumField(2, label="无模块,指向主模块") ONLY_CODE = EnumField(3, label="无模块无环境,指向主模块生产环境") diff --git a/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py b/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py index 0631185b7d..41f39b0e8e 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/entrance/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import IntEnum, StrEnum +from blue_krill.data_types.enum import IntStructuredEnum, StrStructuredEnum -class AppDomainSource(IntEnum): +class AppDomainSource(IntStructuredEnum): # "BUILT_IN" is reserved for the default ingress's domain, it looks like '{engine_app_name}.apps.com' BUILT_IN = 1 # Auto-generated sub-domains @@ -26,11 +26,11 @@ class AppDomainSource(IntEnum): INDEPENDENT = 3 -class AppSubpathSource(IntEnum): +class AppSubpathSource(IntStructuredEnum): DEFAULT = 1 -class AddressType(StrEnum): +class AddressType(StrStructuredEnum): """Address types, different value means different source. For example, "custom" means the address was provided by a custom domain created by user. """ diff --git a/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py b/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py index ee71280205..5127427cee 100644 --- a/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py +++ b/apiserver/paasng/paas_wl/workloads/networking/ingress/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import IntEnum +from blue_krill.data_types.enum import IntStructuredEnum ANNOT_SERVER_SNIPPET = "nginx.ingress.kubernetes.io/server-snippet" ANNOT_CONFIGURATION_SNIPPET = "nginx.ingress.kubernetes.io/configuration-snippet" @@ -37,7 +37,7 @@ } -class AppDomainSource(IntEnum): +class AppDomainSource(IntStructuredEnum): # "BUILT_IN" is reserved for the default ingress's domain, it looks like '{engine_app_name}.apps.com' BUILT_IN = 1 # Auto-generated sub-domains @@ -45,5 +45,5 @@ class AppDomainSource(IntEnum): INDEPENDENT = 3 -class AppSubpathSource(IntEnum): +class AppSubpathSource(IntStructuredEnum): DEFAULT = 1 diff --git a/apiserver/paasng/paas_wl/workloads/release_controller/constants.py b/apiserver/paasng/paas_wl/workloads/release_controller/constants.py index ff16c8e0d1..431dd6f5f2 100644 --- a/apiserver/paasng/paas_wl/workloads/release_controller/constants.py +++ b/apiserver/paasng/paas_wl/workloads/release_controller/constants.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class RuntimeType(StrEnum): +class RuntimeType(StrStructuredEnum): BUILDPACK = EnumField("buildpack", label="Runtime for buildpack") CUSTOM_IMAGE = EnumField("custom_image", label="Custom Image") BK_SMART = EnumField("bk-smart", label="Runtime for buildpack, but build as image") DOCKERFILE = EnumField("dockerfile", label="Runtime for dockerfile") -class ImagePullPolicy(StrEnum): +class ImagePullPolicy(StrStructuredEnum): ALWAYS = EnumField("Always") IF_NOT_PRESENT = EnumField("IfNotPresent") NEVER = EnumField("Never") diff --git a/apiserver/paasng/paasng/accessories/ci/constants.py b/apiserver/paasng/paasng/accessories/ci/constants.py index c7db3a820a..900cec005c 100644 --- a/apiserver/paasng/paasng/accessories/ci/constants.py +++ b/apiserver/paasng/paasng/accessories/ci/constants.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class CIBackend(StrEnum): +class CIBackend(StrStructuredEnum): CODECC = EnumField("codecc", label="CodeCC") diff --git a/apiserver/paasng/paasng/accessories/cloudapi/constants.py b/apiserver/paasng/paasng/accessories/cloudapi/constants.py index d600a5c14f..25844a2afe 100644 --- a/apiserver/paasng/paasng/accessories/cloudapi/constants.py +++ b/apiserver/paasng/paasng/accessories/cloudapi/constants.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class ApplyStatusEnum(StrEnum): +class ApplyStatusEnum(StrStructuredEnum): PARTIAL_APPROVED = EnumField("partial_approved", label="部分通过") APPROVED = EnumField("approved", label="通过") REJECTED = EnumField("rejected", label="驳回") PENDING = EnumField("pending", label="待审批") -class PermissionStatusEnum(StrEnum): +class PermissionStatusEnum(StrStructuredEnum): OWNED = EnumField("owned", label="已拥有") REJECTED = EnumField("rejected", label="已拒绝") EXPIRED = EnumField("expired", label="已过期") @@ -33,24 +33,24 @@ class PermissionStatusEnum(StrEnum): NEED_APPLY = EnumField("need_apply", label="未申请") -class PermissionLevelEnum(StrEnum): +class PermissionLevelEnum(StrStructuredEnum): UNLIMITED = EnumField("unlimited", label="无限制") NORMAL = EnumField("normal", label="普通") SENSITIVE = EnumField("sensitive", label="敏感") SPECIAL = EnumField("special", label="特殊") -class PermissionActionEnum(StrEnum): +class PermissionActionEnum(StrStructuredEnum): APPLY = EnumField("apply", label="申请") RENEW = EnumField("renew", label="续期") -class PermissionApplyExpireDaysEnum(StrEnum): +class PermissionApplyExpireDaysEnum(StrStructuredEnum): PERMANENT = EnumField(0, label="永久") SIX_MONTH = EnumField(180, label="6个月") TWELVE_MONTH = EnumField(360, label="12个月") -class GrantDimensionEnum(StrEnum): +class GrantDimensionEnum(StrStructuredEnum): API = EnumField("api", label="按网关") RESOURCE = EnumField("resource", label="按资源") diff --git a/apiserver/paasng/paasng/accessories/log/constants.py b/apiserver/paasng/paasng/accessories/log/constants.py index 14fc1dc8e7..e69b54414b 100644 --- a/apiserver/paasng/paasng/accessories/log/constants.py +++ b/apiserver/paasng/paasng/accessories/log/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum # 如果日志配置是所有进程通用的, process_type 填充为 "-" DEFAULT_LOG_CONFIG_PLACEHOLDER = "-" @@ -27,7 +27,7 @@ MAX_RESULT_WINDOW = 10000 -class LogTimeChoices(StrEnum): +class LogTimeChoices(StrStructuredEnum): """日志搜索-日期范围可选值""" FIVE_MINUTES = EnumField("5m", label="5分钟") @@ -41,7 +41,7 @@ class LogTimeChoices(StrEnum): CUSTOMIZED = EnumField("customized", label="自定义") -class LogType(StrEnum): +class LogType(StrStructuredEnum): """ 日志类型 """ @@ -51,7 +51,7 @@ class LogType(StrEnum): INGRESS = EnumField("INGRESS", label="接入层日志") -class LogCollectorType(StrEnum): +class LogCollectorType(StrStructuredEnum): """日志采集器类型""" BK_LOG = EnumField("BK_LOG", label="蓝鲸日志平台采集器") diff --git a/apiserver/paasng/paasng/accessories/paas_analysis/constants.py b/apiserver/paasng/paasng/accessories/paas_analysis/constants.py index b470535e93..77471715e1 100644 --- a/apiserver/paasng/paasng/accessories/paas_analysis/constants.py +++ b/apiserver/paasng/paasng/accessories/paas_analysis/constants.py @@ -14,25 +14,25 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, IntEnum, StrEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum -class PAMetadataKey(StrEnum): +class PAMetadataKey(StrStructuredEnum): SITE_ID = "bkpa_site_id" -class MetricSourceType(IntEnum): +class MetricSourceType(IntStructuredEnum): INGRESS = EnumField(1, label="ingress") USER_TRACKER = EnumField(2, label="user_tracker") -class MetricsDimensionType(StrEnum): +class MetricsDimensionType(StrStructuredEnum): PATH = EnumField("path", label="path") USER = EnumField("user", label="user") ACTION = EnumField("action", label="action") -class MetricsInterval(StrEnum): +class MetricsInterval(StrStructuredEnum): """Available interval for metrics""" FIVE_MINUTES = EnumField("5m", label="5m") diff --git a/apiserver/paasng/paasng/accessories/publish/market/constant.py b/apiserver/paasng/paasng/accessories/publish/market/constant.py index 5148cb9d52..baf8b304f2 100644 --- a/apiserver/paasng/paasng/accessories/publish/market/constant.py +++ b/apiserver/paasng/paasng/accessories/publish/market/constant.py @@ -17,13 +17,13 @@ from enum import Enum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.core.region.states import RegionType -from paasng.utils.enum import EnumField, IntEnum, StrEnum -class ProductSourceUrlType(IntEnum): +class ProductSourceUrlType(IntStructuredEnum): """访问地址类型""" DISABLED = EnumField(1, label="未开启") @@ -63,14 +63,14 @@ def get_choices(cls): TAG_REGION_CHOICES = list(RegionType.get_choices()) + [("all", "所有版本")] -class OpenMode(StrEnum): +class OpenMode(StrStructuredEnum): """应用在桌面的打开方式""" DESKTOP = EnumField(real_value="desktop", label="桌面") NEW_TAB = EnumField(real_value="new_tab", label="新标签页") -class TagName(StrEnum): +class TagName(StrStructuredEnum): """应用分类名称""" OPSTOOlS = EnumField("OpsTools", label=_("运维工具")) diff --git a/apiserver/paasng/paasng/accessories/servicehub/constants.py b/apiserver/paasng/paasng/accessories/servicehub/constants.py index 03f8e208e6..3d34c72373 100644 --- a/apiserver/paasng/paasng/accessories/servicehub/constants.py +++ b/apiserver/paasng/paasng/accessories/servicehub/constants.py @@ -17,7 +17,7 @@ import uuid -from paasng.utils.enum import IntEnum, StrEnum +from blue_krill.data_types.enum import IntStructuredEnum, StrStructuredEnum # 需要在平台侧完全隐藏的字段名称,用户无法在产品上查看该字段内容,只能通过环境变量查看 SERVICE_SENSITIVE_FIELDS: dict = {} @@ -41,19 +41,19 @@ ) -class Category(IntEnum): +class Category(IntStructuredEnum): """Paas service categories""" DATA_STORAGE = 1 MONITORING_HEALTHY = 2 -class ServiceType(StrEnum): +class ServiceType(StrStructuredEnum): LOCAL = "local" REMOTE = "remote" -class ServiceBindingType(IntEnum): +class ServiceBindingType(IntStructuredEnum): """Type of service binding relationship""" NORMAL = 1 diff --git a/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py b/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py index d5557323b1..e1e9c6d767 100644 --- a/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py +++ b/apiserver/paasng/paasng/accessories/services/providers/mysql/constants.py @@ -14,10 +14,10 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import IntEnum +from blue_krill.data_types.enum import IntStructuredEnum -class MySQLAuthTypeEnum(IntEnum): +class MySQLAuthTypeEnum(IntStructuredEnum): GRANT = 1 REVOKE = 2 diff --git a/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py b/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py index 346c76f572..1a025d94a4 100644 --- a/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/bk_plugins/constants.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, IntEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum -class PluginTagIdType(IntEnum): +class PluginTagIdType(IntStructuredEnum): UNTAGGED = EnumField(-1, label="未分类") diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py index 62d7436385..8e23fa5101 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/bk_devops/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class PipelineBuildStatus(StrEnum): +class PipelineBuildStatus(StrStructuredEnum): """蓝盾流水线构建状态""" # 由于蓝盾接口文档未提供所有枚举值, 因此这里只列举目前已知的状态 diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py index 589cd70482..87d9a9ab64 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/constants.py @@ -15,12 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, IntEnum, StrEnum - -class PluginReleaseMethod(StrEnum): +class PluginReleaseMethod(StrStructuredEnum): """插件发布方式""" CODE = EnumField("code", label="源码发布") @@ -28,14 +27,14 @@ class PluginReleaseMethod(StrEnum): IMAGE = EnumField("image", label="镜像发布") -class PluginBasicInfoAccessMode(StrEnum): +class PluginBasicInfoAccessMode(StrStructuredEnum): """插件基本信息查看模式""" READONLY = EnumField("readonly", label="只读") READWRITE = EnumField("readwrite", label="读写") -class PluginReleaseVersionRule(StrEnum): +class PluginReleaseVersionRule(StrStructuredEnum): """插件发布版本号规则""" AUTOMATIC = EnumField("automatic", label="自动生成 semver") @@ -45,7 +44,7 @@ class PluginReleaseVersionRule(StrEnum): SELF_FILL = EnumField("self-fill", label="用户自助填写") -class SemverAutomaticType(StrEnum): +class SemverAutomaticType(StrStructuredEnum): """语义化版本生成规则""" MAJOR = EnumField("major", label="重大版本") @@ -53,7 +52,7 @@ class SemverAutomaticType(StrEnum): PATCH = EnumField("patch", label="修正版本") -class ReleaseStageInvokeMethod(StrEnum): +class ReleaseStageInvokeMethod(StrStructuredEnum): """发布步骤触发方式""" DEPLOY_API = EnumField("deployAPI", label="部署接口") @@ -64,7 +63,7 @@ class ReleaseStageInvokeMethod(StrEnum): BUILTIN = EnumField("builtin", label="内置功能(完善市场信息market, 灰度grayScale, 上线online)") -class PluginStatus(StrEnum): +class PluginStatus(StrStructuredEnum): """插件状态""" WAITING_APPROVAL = EnumField("waiting-approval", label="创建审批中") @@ -85,14 +84,14 @@ def approval_status(cls): return [cls.APPROVAL_FAILED, cls.WAITING_APPROVAL] -class PluginRole(IntEnum): +class PluginRole(IntStructuredEnum): """插件角色""" ADMINISTRATOR = EnumField(2, label="管理员") DEVELOPER = EnumField(3, label="开发者") -class MarketInfoStorageType(StrEnum): +class MarketInfoStorageType(StrStructuredEnum): """市场信息存储类型""" THIRD_PARTY = EnumField("third-party", label="仅存储在第三方系统") @@ -100,7 +99,7 @@ class MarketInfoStorageType(StrEnum): BOTH = EnumField("both", label="同时存储在插件开发中心和第三方系统") -class PluginReleaseStatus(StrEnum): +class PluginReleaseStatus(StrStructuredEnum): """插件发布状态""" SUCCESSFUL = EnumField("successful", label="成功") @@ -122,7 +121,7 @@ def terminated_status(cls): return [cls.FAILED, cls.INTERRUPTED, cls.SUCCESSFUL] -class LogTimeChoices(StrEnum): +class LogTimeChoices(StrStructuredEnum): """日志搜索-日期范围可选值""" FIVE_MINUTES = EnumField("5m", label="5分钟") @@ -136,7 +135,7 @@ class LogTimeChoices(StrEnum): CUSTOMIZED = EnumField("customized", label="自定义") -class ActionTypes(StrEnum): +class ActionTypes(StrStructuredEnum): """操作记录-动作类型""" CREATE = EnumField("create", label=_("创建")) @@ -150,7 +149,7 @@ class ActionTypes(StrEnum): ROLLBACK = EnumField("rollback", label=_("回滚")) -class SubjectTypes(StrEnum): +class SubjectTypes(StrStructuredEnum): """操作记录-主体""" PLUGIN = EnumField("plugin", label=_("插件")) @@ -165,28 +164,28 @@ class SubjectTypes(StrEnum): RELEASE_STRATEGY = EnumField("release_strategy", label=_("发布策略")) -class PluginReleaseType(StrEnum): +class PluginReleaseType(StrStructuredEnum): """插件版本发布类型""" PROD = EnumField("prod", label=_("正式发布")) TEST = EnumField("test", label=_("测试发布")) -class ReleaseStrategy(StrEnum): +class ReleaseStrategy(StrStructuredEnum): """插件发布策略""" GRAY = EnumField("gray", label=_("灰度发布")) FULL = EnumField("full", label=_("全量发布")) -class StatusPollingMethod(StrEnum): +class StatusPollingMethod(StrStructuredEnum): """发布阶段的状态轮询方式""" API = EnumField("api", label=_("后台 API 轮询")) FRONTEND = EnumField("frontend", label=_("前端轮询,如通过 Iframe message 通信等")) -class PluginRevisionType(StrEnum): +class PluginRevisionType(StrStructuredEnum): """代码版本类型""" ALL = EnumField("all", label=_("不限制")) @@ -195,7 +194,7 @@ class PluginRevisionType(StrEnum): TESTED_VERSION = EnumField("tested_version", label=_("已经测试通过的版本")) -class GrayReleaseStatus(StrEnum): +class GrayReleaseStatus(StrStructuredEnum): """插件灰度发布展示的状态,提供给前端展示的字段不需要国际化标记""" GRAY_APPROVAL_IN_PROGRESS = EnumField("gray_approval_in_progress", label="灰度发布审批中") diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py index a8f7547e84..079c2262d6 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/iam_adaptor/constants.py @@ -17,10 +17,10 @@ from typing import List +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.bk_plugins.pluginscenter.constants import PluginRole -from paasng.utils.enum import EnumField, StrEnum # 永不过期的时间(伪,其实是 2100.01.01 08:00:00,与权限中心保持一致) NEVER_EXPIRE_TIMESTAMP = 4102444800 @@ -41,7 +41,7 @@ NEVER_EXPIRE_DAYS = -1 -class PluginPermissionActions(StrEnum): +class PluginPermissionActions(StrStructuredEnum): """插件相关的操作权限""" BASIC_DEVELOPMENT = EnumField("basic_development", label=_("基础开发")) @@ -75,5 +75,5 @@ def get_choices_by_role(cls, role: PluginRole) -> List["PluginPermissionActions" raise NotImplementedError -class ResourceType(StrEnum): +class ResourceType(StrStructuredEnum): PLUGIN = EnumField("plugin", label=_("蓝鲸插件")) diff --git a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py index 060360f3e1..37d047d0ab 100644 --- a/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py +++ b/apiserver/paasng/paasng/bk_plugins/pluginscenter/itsm_adaptor/constants.py @@ -15,12 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class ApprovalServiceName(StrEnum): +class ApprovalServiceName(StrStructuredEnum): """审批流程服务名""" CREATE_APPROVAL = EnumField("create_approval", label=_("插件上线审批")) @@ -36,7 +35,7 @@ class ApprovalServiceName(StrEnum): ) -class ItsmTicketStatus(StrEnum): +class ItsmTicketStatus(StrStructuredEnum): """ITSM 流程状态""" RUNNING = EnumField("RUNNING", label=_("处理中")) diff --git a/apiserver/paasng/paasng/infras/accounts/permissions/constants.py b/apiserver/paasng/paasng/infras/accounts/permissions/constants.py index e37a982398..69af46406d 100644 --- a/apiserver/paasng/paasng/infras/accounts/permissions/constants.py +++ b/apiserver/paasng/paasng/infras/accounts/permissions/constants.py @@ -15,12 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class SiteAction(StrEnum): +class SiteAction(StrStructuredEnum): """蓝鲸 PaaS 平台全局功能相关权限""" VISIT_SITE = EnumField("visit_site", label=_("平台页面查看")) diff --git a/apiserver/paasng/paasng/infras/bk_ci/constants.py b/apiserver/paasng/paasng/infras/bk_ci/constants.py index 5f1be5b59e..4bc48138ea 100644 --- a/apiserver/paasng/paasng/infras/bk_ci/constants.py +++ b/apiserver/paasng/paasng/infras/bk_ci/constants.py @@ -15,12 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class PipelineBuildStatus(StrEnum): +class PipelineBuildStatus(StrStructuredEnum): """蓝盾流水线构建状态""" SUCCEED = EnumField("SUCCEED", label=_("成功")) diff --git a/apiserver/paasng/paasng/infras/bk_log/constatns.py b/apiserver/paasng/paasng/infras/bk_log/constatns.py index 6c77d8801f..a55d6865db 100644 --- a/apiserver/paasng/paasng/infras/bk_log/constatns.py +++ b/apiserver/paasng/paasng/infras/bk_log/constatns.py @@ -15,17 +15,17 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class ETLType(StrEnum): +class ETLType(StrStructuredEnum): DELIMITER = EnumField("bk_log_delimiter") REGEXP = EnumField("bk_log_regexp") JSON = EnumField("bk_log_json") TEXT = EnumField("bk_log_text") -class FieldType(StrEnum): +class FieldType(StrStructuredEnum): INT = EnumField("int") LONG = EnumField("long") DOUBLE = EnumField("double") @@ -34,6 +34,6 @@ class FieldType(StrEnum): NESTED = EnumField("nested") -class BkLogType(StrEnum): +class BkLogType(StrStructuredEnum): JSON = EnumField("json") STDOUT = EnumField("stdout") diff --git a/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py b/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py index 8ae3c9ce9f..6673643d5b 100644 --- a/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py +++ b/apiserver/paasng/paasng/infras/bkmonitorv3/constants.py @@ -15,11 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class SpaceType(StrEnum): +class SpaceType(StrStructuredEnum): SAAS = EnumField("bksaas", label=_("蓝鲸应用")) BKCC = EnumField("bkcc", label=_("业务")) diff --git a/apiserver/paasng/paasng/infras/iam/constants.py b/apiserver/paasng/paasng/infras/iam/constants.py index ed00331dc6..a9b0b42033 100644 --- a/apiserver/paasng/paasng/infras/iam/constants.py +++ b/apiserver/paasng/paasng/infras/iam/constants.py @@ -15,8 +15,9 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import IntStructuredEnum, StrStructuredEnum + from paasng.platform.applications.constants import ApplicationRole -from paasng.utils.enum import IntEnum, StrEnum # 使用 -1 表示永不过期 NEVER_EXPIRE_DAYS = -1 @@ -40,7 +41,7 @@ LIST_GRADE_MANAGERS_LIMIT = 15000 -class ResourceType(StrEnum): +class ResourceType(StrStructuredEnum): """ iam 上注册的资源类型 """ @@ -60,7 +61,7 @@ class ResourceType(StrEnum): BkLogEsSource = "es_source" -class IAMErrorCodes(IntEnum): +class IAMErrorCodes(IntStructuredEnum): """ iam api 返回错误码 https://bk.tencent.com/docs/document/7.0/236/39801 diff --git a/apiserver/paasng/paasng/infras/iam/legacy.py b/apiserver/paasng/paasng/infras/iam/legacy.py index b0bbb9bfc6..e51b54b825 100644 --- a/apiserver/paasng/paasng/infras/iam/legacy.py +++ b/apiserver/paasng/paasng/infras/iam/legacy.py @@ -18,17 +18,16 @@ # PaaS 2.0 相关权限 import logging +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.conf import settings from iam import IAM, Action, Request, Subject from iam.contrib.converter.sql import SQLConverter from iam.exceptions import AuthAPIError -from paasng.utils.enum import EnumField, StrEnum - logger = logging.getLogger(__name__) -class LegacyAction(StrEnum): +class LegacyAction(StrStructuredEnum): DEVELOP_APP = EnumField("develop_app", label="开发 SaaS 应用及外链应用") MANAGE_SMART = EnumField("manage_smart", label="管理 S-mart 应用") diff --git a/apiserver/paasng/paasng/infras/iam/open_apis/constants.py b/apiserver/paasng/paasng/infras/iam/open_apis/constants.py index 23a76012cb..de60eece91 100644 --- a/apiserver/paasng/paasng/infras/iam/open_apis/constants.py +++ b/apiserver/paasng/paasng/infras/iam/open_apis/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import StrEnum +from blue_krill.data_types.enum import StrStructuredEnum -class MethodType(StrEnum): +class MethodType(StrStructuredEnum): """ 权限中心拉取资源的 method 参数值 字段协议说明 https://bk.tencent.com/docs/document/6.0/160/8427?r=1 diff --git a/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py b/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py index 5c9df950d3..4f766ad099 100644 --- a/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py +++ b/apiserver/paasng/paasng/infras/iam/permissions/resources/application.py @@ -21,6 +21,7 @@ from attrs import define, field, validators from bkpaas_auth.core.encoder import user_id_encoder +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.conf import settings from django.db.models import Q from django.utils.translation import gettext_lazy as _ @@ -29,12 +30,11 @@ from paasng.infras.iam.constants import ResourceType from paasng.infras.iam.permissions.perm import PermCtx, Permission, ResCreatorAction, validate_empty from paasng.infras.iam.permissions.request import ResourceRequest -from paasng.utils.enum import EnumField, StrEnum logger = logging.getLogger(__name__) -class AppAction(StrEnum): +class AppAction(StrStructuredEnum): """蓝鲸 PaaS 应用相关权限""" # 应用基础信息查看 diff --git a/apiserver/paasng/paasng/misc/audit/constants.py b/apiserver/paasng/paasng/misc/audit/constants.py index 2756f9cef0..238951a400 100644 --- a/apiserver/paasng/paasng/misc/audit/constants.py +++ b/apiserver/paasng/paasng/misc/audit/constants.py @@ -15,19 +15,18 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, IntEnum, StrEnum - -class AccessType(IntEnum): +class AccessType(IntStructuredEnum): """访问方式""" WEB = EnumField(0, label=_("网页")) API = EnumField(1, label="API") -class ResultCode(IntEnum): +class ResultCode(IntStructuredEnum): """操作结果""" SUCCESS = EnumField(0, label=_("成功")) @@ -40,7 +39,7 @@ def get_terminated_codes(cls): return [cls.SUCCESS, cls.FAILURE, cls.INTERRUPT] -class DataType(StrEnum): +class DataType(StrStructuredEnum): """记录操作前后数据的数据类型,前端会根据该字段做不同的展示 前端不需要展示相关的 label, 故不用做国际化标记 """ @@ -55,7 +54,7 @@ class DataType(StrEnum): ) -class OperationTarget(StrEnum): +class OperationTarget(StrStructuredEnum): """操作对象""" APP = EnumField("app", label=_("应用")) @@ -93,7 +92,7 @@ class OperationTarget(StrEnum): SLUGRUNNER = EnumField("slugrunner", label="Slugrunner") -class OperationEnum(StrEnum): +class OperationEnum(StrStructuredEnum): """操作类型""" CREATE = EnumField("create", label=_("新建")) diff --git a/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py b/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py index 4027f2f3ac..904c88a51c 100644 --- a/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py +++ b/apiserver/paasng/paasng/misc/monitoring/metrics/constants.py @@ -15,16 +15,16 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum -class MetricsSeriesType(StrEnum): +class MetricsSeriesType(StrStructuredEnum): CURRENT = EnumField("current", "使用量") REQUEST = EnumField("request", "保留量") LIMIT = EnumField("limit", "配额上限") -class MetricsResourceType(StrEnum): +class MetricsResourceType(StrStructuredEnum): MEM = EnumField("mem") CPU = EnumField("cpu") diff --git a/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py b/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py index 4572b006db..9fd6f29dd6 100644 --- a/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py +++ b/apiserver/paasng/paasng/misc/monitoring/monitor/alert_rules/config/entities.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import StrEnum +from blue_krill.data_types.enum import StrStructuredEnum -class AlertCode(StrEnum): +class AlertCode(StrStructuredEnum): HIGH_CPU_USAGE = "high_cpu_usage" HIGH_MEM_USAGE = "high_mem_usage" POD_RESTART = "pod_restart" diff --git a/apiserver/paasng/paasng/misc/operations/models.py b/apiserver/paasng/paasng/misc/operations/models.py index 6d61e0b318..1ddb9d7ad0 100644 --- a/apiserver/paasng/paasng/misc/operations/models.py +++ b/apiserver/paasng/paasng/misc/operations/models.py @@ -157,7 +157,7 @@ def create_from_deployment(cls, deployment: Deployment): def get_text_display(self) -> str: if self.extra_values.status is not None: - status = JobStatus(self.extra_values.status) + status = JobStatus.SUCCESSFUL if self.extra_values.status is True else JobStatus.FAILED else: # Backward compatible with data which don't have `status` field status = JobStatus.SUCCESSFUL if self.extra_values.has_succeeded else JobStatus.FAILED diff --git a/apiserver/paasng/paasng/plat_admin/numbers/app.py b/apiserver/paasng/paasng/plat_admin/numbers/app.py index c50085cafc..c6f1d1a275 100644 --- a/apiserver/paasng/paasng/plat_admin/numbers/app.py +++ b/apiserver/paasng/paasng/plat_admin/numbers/app.py @@ -28,6 +28,7 @@ from bkpaas_auth import get_user_by_user_id from bkpaas_auth.models import user_id_encoder +from blue_krill.data_types.enum import IntStructuredEnum from django.conf import settings from django.utils.translation import gettext as _ from rest_framework.fields import get_attribute @@ -49,7 +50,6 @@ from paasng.platform.sourcectl.repo_controller import BaseGitRepoController from paasng.platform.sourcectl.source_types import get_sourcectl_names, get_sourcectl_type from paasng.platform.sourcectl.svn.server_config import get_bksvn_config -from paasng.utils.enum import IntEnum try: from paasng.infras.legacydb_te.models import LApplication, LApplicationUseRecord @@ -72,7 +72,7 @@ def get_pv_uv_for_env(*args, **kwargs) -> Tuple[int, int]: # type: ignore logger = logging.getLogger(__name__) -class DeployStatus(IntEnum): +class DeployStatus(IntStructuredEnum): PRODUCTION = 1 STAGING = 2 DEVELOPING = 3 diff --git a/apiserver/paasng/paasng/plat_admin/system/constants.py b/apiserver/paasng/paasng/plat_admin/system/constants.py index 4cc617326d..6ae9f0d7f6 100644 --- a/apiserver/paasng/paasng/plat_admin/system/constants.py +++ b/apiserver/paasng/paasng/plat_admin/system/constants.py @@ -14,9 +14,9 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import IntEnum +from blue_krill.data_types.enum import IntStructuredEnum -class SimpleAppSource(IntEnum): +class SimpleAppSource(IntStructuredEnum): DEFAULT = 1 LEGACY = 2 diff --git a/apiserver/paasng/paasng/platform/applications/constants.py b/apiserver/paasng/paasng/platform/applications/constants.py index 8ab43aa721..933aa03c49 100644 --- a/apiserver/paasng/paasng/platform/applications/constants.py +++ b/apiserver/paasng/paasng/platform/applications/constants.py @@ -17,13 +17,11 @@ from typing import Type -from blue_krill.data_types.enum import FeatureFlag, FeatureFlagField +from blue_krill.data_types.enum import EnumField, FeatureFlag, FeatureFlagField, IntStructuredEnum, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, IntEnum, StrEnum - -class ApplicationType(StrEnum): +class ApplicationType(StrStructuredEnum): DEFAULT = EnumField("default", label="普通应用") # 默认类型:无任何定制逻辑 ENGINELESS_APP = EnumField( "engineless_app", label="外链应用" @@ -33,7 +31,7 @@ class ApplicationType(StrEnum): CLOUD_NATIVE = EnumField("cloud_native", label="云原生应用") -class ApplicationRole(IntEnum): +class ApplicationRole(IntStructuredEnum): NOBODY = EnumField(-1, label="无身份用户") COLLABORATOR = EnumField(1, label="协作者") ADMINISTRATOR = EnumField(2, label="管理员") @@ -41,7 +39,7 @@ class ApplicationRole(IntEnum): OPERATOR = EnumField(4, label="运营") @classmethod - def get_roles(cls: Type[IntEnum]): + def get_roles(cls: Type[IntStructuredEnum]): return [ {"id": role.value, "name": role.name.lower()} for role in cls @@ -49,7 +47,7 @@ def get_roles(cls: Type[IntEnum]): ] -class AppLanguage(StrEnum): +class AppLanguage(StrStructuredEnum): PYTHON = EnumField("Python", label="Python") PHP = EnumField("PHP", label="PHP") GO = EnumField("Go", label="Go") @@ -76,7 +74,7 @@ def __str__(self): } -class AppEnvironment(StrEnum): +class AppEnvironment(StrStructuredEnum): STAGING = EnumField("stag", label="预发布环境") PRODUCTION = EnumField("prod", label="生产环境") @@ -104,7 +102,7 @@ class AppFeatureFlag(FeatureFlag): # type: ignore ENABLE_PERSISTENT_STORAGE = FeatureFlagField(label=_("开启持久存储挂载卷"), default=False) -class LightApplicationViewSetErrorCode(StrEnum): +class LightApplicationViewSetErrorCode(StrStructuredEnum): SUCCESS = 0 PARAM_NOT_VALID = 1301100 CREATE_APP_ERROR = 1301101 diff --git a/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py b/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py index f3d84a9036..2930d05156 100644 --- a/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py +++ b/apiserver/paasng/paasng/platform/applications/management/commands/force_del_app.py @@ -17,18 +17,18 @@ import logging +from blue_krill.data_types.enum import StrStructuredEnum from django.core.management.base import BaseCommand from paasng.accessories.publish.sync_market.managers import AppManger from paasng.core.core.storages.sqlalchemy import console_db from paasng.infras.iam.helpers import delete_builtin_user_groups, delete_grade_manager from paasng.platform.applications.models import Application -from paasng.utils.enum import StrEnum logger = logging.getLogger(__name__) -class DelKeyType(StrEnum): +class DelKeyType(StrStructuredEnum): """Source origin defines the origin of module's source code""" CODE = "code" diff --git a/apiserver/paasng/paasng/platform/bkapp_model/constants.py b/apiserver/paasng/paasng/platform/bkapp_model/constants.py index 1782c3f8bb..d6ec529515 100644 --- a/apiserver/paasng/paasng/platform/bkapp_model/constants.py +++ b/apiserver/paasng/paasng/platform/bkapp_model/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import EnumField, StrEnum +from blue_krill.data_types.enum import EnumField, StrStructuredEnum # legacy: Slug runner 默认的 entrypoint, 平台所有 slug runner 镜像都以该值作为入口 # TODO: 需验证存量所有镜像是否都设置了默认的 entrypoint, 如是, 即可移除所有 DEFAULT_SLUG_RUNNER_ENTRYPOINT @@ -25,7 +25,7 @@ PORT_PLACEHOLDER = "${PORT}" -class ExposedTypeName(StrEnum): +class ExposedTypeName(StrStructuredEnum): """与 paas_wl.workloads.networking.constants.ExposedTypeName 重复定义 # TODO 将 paasng 和 paas_wl 中重复定义的一些常量, 合并放到更底层的模块中, 避免破坏当前 importlinter 的依赖规则? """ @@ -33,7 +33,7 @@ class ExposedTypeName(StrEnum): BK_HTTP = "bk/http" -class NetworkProtocol(StrEnum): +class NetworkProtocol(StrStructuredEnum): """与 paas_wl.workloads.networking.constants.NetworkProtocol 重复定义 # TODO 将 paasng 和 paas_wl 中重复定义的一些常量, 合并放到更底层的模块中, 避免破坏当前 importlinter 的依赖规则? """ @@ -42,7 +42,7 @@ class NetworkProtocol(StrEnum): UDP = EnumField("UDP", label="UDP") -class ImagePullPolicy(StrEnum): +class ImagePullPolicy(StrStructuredEnum): """duplicated from paas_wl.workloads.release_controller.constants.ImagePullPolicy to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ @@ -52,7 +52,7 @@ class ImagePullPolicy(StrEnum): NEVER = EnumField("Never") -class ResQuotaPlan(StrEnum): +class ResQuotaPlan(StrStructuredEnum): """duplicated from paas_wl.bk_app.cnative.specs.constants.ResQuotaPlan to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ @@ -63,7 +63,7 @@ class ResQuotaPlan(StrEnum): P_4C4G = EnumField("4C4G", label="4C4G") -class ScalingPolicy(StrEnum): +class ScalingPolicy(StrStructuredEnum): """duplicated from paas_wl.bk_app.cnative.specs.constants.ScalingPolicy to decouple dependencies TODO 统一放置到一个独立于 paas_wl 和 paasng 的模块下? """ diff --git a/apiserver/paasng/paasng/platform/bkapp_model/utils.py b/apiserver/paasng/paasng/platform/bkapp_model/utils.py index 6c50dcc8d9..ef719d5c4d 100644 --- a/apiserver/paasng/paasng/platform/bkapp_model/utils.py +++ b/apiserver/paasng/paasng/platform/bkapp_model/utils.py @@ -17,16 +17,17 @@ import copy from typing import List, Optional, Tuple +from blue_krill.data_types.enum import StrStructuredEnum + from paas_wl.bk_app.cnative.specs.crd.bk_app import EnvVar, EnvVarOverlay from paasng.platform.applications.constants import ApplicationType from paasng.platform.engine.configurations.image import generate_image_repository from paasng.platform.engine.constants import RuntimeType from paasng.platform.modules.helpers import ModuleRuntimeManager from paasng.platform.modules.models import BuildConfig, Module -from paasng.utils.enum import StrEnum -class MergeStrategy(StrEnum): +class MergeStrategy(StrStructuredEnum): """Different strategy when merging env vars""" OVERRIDE = "Override" diff --git a/apiserver/paasng/paasng/platform/declarative/constants.py b/apiserver/paasng/paasng/platform/declarative/constants.py index a70f8282f9..12d7631072 100644 --- a/apiserver/paasng/paasng/platform/declarative/constants.py +++ b/apiserver/paasng/paasng/platform/declarative/constants.py @@ -17,7 +17,7 @@ from typing import Any, TypeVar -from paasng.utils.enum import EnumField, IntEnum, StrEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum T = TypeVar("T") @@ -43,7 +43,7 @@ def dict(self, *args, **kwargs): OMITTED_VALUE = OmittedType() -class AppSpecVersion(IntEnum): +class AppSpecVersion(IntStructuredEnum): # VER_1 meaning app.yaml is provided by S-Mart App VER_1 = 1 VER_2 = 2 @@ -51,12 +51,12 @@ class AppSpecVersion(IntEnum): VER_3 = 3 -class AppDescPluginType(StrEnum): +class AppDescPluginType(StrStructuredEnum): APP_VERSION = EnumField("app_version", label="应用版本") APP_LIBRARIES = EnumField("app_libraries", label="应用依赖库") -class DiffType(StrEnum): +class DiffType(StrStructuredEnum): ADDED = EnumField("added", label="新增") DELETED = EnumField("deleted", label="删除") NOT_MODIFIED = EnumField("not_modified", label="未改动") diff --git a/apiserver/paasng/paasng/platform/engine/constants.py b/apiserver/paasng/paasng/platform/engine/constants.py index dd3137b642..a125c27648 100644 --- a/apiserver/paasng/paasng/platform/engine/constants.py +++ b/apiserver/paasng/paasng/platform/engine/constants.py @@ -17,31 +17,31 @@ from typing import List +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ from paasng.utils.basic import ChoicesEnum -from paasng.utils.enum import EnumField, StrEnum PROC_DEFAULT_REPLICAS = 1 DOCKER_BUILD_STEPSET_NAME = "docker-build" IMAGE_RELEASE_STEPSET_NAME = "image-release" -class ClusterType(StrEnum): +class ClusterType(StrStructuredEnum): """集群类别""" NORMAL = EnumField("normal", label=_("普通集群")) VIRTUAL = EnumField("virtual", label=_("虚拟集群")) -class AppEnvName(StrEnum): +class AppEnvName(StrStructuredEnum): """The default environment names""" STAG = EnumField("stag", label=_("预发布环境")) PROD = EnumField("prod", label=_("生产环境")) -class JobStatus(StrEnum): +class JobStatus(StrStructuredEnum): SUCCESSFUL = EnumField("successful", label="成功") FAILED = EnumField("failed", label="失败") PENDING = EnumField("pending", label="等待") @@ -53,7 +53,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class BuildStatus(StrEnum): +class BuildStatus(StrStructuredEnum): """While `BuildStatus` has same members with `JobStatus`, different statuses might be added in the future""" SUCCESSFUL = "successful" @@ -67,7 +67,7 @@ def get_finished_states(cls) -> List[str]: return [cls.FAILED, cls.SUCCESSFUL, cls.INTERRUPTED] -class ReleaseStatus(StrEnum): +class ReleaseStatus(StrStructuredEnum): """While `ReleaseStatus` has same members with `JobStatus`, different statuses might be added in the future""" SUCCESSFUL = "successful" @@ -109,7 +109,7 @@ class MetricsType(ChoicesEnum): _choices_labels = ((MEM, "mem"), (CPU, "cpu"), (__ALL__, "__all__")) -class ConfigVarEnvName(StrEnum): +class ConfigVarEnvName(StrStructuredEnum): """Environment name for managing config var""" STAG = EnumField("stag", label="仅测试环境") @@ -141,20 +141,20 @@ class DeployConditions(ChoicesEnum): ) -class RuntimeType(StrEnum): +class RuntimeType(StrStructuredEnum): BUILDPACK = EnumField("buildpack", label=_("使用 Buildpacks 构建")) DOCKERFILE = EnumField("dockerfile", label=_("使用 Dockerfile 构建")) CUSTOM_IMAGE = EnumField("custom_image", label="Custom Image(云原生和旧镜像应用)") -class AppInfoBuiltinEnv(StrEnum): +class AppInfoBuiltinEnv(StrStructuredEnum): """应用基本信息的内置环境变量built-in""" APP_ID = EnumField("APP_ID", label=_("蓝鲸应用ID")) APP_SECRET = EnumField("APP_SECRET", label=_("蓝鲸应用密钥")) -class AppRunTimeBuiltinEnv(StrEnum): +class AppRunTimeBuiltinEnv(StrStructuredEnum): """Built-in envs in the app runtime""" APP_MODULE_NAME = EnumField("APP_MODULE_NAME", label=_("应用当前模块名")) diff --git a/apiserver/paasng/paasng/platform/engine/models/phases.py b/apiserver/paasng/paasng/platform/engine/models/phases.py index 335c635fb0..89725d6d80 100644 --- a/apiserver/paasng/paasng/platform/engine/models/phases.py +++ b/apiserver/paasng/paasng/platform/engine/models/phases.py @@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Dict +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.db import models from django.utils.translation import gettext_lazy as _ @@ -25,14 +26,13 @@ from paasng.platform.engine.constants import JobStatus from paasng.platform.engine.exceptions import DuplicateNameInSamePhaseError, StepNotInPresetListError from paasng.platform.engine.models import Deployment, EngineApp, MarkStatusMixin -from paasng.utils.enum import EnumField, StrEnum from paasng.utils.models import UuidAuditedModel if TYPE_CHECKING: from paasng.platform.engine.models.steps import DeployStep -class DeployPhaseTypes(StrEnum): +class DeployPhaseTypes(StrStructuredEnum): """部署阶段""" PREPARATION = EnumField("preparation", label=_("准备阶段")) diff --git a/apiserver/paasng/paasng/platform/engine/processes/events.py b/apiserver/paasng/paasng/platform/engine/processes/events.py index d3807e14e7..1809bdb379 100644 --- a/apiserver/paasng/paasng/platform/engine/processes/events.py +++ b/apiserver/paasng/paasng/platform/engine/processes/events.py @@ -21,20 +21,21 @@ from dataclasses import dataclass from typing import Any, Dict, Iterator, List, Tuple +from blue_krill.data_types.enum import IntStructuredEnum + from paas_wl.bk_app.processes.processes import PlainInstance, PlainProcess from paasng.platform.engine.processes.utils import diff_list -from paasng.utils.enum import IntEnum logger = logging.getLogger(__name__) @dataclass class ProcessBaseEvent: - type: IntEnum + type: IntStructuredEnum invoker: Any -class ProcessEventType(IntEnum): +class ProcessEventType(IntStructuredEnum): CREATED = 1 REMOVED = 2 UPDATED_COMMAND = 3 @@ -48,7 +49,7 @@ class ProcessEvent(ProcessBaseEvent): message: str -class ProcInstEventType(IntEnum): +class ProcInstEventType(IntStructuredEnum): CREATED = 1 REMOVED = 2 UPDATED_BECOME_READY = 3 diff --git a/apiserver/paasng/paasng/platform/engine/utils/output.py b/apiserver/paasng/paasng/platform/engine/utils/output.py index 1a8459361a..878aed7463 100644 --- a/apiserver/paasng/paasng/platform/engine/utils/output.py +++ b/apiserver/paasng/paasng/platform/engine/utils/output.py @@ -19,13 +19,13 @@ import sys from typing import Optional, Protocol +from blue_krill.data_types.enum import StrStructuredEnum from blue_krill.redis_tools.messaging import StreamChannel from django.conf import settings from paasng.core.core.storages.redisdb import get_default_redis from paasng.platform.engine.models import Deployment from paasng.utils import termcolors -from paasng.utils.enum import StrEnum def make_style(*args, **kwargs): @@ -67,7 +67,7 @@ class Style: White = make_style(fg="white", opts=("bold",)) -class StreamType(StrEnum): +class StreamType(StrStructuredEnum): STDOUT = "STDOUT" STDERR = "STDERR" diff --git a/apiserver/paasng/paasng/platform/evaluation/constants.py b/apiserver/paasng/paasng/platform/evaluation/constants.py index 4ccf6e1b15..93f76e106d 100644 --- a/apiserver/paasng/paasng/platform/evaluation/constants.py +++ b/apiserver/paasng/paasng/platform/evaluation/constants.py @@ -15,32 +15,31 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class BatchTaskStatus(StrEnum): +class BatchTaskStatus(StrStructuredEnum): """任务状态""" RUNNING = EnumField("running", label=_("运行中")) FINISHED = EnumField("finished", label=_("已完成")) -class EmailNotificationType(StrEnum): +class EmailNotificationType(StrStructuredEnum): """邮件通知类型""" IDLE_APP_MODULE_ENVS = EnumField("idle_app_module_envs", label=_("闲置应用模块")) -class EmailReceiverType(StrEnum): +class EmailReceiverType(StrStructuredEnum): """邮件接收者类型""" PLAT_ADMIN = EnumField("plat_admin", label=_("平台管理员")) APP_DEVELOPER = EnumField("app_developer", label=_("应用开发者")) -class OperationIssueType(StrEnum): +class OperationIssueType(StrStructuredEnum): """应用运营问题类型""" NONE = EnumField("none", label=_("无")) diff --git a/apiserver/paasng/paasng/platform/mgrlegacy/constants.py b/apiserver/paasng/paasng/platform/mgrlegacy/constants.py index 73ea1a5493..ecadc31910 100644 --- a/apiserver/paasng/paasng/platform/mgrlegacy/constants.py +++ b/apiserver/paasng/paasng/platform/mgrlegacy/constants.py @@ -17,8 +17,9 @@ from dataclasses import dataclass +from blue_krill.data_types.enum import StrStructuredEnum + from paasng.utils.basic import ChoicesEnum -from paasng.utils.enum import StrEnum class MigrationStatus(ChoicesEnum): @@ -120,7 +121,7 @@ class AppMember: role: int -class CNativeMigrationStatus(StrEnum): +class CNativeMigrationStatus(StrStructuredEnum): DEFAULT = "default" ON_MIGRATION = "on_migration" MIGRATION_SUCCEEDED = "migration_succeeded" diff --git a/apiserver/paasng/paasng/platform/modules/constants.py b/apiserver/paasng/paasng/platform/modules/constants.py index f6e5b16a2b..8f6d5f4004 100644 --- a/apiserver/paasng/paasng/platform/modules/constants.py +++ b/apiserver/paasng/paasng/platform/modules/constants.py @@ -17,23 +17,23 @@ from typing import Dict, List -from paasng.utils.enum import EnumField, IntEnum, StrEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum DEFAULT_ENGINE_APP_PREFIX = "bkapp" -class ModuleName(StrEnum): +class ModuleName(StrStructuredEnum): DEFAULT = "default" -class ExposedURLType(IntEnum): +class ExposedURLType(IntStructuredEnum): # eg: http://foo.com/region-bkapp-code-stag/ SUBPATH = 1 # eg: http://code.foo-apps.com/ SUBDOMAIN = 2 -class SourceOrigin(IntEnum): +class SourceOrigin(IntStructuredEnum): """Source origin defines the origin of module's source code""" AUTHORIZED_VCS = EnumField(1, "Authorized VCS") @@ -57,7 +57,7 @@ def get_package_origins(cls) -> List["SourceOrigin"]: return [SourceOrigin.BK_LESS_CODE, SourceOrigin.S_MART, SourceOrigin.AI_AGENT] -class APP_CATEGORY(StrEnum): +class APP_CATEGORY(StrStructuredEnum): """Application category, used when setting label to images""" NORMAL_APP = "normal_app" @@ -66,7 +66,7 @@ class APP_CATEGORY(StrEnum): LEGACY_APP = "legacy_app" -class DeployHookType(StrEnum): +class DeployHookType(StrStructuredEnum): """DeployHook Type""" PRE_RELEASE_HOOK = EnumField("pre-release-hook", label="部署前置钩子") @@ -79,7 +79,7 @@ def _missing_(cls, value): return super()._missing_(value) -class BuildPackType(StrEnum): +class BuildPackType(StrStructuredEnum): # legacy heroku buildpack format, just a tarball TAR = EnumField("tar", label="tar") @@ -101,7 +101,7 @@ def get_buildpack_builder_type_map(cls) -> Dict["BuildPackType", "AppImageType"] } -class AppImageType(StrEnum): +class AppImageType(StrStructuredEnum): LEGACY = EnumField("legacy", label="legacy") CNB = EnumField("cnb", label="cnb") diff --git a/apiserver/paasng/paasng/platform/sourcectl/client.py b/apiserver/paasng/paasng/platform/sourcectl/client.py index b54d810780..92686023d4 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/client.py +++ b/apiserver/paasng/paasng/platform/sourcectl/client.py @@ -21,13 +21,13 @@ from typing import Any, Dict, Generator, List, Optional import requests +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ from oauthlib.oauth2.rfc6749.errors import OAuth2Error from paasng.infras.accounts.models import Oauth2TokenHolder from paasng.platform.sourcectl import exceptions from paasng.platform.sourcectl.models import GitProject -from paasng.utils.enum import EnumField, StrEnum logger = logging.getLogger(__name__) @@ -43,7 +43,7 @@ RETRY_TIME = 3 -class GitRepoProvider(StrEnum): +class GitRepoProvider(StrStructuredEnum): """Git 仓库服务提供方""" GitHub = EnumField("github", label="GitHub") diff --git a/apiserver/paasng/paasng/platform/sourcectl/constants.py b/apiserver/paasng/paasng/platform/sourcectl/constants.py index 9549eea827..d28b4280c2 100644 --- a/apiserver/paasng/paasng/platform/sourcectl/constants.py +++ b/apiserver/paasng/paasng/platform/sourcectl/constants.py @@ -14,20 +14,19 @@ # # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import FeatureFlagField +from blue_krill.data_types.enum import EnumField, FeatureFlagField, StrStructuredEnum from paasng.infras.accounts.constants import AccountFeatureFlag -from paasng.utils.enum import EnumField, StrEnum -class DiffFeatureType(StrEnum): +class DiffFeatureType(StrStructuredEnum): """代码对比类型""" INTERNAL = "internal" EXTERNAL = "external" -class BasicSourceType(StrEnum): +class BasicSourceType(StrStructuredEnum): """基础源码类型""" GIT = "git" @@ -43,7 +42,7 @@ def register_new_sourcectl_type(feature_flag: FeatureFlagField): AccountFeatureFlag.register_ext_feature_flag(feature_flag) -class VersionType(StrEnum): +class VersionType(StrStructuredEnum): """版本类型. 对应 VersionInfo.version_type""" TAG = EnumField("tag", label="用于 Git 仓库、云原生镜像应用、旧镜像应用、镜像模式的 S-Mart 应用") diff --git a/apiserver/paasng/paasng/platform/templates/constants.py b/apiserver/paasng/paasng/platform/templates/constants.py index 7a06189803..c0dc726fd7 100644 --- a/apiserver/paasng/paasng/platform/templates/constants.py +++ b/apiserver/paasng/paasng/platform/templates/constants.py @@ -15,12 +15,11 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from django.utils.translation import gettext_lazy as _ -from paasng.utils.enum import EnumField, StrEnum - -class TemplateType(StrEnum): +class TemplateType(StrStructuredEnum): """模板类型""" NORMAL = EnumField("normal", _("普通应用")) diff --git a/apiserver/paasng/paasng/utils/blobstore.py b/apiserver/paasng/paasng/utils/blobstore.py index d448b0a81c..a58073b1bc 100644 --- a/apiserver/paasng/paasng/utils/blobstore.py +++ b/apiserver/paasng/paasng/utils/blobstore.py @@ -27,6 +27,7 @@ import boto3 from bkstorages.backends.bkrepo import BKRepoStorage from bkstorages.backends.rgw import RGWBoto3Storage +from blue_krill.data_types.enum import EnumField, StrStructuredEnum from blue_krill.storages.blobstore.base import BlobStore from blue_krill.storages.blobstore.bkrepo import BKGenericRepo from blue_krill.storages.blobstore.s3 import S3Store @@ -35,12 +36,10 @@ from django.conf import settings from django.utils.encoding import force_bytes, force_text -from paasng.utils.enum import EnumField, StrEnum - logger = logging.getLogger(__name__) -class StoreType(StrEnum): +class StoreType(StrStructuredEnum): S3 = EnumField("s3") BKREPO = EnumField("bkrepo") # 向前兼容, 支持 http/https 协议 diff --git a/apiserver/paasng/paasng/utils/enum.py b/apiserver/paasng/paasng/utils/enum.py deleted file mode 100644 index b1d84d7bbf..0000000000 --- a/apiserver/paasng/paasng/utils/enum.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -# TencentBlueKing is pleased to support the open source community by making -# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available. -# Copyright (C) 2017 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. -# -# We undertake not to change the open source license (MIT license) applicable -# to the current version of the project delivered to anyone in the future. - -# Q: 为什么需要这个包,而不是之前直接从 blue_krill 引入的方式? -# A: Python 3.11 中改变了枚举类的一些行为,且 blue_krill 不好做兼容,因此先由 apiserver 自行处理: -# https://github.com/python/cpython/issues/100458 -# https://github.com/TencentBlueKing/bkpaas-python-sdk/issues/190 - -# Q: 为什么这里 import EnumField 且忽略 F401 -# A: 统一枚举 import 入口,避免业务逻辑中需要从 utils.enum & blue_krill 中分别导入 -from blue_krill.data_types.enum import ( - EnumField, # noqa: F401 - StructuredEnum, -) - - -class StrEnum(str, StructuredEnum): - """Py3.11+ 中替换 (str, StructuredEnum) 的枚举基类""" - - __str__ = str.__str__ - - -class IntEnum(int, StructuredEnum): - """Py3.11+ 中替换 (int. StructuredEnum) 的枚举基类""" - - def __str__(self): - return "{}".format(self.value) diff --git a/apiserver/paasng/paasng/utils/patternmatcher.py b/apiserver/paasng/paasng/utils/patternmatcher.py index 62861f8bb3..910161a8d2 100644 --- a/apiserver/paasng/paasng/utils/patternmatcher.py +++ b/apiserver/paasng/paasng/utils/patternmatcher.py @@ -21,10 +21,10 @@ from dataclasses import dataclass from typing import Optional -from paasng.utils.enum import IntEnum +from blue_krill.data_types.enum import IntStructuredEnum -class MatchType(IntEnum): +class MatchType(IntStructuredEnum): Unknown = 0 Excat = 1 Prefix = 2 diff --git a/apiserver/paasng/paasng/utils/rate_limit/constants.py b/apiserver/paasng/paasng/utils/rate_limit/constants.py index fb34699d62..a906373013 100644 --- a/apiserver/paasng/paasng/utils/rate_limit/constants.py +++ b/apiserver/paasng/paasng/utils/rate_limit/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from paasng.utils.enum import IntEnum +from blue_krill.data_types.enum import IntStructuredEnum -class UserAction(IntEnum): +class UserAction(IntStructuredEnum): """ 用于频率限制的用户操作 diff --git a/apiserver/poetry.lock b/apiserver/poetry.lock index d4a19ca30a..277a8f8829 100644 --- a/apiserver/poetry.lock +++ b/apiserver/poetry.lock @@ -443,14 +443,14 @@ reference = "tencent-mirror" [[package]] name = "blue-krill" -version = "2.0.6" +version = "2.0.7" description = "Tools and common packages for blueking PaaS platform." category = "main" optional = false python-versions = ">=3.8,<3.12" files = [ - {file = "blue_krill-2.0.6-py3-none-any.whl", hash = "sha256:fef55abd4b8f80caf2e7e0a031af3f0b394254763a4fa052c4f138c341852851"}, - {file = "blue_krill-2.0.6.tar.gz", hash = "sha256:953392ab410106bee95caa1a0719cc57d09f5c40144e6b20aa86c211f2bbb2c7"}, + {file = "blue_krill-2.0.7-py3-none-any.whl", hash = "sha256:3b7cbd86a8ed1721fe853981d48b19485115f4db8f6b69d3cf33f34b7299b8e3"}, + {file = "blue_krill-2.0.7.tar.gz", hash = "sha256:7d0e42762033e63881ec7ab978f04558d17f1971ac132ef55812cbc7733561d5"}, ] [package.dependencies] @@ -5253,4 +5253,4 @@ reference = "tencent-mirror" [metadata] lock-version = "2.0" python-versions = ">=3.11,<3.12" -content-hash = "07a6d82d5b02d1b39441578e795ebe1c272f5ba8a2beb26330d07fa0774d7ad7" +content-hash = "a58e48ca22c120be4413c9e412d5d1afa49af6fff43f55a47c1f5b25db46eb40" diff --git a/apiserver/pyproject.toml b/apiserver/pyproject.toml index 3aa85e05c7..4b0d379125 100644 --- a/apiserver/pyproject.toml +++ b/apiserver/pyproject.toml @@ -16,7 +16,7 @@ bkpaas-auth = "2.1.0" apigw-manager = "3.0.2" bkstorages = "1.1.1" bleach = "3.3.0" -blue-krill = "2.0.6" +blue-krill = "2.0.7" bkapi-component-open = {version = "1.1.0"} boto = "2.49.0" boto3 = "1.33.13" From 8d8f42a188c4e5c37591e23936b24d6872d94957 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 21 Oct 2024 12:04:26 +0800 Subject: [PATCH 15/16] fix: enum type --- .../paas_wl/infras/resources/base/kres.py | 14 +++++------ .../paasng/accessories/cloudapi/constants.py | 4 ++-- .../accessories/smart_advisor/constants.py | 4 ++-- .../management/commands/adm_mapper_v1.py | 24 ++++++++++--------- .../paasng/platform/applications/constants.py | 2 +- .../paasng/platform/smart_app/constants.py | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/apiserver/paasng/paas_wl/infras/resources/base/kres.py b/apiserver/paasng/paas_wl/infras/resources/base/kres.py index 6f7985d144..81d6c4c01d 100644 --- a/apiserver/paasng/paas_wl/infras/resources/base/kres.py +++ b/apiserver/paasng/paas_wl/infras/resources/base/kres.py @@ -15,20 +15,20 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -"""kres is a well capsuled package for playing with kubernetes resources -""" +"""kres is a well capsuled package for playing with kubernetes resources""" + import functools import json import logging import time from contextlib import contextmanager from datetime import datetime -from enum import Enum from types import ModuleType from typing import Any, Callable, Collection, Dict, Iterator, List, Optional, Tuple, Type, Union, overload import cattr from attrs import define +from blue_krill.data_types.enum import StrStructuredEnum from kubernetes import client as client_mod from kubernetes.client.api_client import ApiClient from kubernetes.client.exceptions import ApiException @@ -66,7 +66,7 @@ def set_default_options(options: ClientOptionsDict): _default_options = options -class PatchType(str, Enum): +class PatchType(StrStructuredEnum): """Different merge types when patching a kubernetes resource See also: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/ """ @@ -116,12 +116,10 @@ def __set_name__(self, owner, name: str): self.method_name = name @overload - def __get__(self, instance: None, owner: None) -> "NameBasedMethodProxy": - ... + def __get__(self, instance: None, owner: None) -> "NameBasedMethodProxy": ... @overload - def __get__(self, instance: object, owner: Type) -> Callable: - ... + def __get__(self, instance: object, owner: Type) -> Callable: ... def __get__(self, instance, owner: Optional[Type] = None) -> Union["NameBasedMethodProxy", Callable]: if not instance: diff --git a/apiserver/paasng/paasng/accessories/cloudapi/constants.py b/apiserver/paasng/paasng/accessories/cloudapi/constants.py index 25844a2afe..b935ba8b05 100644 --- a/apiserver/paasng/paasng/accessories/cloudapi/constants.py +++ b/apiserver/paasng/paasng/accessories/cloudapi/constants.py @@ -15,7 +15,7 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from blue_krill.data_types.enum import EnumField, StrStructuredEnum +from blue_krill.data_types.enum import EnumField, IntStructuredEnum, StrStructuredEnum class ApplyStatusEnum(StrStructuredEnum): @@ -45,7 +45,7 @@ class PermissionActionEnum(StrStructuredEnum): RENEW = EnumField("renew", label="续期") -class PermissionApplyExpireDaysEnum(StrStructuredEnum): +class PermissionApplyExpireDaysEnum(IntStructuredEnum): PERMANENT = EnumField(0, label="永久") SIX_MONTH = EnumField(180, label="6个月") TWELVE_MONTH = EnumField(360, label="12个月") diff --git a/apiserver/paasng/paasng/accessories/smart_advisor/constants.py b/apiserver/paasng/paasng/accessories/smart_advisor/constants.py index 4ece7b1f49..e6fc42f6c8 100644 --- a/apiserver/paasng/paasng/accessories/smart_advisor/constants.py +++ b/apiserver/paasng/paasng/accessories/smart_advisor/constants.py @@ -15,8 +15,8 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from enum import Enum +from blue_krill.data_types.enum import IntStructuredEnum -class DeployFailurePatternType(int, Enum): +class DeployFailurePatternType(IntStructuredEnum): REGULAR_EXPRESSION = 1 diff --git a/apiserver/paasng/paasng/plat_admin/admin_cli/management/commands/adm_mapper_v1.py b/apiserver/paasng/paasng/plat_admin/admin_cli/management/commands/adm_mapper_v1.py index cad408e273..69c32efc95 100644 --- a/apiserver/paasng/paasng/plat_admin/admin_cli/management/commands/adm_mapper_v1.py +++ b/apiserver/paasng/paasng/plat_admin/admin_cli/management/commands/adm_mapper_v1.py @@ -37,9 +37,11 @@ python manage.py adm_mapper_v1 --action rollback --env-id {ENV_ID} """ + import sys -from enum import Enum +from blue_krill.data_types.enum import StrStructuredEnum +from django.core.exceptions import ObjectDoesNotExist from django.core.management.base import BaseCommand from paas_wl.bk_app.applications.api import get_latest_build_id @@ -53,7 +55,7 @@ from paasng.platform.engine.deploy.release.legacy import release_by_engine -class CommandAction(str, Enum): +class CommandAction(StrStructuredEnum): """A command action.""" # Upgrade to resource mapper v2 @@ -77,17 +79,17 @@ def add_arguments(self, parser): def handle(self, *args, **options): try: env = ModuleEnvironment.objects.get(id=options["env_id"]) - except ModuleEnvironment.DoesNotExist: + except ObjectDoesNotExist: self.exit_with_error(f"Environment {options['env_id']} does not exist") - - if options["action"] == CommandAction.UPGRADE.value: - self._handle_upgrade(env) - elif options["action"] == CommandAction.ROLLBACK.value: - self._handle_rollback(env) - elif options["action"] == CommandAction.CLEAN_V1.value: - self._handle_clean_v1(env) else: - raise RuntimeError("Invalid action") + if options["action"] == CommandAction.UPGRADE: + self._handle_upgrade(env) + elif options["action"] == CommandAction.ROLLBACK: + self._handle_rollback(env) + elif options["action"] == CommandAction.CLEAN_V1: + self._handle_clean_v1(env) + else: + raise RuntimeError("Invalid action") def _handle_upgrade(self, env: ModuleEnvironment): """Upgrade the environment to use resource mapper v2, it will re-deploy the environment diff --git a/apiserver/paasng/paasng/platform/applications/constants.py b/apiserver/paasng/paasng/platform/applications/constants.py index 933aa03c49..4ccecba0ca 100644 --- a/apiserver/paasng/paasng/platform/applications/constants.py +++ b/apiserver/paasng/paasng/platform/applications/constants.py @@ -102,7 +102,7 @@ class AppFeatureFlag(FeatureFlag): # type: ignore ENABLE_PERSISTENT_STORAGE = FeatureFlagField(label=_("开启持久存储挂载卷"), default=False) -class LightApplicationViewSetErrorCode(StrStructuredEnum): +class LightApplicationViewSetErrorCode(IntStructuredEnum): SUCCESS = 0 PARAM_NOT_VALID = 1301100 CREATE_APP_ERROR = 1301101 diff --git a/apiserver/paasng/paasng/platform/smart_app/constants.py b/apiserver/paasng/paasng/platform/smart_app/constants.py index af1d403c2d..a37ceaaca6 100644 --- a/apiserver/paasng/paasng/platform/smart_app/constants.py +++ b/apiserver/paasng/paasng/platform/smart_app/constants.py @@ -15,10 +15,10 @@ # We undertake not to change the open source license (MIT license) applicable # to the current version of the project delivered to anyone in the future. -from enum import Enum +from blue_krill.data_types.enum import StrStructuredEnum -class SMartPackageBuilderVersionFlag(str, Enum): +class SMartPackageBuilderVersionFlag(StrStructuredEnum): """s-mart 包构建器版本, 不同版本的构建器输出的产物类型不一样""" # 源码包 From e4fb38f8133ac39bddeba63d67a5243ce162c5c2 Mon Sep 17 00:00:00 2001 From: narasux Date: Mon, 21 Oct 2024 16:02:09 +0800 Subject: [PATCH 16/16] fix: type error --- .../paasng/paasng/misc/operations/models.py | 4 ++-- .../paasng/platform/applications/constants.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apiserver/paasng/paasng/misc/operations/models.py b/apiserver/paasng/paasng/misc/operations/models.py index 1ddb9d7ad0..d90c809917 100644 --- a/apiserver/paasng/paasng/misc/operations/models.py +++ b/apiserver/paasng/paasng/misc/operations/models.py @@ -118,7 +118,7 @@ class DeployOpValues: env_name: str has_succeeded: bool # `status` is optional to be compatible with legacy database data - status: Optional[bool] = None + status: Optional[str] = None class AppDeploymentOperationObj(OperationObj): @@ -157,7 +157,7 @@ def create_from_deployment(cls, deployment: Deployment): def get_text_display(self) -> str: if self.extra_values.status is not None: - status = JobStatus.SUCCESSFUL if self.extra_values.status is True else JobStatus.FAILED + status = JobStatus(self.extra_values.status) else: # Backward compatible with data which don't have `status` field status = JobStatus.SUCCESSFUL if self.extra_values.has_succeeded else JobStatus.FAILED diff --git a/apiserver/paasng/paasng/platform/applications/constants.py b/apiserver/paasng/paasng/platform/applications/constants.py index 4ccecba0ca..79567f9b3a 100644 --- a/apiserver/paasng/paasng/platform/applications/constants.py +++ b/apiserver/paasng/paasng/platform/applications/constants.py @@ -102,11 +102,11 @@ class AppFeatureFlag(FeatureFlag): # type: ignore ENABLE_PERSISTENT_STORAGE = FeatureFlagField(label=_("开启持久存储挂载卷"), default=False) -class LightApplicationViewSetErrorCode(IntStructuredEnum): - SUCCESS = 0 - PARAM_NOT_VALID = 1301100 - CREATE_APP_ERROR = 1301101 - EDIT_APP_ERROR = 1301102 - ESB_NOT_VALID = 1301103 - APP_NOT_EXIST = 1301104 - NO_PERMISSION = 1301105 +class LightApplicationViewSetErrorCode(StrStructuredEnum): + SUCCESS = "0" + PARAM_NOT_VALID = "1301100" + CREATE_APP_ERROR = "1301101" + EDIT_APP_ERROR = "1301102" + ESB_NOT_VALID = "1301103" + APP_NOT_EXIST = "1301104" + NO_PERMISSION = "1301105"