Skip to content

Commit

Permalink
feat: 提供 Agent 包管理后台基础接口 (closed #1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ping15 committed Nov 12, 2024
1 parent b236465 commit cc08b9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions apps/node_man/handlers/gse_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ def handle_add_tag(cls, tag_description: str, package_obj: GsePackages, package_
:param package_desc_obj: Gse包描述记录
"""
# 如果新增的是内置标签,将原有的内置标签中的target_version进行修改即可,否则创建一个新的标签
if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS:
if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS + constants.BUILT_IN_TAG_NAMES:
Tag.objects.filter(
name=constants.TAG_DESCRIPTION__TAG_NAME[tag_description], target_id=package_desc_obj.id
name=constants.TAG_DESCRIPTION__TAG_NAME.get(tag_description, tag_description),
target_id=package_desc_obj.id,
).update(target_version=package_obj.version)
else:
tag: Tag = Tag.objects.filter(description=tag_description, target_id=package_desc_obj.id).first()
Expand Down Expand Up @@ -219,9 +220,10 @@ def handle_update_tag(
# 如果目标标签为内置标签的话,将内置标签的target_version进行覆盖,并对原来的标签进行删除或者清空
# 如果目标标签为自定义标签,原有标签为内置标签的话,原有标签target_version置空,并新增自定义标签
# 否则(目标和原有都为自定义标签)将直接修改原有标签的target_version
if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS:
if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS + constants.BUILT_IN_TAG_NAMES:
Tag.objects.filter(
name=constants.TAG_DESCRIPTION__TAG_NAME[tag_description], target_id=package_desc_obj.id
name=constants.TAG_DESCRIPTION__TAG_NAME.get(tag_description, tag_description),
target_id=package_desc_obj.id,
).update(target_version=package_obj.version)
cls.handle_delete_tag(tag_obj.name, tag_obj)
elif tag_obj.name in constants.BUILT_IN_TAG_NAMES:
Expand Down
3 changes: 2 additions & 1 deletion apps/node_man/tools/gse_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def create_agent_tags(cls, tag_descriptions, project):
project=project, category=CategoryType.official
)

if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS:
if tag_description in constants.BUILT_IN_TAG_DESCRIPTIONS + constants.BUILT_IN_TAG_NAMES:
# 内置标签,手动指定name和description
name: str = constants.TAG_DESCRIPTION__TAG_NAME[tag_description]
tag_description = constants.TAG_NAME__TAG_DESCRIPTION.get(tag_description, tag_description)
else:
# 自定义标签,自动生成name
name: str = GsePackageTools.generate_name_by_description(tag_description)
Expand Down
2 changes: 2 additions & 0 deletions apps/node_man/views/package_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ def version(self, request):
}

machine_latest_version: str = ""
if validated_data.get("versions", ""):
machine_latest_version = max(validated_data["versions"], key=GsePackageTools.extract_numbers)
package_latest_version = list(version__pkg_version_info_map.keys())[0] if version__pkg_version_info_map else ""

return Response(
Expand Down

0 comments on commit cc08b9b

Please sign in to comment.