Skip to content

Commit 4a966cf

Browse files
feat: service list 接口返回增加 plan_schema 字段,以指导服务方案配置 (TencentBlueKing#233)
1 parent a09759d commit 4a966cf

9 files changed

Lines changed: 115 additions & 9 deletions

File tree

sdks/paas-service/CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# 版本历史
2+
## 2.0.3
3+
- service list 接口返回增加 `plan_schema` 字段,以指导服务方案配置
4+
25
## 2.0.2
36
- Support multi tenant
47

sdks/paas-service/paas_service/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
We undertake not to change the open source license (MIT license) applicable
1717
to the current version of the project delivered to anyone in the future.
1818
"""
19-
__version__ = '2.0.2'
19+
__version__ = '2.0.3'
2020

2121
default_app_config = 'paas_service.apps.PaaSServiceConfig'

sdks/paas-service/paas_service/base_vendor.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from abc import ABCMeta, abstractmethod
2020
from typing import ClassVar, Dict, Optional
2121

22+
from pydantic import BaseModel, Field
23+
2224
from django.conf import settings
2325
from django.core.exceptions import ImproperlyConfigured
2426
from django.utils.module_loading import import_string
@@ -33,6 +35,22 @@ def get_provider_cls():
3335
return import_string(SVC_PROVIDER_CLS)
3436

3537

38+
def get_plan_schema_cls():
39+
# 尝试从设置中获取类路径
40+
plan_schema_cls = getattr(settings, 'PAAS_SERVICE_PLAN_SCHEMA_CLS', None)
41+
42+
# 若存在有效类路径则导入,否则返回默认类
43+
return import_string(plan_schema_cls) if plan_schema_cls else EmptyPlanSchema
44+
45+
46+
def get_plan_schema() -> dict:
47+
return get_plan_schema_cls().schema()
48+
49+
50+
class EmptyPlanSchema(BaseModel):
51+
...
52+
53+
3654
class BaseVendorException(Exception):
3755
"""Base class for vendor exception"""
3856

@@ -80,3 +98,12 @@ def delete(self, instanceData: InstanceData):
8098

8199
def patch(self, instanceData: InstanceData, params: Dict) -> InstanceData:
82100
raise NotImplementedError
101+
102+
103+
# Plan Schema
104+
class BasePlanSchema(BaseModel):
105+
...
106+
107+
108+
class DummySchema(BasePlanSchema):
109+
foo: str = Field(..., description="这是一个示例字段")

sdks/paas-service/paas_service/serializers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
from typing import Optional
2020

21+
from paas_service.base_vendor import get_plan_schema as get_svc_plan_schema
2122
from paas_service.models import Plan, Service, ServiceInstance, SpecDefinition, Specification
2223
from rest_framework import serializers
2324

@@ -32,6 +33,7 @@ class ServiceSLZ(serializers.ModelSerializer):
3233
specifications = serializers.ListField(child=SpecDefinitionSLZ(), source='specifications.all')
3334
logo = serializers.SerializerMethodField()
3435
config = serializers.JSONField()
36+
plan_schema = serializers.SerializerMethodField()
3537

3638
def get_logo(self, obj):
3739
# type: (Service) -> Optional[str]
@@ -42,6 +44,9 @@ def get_logo(self, obj):
4244
else:
4345
return None
4446

47+
def get_plan_schema(self, obj) -> dict:
48+
return get_svc_plan_schema()
49+
4550
class Meta(object):
4651
model = Service
4752
exclude = ['created', 'updated']

0 commit comments

Comments
 (0)