Merged
Conversation
- 在 Overview 类中添加 logs 方法,用于获取面板操作日志 - 在 OverviewModel 中添加 LogType 枚举类和 LogDetail 模型类,用于表示操作日志详情 - 在 ApiPool 中添加 LOG 常量,用于表示操作日志 API 端点 - 优化请求发送方法,支持传入 ApiPool 枚举值
Contributor
审阅者指南此 PR 通过扩展 Overview API 实现了一个新的操作日志端点,定义了详细的 LogType 枚举和 LogDetail 模型,增强了 HTTP 请求辅助函数以接受 ApiPool 枚举,通过移除默认值来收紧模型字段定义,并重构了文件下载/上传配置命名。 新操作日志端点的 ER 图erDiagram
LOG_DETAIL {
operation_id string
operator_name string
operation_time string
operator_ip string
operation_level enum
type enum
instance_name string
instance_id string
daemon_id string
login_result bool
file string
task_name string
}
LOG_TYPE {
value string
}
LOG_DETAIL ||--|| LOG_TYPE : has_type
新增和更新的 Overview 日志模型的类图classDiagram
class OverviewModel {
version: str
specifiedDaemonVersion: str
system: SystemInfo
record: RecordInfo
process: ProcessInfo
chart: ChartInfo
remoteCount: RemoteCountInfo
remote: list[DaemonModel]
}
class LogType {
<<enum>>
SYSTEM_CONFIG_CHANGE
USER_LOGIN
USER_CONFIG_CHANGE
USER_DELETE
USER_CREATE
DAEMON_CONFIG_CHANGE
DAEMON_REMOVE
DAEMON_CREATE
INSTANCE_TASK_DELETE
INSTANCE_TASK_CREATE
INSTANCE_FILE_DELETE
INSTANCE_FILE_DOWNLOAD
INSTANCE_FILE_UPDATE
INSTANCE_FILE_UPLOAD
INSTANCE_DELETE
INSTANCE_CREATE
INSTANCE_CONFIG_CHANGE
INSTANCE_KILL
INSTANCE_UPDATE
INSTANCE_RESTART
INSTANCE_STOP
INSTANCE_START
}
class LogDetail {
operation_id: str
operator_name: str | None
operation_time: str
operator_ip: str
operation_level: "info"|"warning"|"error"|"unknown"
type: LogType
instance_name: str | None
instance_id: str | None
daemon_id: str | None
login_result: bool | None
file: str | None
task_name: str | None
}
LogDetail --> LogType
OverviewModel --> SystemInfo
OverviewModel --> RecordInfo
OverviewModel --> ProcessInfo
OverviewModel --> ChartInfo
OverviewModel --> RemoteCountInfo
OverviewModel --> DaemonModel
更新的 Request 和 ApiPool 用法的类图classDiagram
class Request {
mcsm_url: str
timeout: int
session: requests.Session
apikey: str | None
token: str | None
+set_mcsm_url(url: str)
+set_timeout(timeout: int)
+set_apikey(apikey: str)
+set_token(token: str)
+__init__(mcsm_url: str | None, timeout: int | None)
+send(method: str, endpoint: str | ApiPool, params: dict | None, data: Any | None)
}
class ApiPool {
OVERVIEW
LOG
SERVICE
FILE
IMAGE
}
Request --> ApiPool
更新的 Overview API 和 MCSMAPI 用法的类图classDiagram
class Overview {
+overview()
+logs()
}
class MCSMAPI {
authentication: "apikey"|"account"
+__init__(url: str, timeout: int)
+login(username: str, password: str)
+login_with_apikey(apikey: str)
+overview() Overview
+instance() Instance
}
MCSMAPI --> Overview
重构的文件下载/上传配置的类图classDiagram
class FileDownloadConfig {
password: str
addr: str
}
class FileItem {
name: str
size: int
time: str
mode: int
type: FileType
daemonId: str
uuid: str
target: str
file_name: str
+rename(newName: str)
}
class FileList {
items: list[FileItem]
page: int
pageSize: int
total: int
absolutePath: str
daemonId: str
uuid: str
target: str
+__init__(**data: str)
}
FileList --> FileItem
文件级变更
可能相关的问题
提示和命令与 Sourcery 交互
自定义您的体验访问您的 仪表板 以:
获取帮助Original review guide in EnglishReviewer's GuideThis PR implements a new operation log endpoint by extending the Overview API, defines a detailed LogType enum and LogDetail model, enhances the HTTP request helper to accept ApiPool enums, tightens model field definitions by removing default values, and refactors file download/upload configuration naming. ER diagram for new operation log endpointerDiagram
LOG_DETAIL {
operation_id string
operator_name string
operation_time string
operator_ip string
operation_level enum
type enum
instance_name string
instance_id string
daemon_id string
login_result bool
file string
task_name string
}
LOG_TYPE {
value string
}
LOG_DETAIL ||--|| LOG_TYPE : has_type
Class diagram for new and updated Overview log modelsclassDiagram
class OverviewModel {
version: str
specifiedDaemonVersion: str
system: SystemInfo
record: RecordInfo
process: ProcessInfo
chart: ChartInfo
remoteCount: RemoteCountInfo
remote: list[DaemonModel]
}
class LogType {
<<enum>>
SYSTEM_CONFIG_CHANGE
USER_LOGIN
USER_CONFIG_CHANGE
USER_DELETE
USER_CREATE
DAEMON_CONFIG_CHANGE
DAEMON_REMOVE
DAEMON_CREATE
INSTANCE_TASK_DELETE
INSTANCE_TASK_CREATE
INSTANCE_FILE_DELETE
INSTANCE_FILE_DOWNLOAD
INSTANCE_FILE_UPDATE
INSTANCE_FILE_UPLOAD
INSTANCE_DELETE
INSTANCE_CREATE
INSTANCE_CONFIG_CHANGE
INSTANCE_KILL
INSTANCE_UPDATE
INSTANCE_RESTART
INSTANCE_STOP
INSTANCE_START
}
class LogDetail {
operation_id: str
operator_name: str | None
operation_time: str
operator_ip: str
operation_level: "info"|"warning"|"error"|"unknown"
type: LogType
instance_name: str | None
instance_id: str | None
daemon_id: str | None
login_result: bool | None
file: str | None
task_name: str | None
}
LogDetail --> LogType
OverviewModel --> SystemInfo
OverviewModel --> RecordInfo
OverviewModel --> ProcessInfo
OverviewModel --> ChartInfo
OverviewModel --> RemoteCountInfo
OverviewModel --> DaemonModel
Class diagram for updated Request and ApiPool usageclassDiagram
class Request {
mcsm_url: str
timeout: int
session: requests.Session
apikey: str | None
token: str | None
+set_mcsm_url(url: str)
+set_timeout(timeout: int)
+set_apikey(apikey: str)
+set_token(token: str)
+__init__(mcsm_url: str | None, timeout: int | None)
+send(method: str, endpoint: str | ApiPool, params: dict | None, data: Any | None)
}
class ApiPool {
OVERVIEW
LOG
SERVICE
FILE
IMAGE
}
Request --> ApiPool
Class diagram for updated Overview API and MCSMAPI usageclassDiagram
class Overview {
+overview()
+logs()
}
class MCSMAPI {
authentication: "apikey"|"account"
+__init__(url: str, timeout: int)
+login(username: str, password: str)
+login_with_apikey(apikey: str)
+overview() Overview
+instance() Instance
}
MCSMAPI --> Overview
Class diagram for refactored File download/upload configclassDiagram
class FileDownloadConfig {
password: str
addr: str
}
class FileItem {
name: str
size: int
time: str
mode: int
type: FileType
daemonId: str
uuid: str
target: str
file_name: str
+rename(newName: str)
}
class FileList {
items: list[FileItem]
page: int
pageSize: int
total: int
absolutePath: str
daemonId: str
uuid: str
target: str
+__init__(**data: str)
}
FileList --> FileItem
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
大家好 - 我已经审阅了您的更改 - 以下是一些反馈:
- LogDetail 使用了字段名 "type",这会遮蔽内置类型;请考虑重命名它或使用别名以避免潜在冲突。
- 您移除了许多 Pydantic 模型的默认值并使所有字段变为必填项——请验证 API 响应是否始终包含这些字段,或者添加对缺失值的处理以保持兼容性。
- 新的 logs() 方法返回所有未过滤的条目——请考虑添加可选参数进行分页或过滤(例如,按日期范围或日志类型)以防止非常大的有效负载。
AI 代理的提示
请处理此代码审查中的评论:
## 总体评论
- LogDetail 使用了字段名 "type",这会遮蔽内置类型;请考虑重命名它或使用别名以避免潜在冲突。
- 您移除了许多 Pydantic 模型的默认值并使所有字段变为必填项——请验证 API 响应是否始终包含这些字段,或者添加对缺失值的处理以保持兼容性。
- 新的 logs() 方法返回所有未过滤的条目——请考虑添加可选参数进行分页或过滤(例如,按日期范围或日志类型)以防止非常大的有效负载。
## 单个评论
### 评论 1
<location> `mcsmapi/__init__.py:14` </location>
<code_context>
class MCSMAPI:
+ authentication: Literal["apikey", "account"]
+ """认证类型"""
+
def __init__(self, url: str, timeout: int = 5) -> None:
</code_context>
<issue_to_address>
authentication 现在是一个类属性,但在实例方法中设置。
将 authentication 用作类属性可能会导致并发实例问题。请考虑将其改为实例属性。
</issue_to_address>帮助我更有用!请点击每个评论上的 👍 或 👎,我将根据您的反馈改进我的审查。
Original comment in English
Hey there - I've reviewed your changes - here's some feedback:
- LogDetail uses the field name "type", which shadows the built-in; consider renaming it or using an alias to avoid potential conflicts.
- You’ve removed defaults from many Pydantic models and made all fields required—verify that API responses always include these fields or add handling for missing values to maintain compatibility.
- The new logs() method returns all entries unfiltered—consider adding optional parameters for pagination or filtering (e.g., by date range or log type) to prevent very large payloads.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- LogDetail uses the field name "type", which shadows the built-in; consider renaming it or using an alias to avoid potential conflicts.
- You’ve removed defaults from many Pydantic models and made all fields required—verify that API responses always include these fields or add handling for missing values to maintain compatibility.
- The new logs() method returns all entries unfiltered—consider adding optional parameters for pagination or filtering (e.g., by date range or log type) to prevent very large payloads.
## Individual Comments
### Comment 1
<location> `mcsmapi/__init__.py:14` </location>
<code_context>
class MCSMAPI:
+ authentication: Literal["apikey", "account"]
+ """认证类型"""
+
def __init__(self, url: str, timeout: int = 5) -> None:
</code_context>
<issue_to_address>
authentication is now a class attribute, but is set in instance methods.
Using a class attribute for authentication may cause issues with concurrent instances. Consider making it an instance attribute instead.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 删除了 MCSMAPI 类中未使用的 authentication 属性 - 移除了相关的类型注解 Literal - 优化了代码结构,提高了代码的可读性和维护性
molanp
added a commit
that referenced
this pull request
Jan 31, 2026
* feat(overview): 添加获取面板操作日志API - 在 Overview 类中添加 logs 方法,用于获取面板操作日志 - 在 OverviewModel 中添加 LogType 枚举类和 LogDetail 模型类,用于表示操作日志详情 - 在 ApiPool 中添加 LOG 常量,用于表示操作日志 API 端点 - 优化请求发送方法,支持传入 ApiPool 枚举值 * refactor(mcsmapi): 移除未使用的类型注解 Literal - 删除了 MCSMAPI 类中未使用的 authentication 属性 - 移除了相关的类型注解 Literal - 优化了代码结构,提高了代码的可读性和维护性
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sourcery 总结
通过定义新的日志模型和类型,在 Overview API 中添加对检索操作日志的支持;在 ApiPool 中引入 LOG 端点;增强对 ApiPool 值的请求处理;并在所有模型中强制执行更严格的类型检查和配置重命名。
新功能:
logs方法以获取面板操作日志LogType枚举和LogDetail模型来表示操作日志详情ApiPool中添加LOG端点常量改进:
Request.send以接受ApiPool枚举值作为端点BaseModel类中强制执行严格的类型检查CommonConfig重命名为FileDownloadConfigMCSMAPI.overview更改为返回 Overview API 实例而不是OverviewModelOriginal summary in English
Summary by Sourcery
Add support for retrieving operation logs in the Overview API by defining new log models and types, introduce a LOG endpoint in ApiPool, enhance request handling for ApiPool values, and enforce stricter typing and config renaming across models
New Features:
Enhancements: