Skip to content

feat(overview): 添加获取面板操作日志API#16

Merged
molanp merged 2 commits intomainfrom
add-api/log
Aug 15, 2025
Merged

feat(overview): 添加获取面板操作日志API#16
molanp merged 2 commits intomainfrom
add-api/log

Conversation

@molanp
Copy link
Copy Markdown
Owner

@molanp molanp commented Aug 15, 2025

  • 在 Overview 类中添加 logs 方法,用于获取面板操作日志
  • 在 OverviewModel 中添加 LogType 枚举类和 LogDetail 模型类,用于表示操作日志详情
  • 在 ApiPool 中添加 LOG 常量,用于表示操作日志 API 端点
  • 优化请求发送方法,支持传入 ApiPool 枚举值
  • resolve [Feature Request]: 操作日志接口 #13

Sourcery 总结

通过定义新的日志模型和类型,在 Overview API 中添加对检索操作日志的支持;在 ApiPool 中引入 LOG 端点;增强对 ApiPool 值的请求处理;并在所有模型中强制执行更严格的类型检查和配置重命名。

新功能:

  • 在 Overview API 中添加 logs 方法以获取面板操作日志
  • 引入 LogType 枚举和 LogDetail 模型来表示操作日志详情
  • ApiPool 中添加 LOG 端点常量

改进:

  • 更新 Request.send 以接受 ApiPool 枚举值作为端点
  • 通过移除默认字段值,在所有 BaseModel 类中强制执行严格的类型检查
  • 在文件下载/上传 API 中将 CommonConfig 重命名为 FileDownloadConfig
  • MCSMAPI.overview 更改为返回 Overview API 实例而不是 OverviewModel
Original 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:

  • Add logs method to Overview API to fetch panel operation logs
  • Introduce LogType enum and LogDetail model to represent operation log details
  • Add LOG endpoint constant to ApiPool

Enhancements:

  • Update Request.send to accept ApiPool enum values as endpoints
  • Enforce strict typing across BaseModel classes by removing default field values
  • Rename CommonConfig to FileDownloadConfig in file download/upload APIs
  • Change MCSMAPI.overview to return an Overview API instance instead of OverviewModel

- 在 Overview 类中添加 logs 方法,用于获取面板操作日志
- 在 OverviewModel 中添加 LogType 枚举类和 LogDetail 模型类,用于表示操作日志详情
- 在 ApiPool 中添加 LOG 常量,用于表示操作日志 API 端点
- 优化请求发送方法,支持传入 ApiPool 枚举值
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Aug 15, 2025

审阅者指南

此 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
Loading

新增和更新的 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
Loading

更新的 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
Loading

更新的 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
Loading

重构的文件下载/上传配置的类图

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
Loading

文件级变更

变更 详情 文件
引入面板操作日志 API
  • 在 Overview API 中添加 logs() 方法
  • 为日志类别定义 LogType 枚举
  • 为日志条目创建 LogDetail 模型
  • 在 ApiPool 中添加 LOG 常量
mcsmapi/models/overview.py
mcsmapi/apis/overview.py
mcsmapi/pool.py
强制模型字段严格类型
  • 移除默认初始化器,使字段成为必填项
  • 相应调整 BaseModel 子类
  • 确保列表和原始类型没有默认值
mcsmapi/models/overview.py
mcsmapi/models/daemon.py
mcsmapi/models/instance.py
mcsmapi/models/file.py
mcsmapi/models/common.py
增强 Request.send 方法
  • 接受 ApiPool 枚举作为端点
  • 从请求体中移除 apikey/token
  • 为类方法添加类型提示
mcsmapi/request.py
重构文件操作配置
  • 将 CommonConfig 重命名为 FileDownloadConfig
  • 更新下载/上传 API 以使用新模型
mcsmapi/models/file.py
mcsmapi/apis/file.py
在客户端添加认证元数据
  • 在 MCSMAPI 中引入 authentication 属性
  • 将 overview() 返回类型调整为 Overview 类
mcsmapi/__init__.py
mcsmapi/apis/overview.py

可能相关的问题

  • #0: 此 PR 添加了 /api/overview/operation_logs 端点并实现了 LogDetail 模型,正如问题中要求的那样。

提示和命令

与 Sourcery 交互

  • 触发新审查: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复审查评论,要求 Sourcery 从中创建 Issue。您也可以回复审查评论并带上 @sourcery-ai issue 来创建 Issue。
  • 生成拉取请求标题: 随时在拉取请求标题的任何位置写入 @sourcery-ai,即可生成标题。您也可以随时在拉取请求上评论 @sourcery-ai title 来(重新)生成标题。
  • 生成拉取请求摘要: 随时在拉取请求正文的任何位置写入 @sourcery-ai summary,即可在您想要的位置生成 PR 摘要。您也可以随时在拉取请求上评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 随时在拉取请求上评论 @sourcery-ai guide 来(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这会很有用。
  • 驳回所有 Sourcery 审查: 在拉取请求上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这尤其有用——别忘了评论 @sourcery-ai review 以触发新的审查!

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

This 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 endpoint

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
Loading

Class diagram for new and updated Overview log models

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
Loading

Class diagram for updated Request and ApiPool usage

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
Loading

Class diagram for updated Overview API and MCSMAPI usage

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
Loading

Class diagram for refactored File download/upload config

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
Loading

File-Level Changes

Change Details Files
Introduce panel operation logs API
  • Add logs() method in Overview API
  • Define LogType enum for log categories
  • Create LogDetail model for log entries
  • Add LOG constant to ApiPool
mcsmapi/models/overview.py
mcsmapi/apis/overview.py
mcsmapi/pool.py
Enforce strict typing on model fields
  • Remove default initializers to make fields required
  • Adjust BaseModel subclasses accordingly
  • Ensure list and primitive types have no default
mcsmapi/models/overview.py
mcsmapi/models/daemon.py
mcsmapi/models/instance.py
mcsmapi/models/file.py
mcsmapi/models/common.py
Enhance Request.send method
  • Accept ApiPool enum as endpoint
  • Remove apikey/token from request body
  • Add type hints to class methods
mcsmapi/request.py
Refactor file operation configuration
  • Rename CommonConfig to FileDownloadConfig
  • Update download/upload APIs to use new model
mcsmapi/models/file.py
mcsmapi/apis/file.py
Add authentication metadata in client
  • Introduce authentication attribute in MCSMAPI
  • Adjust overview() return type to Overview class
mcsmapi/__init__.py
mcsmapi/apis/overview.py

Possibly linked issues

  • #0: The PR adds the /api/overview/operation_logs endpoint and implements the LogDetail model as requested in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大家好 - 我已经审阅了您的更改 - 以下是一些反馈:

  • 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>

Sourcery 对开源免费 - 如果您喜欢我们的审查,请考虑分享 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将根据您的反馈改进我的审查。
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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 molanp merged commit 285b636 into main Aug 15, 2025
1 check passed
@molanp molanp deleted the add-api/log branch August 15, 2025 07:45
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
- 优化了代码结构,提高了代码的可读性和维护性
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: 操作日志接口

1 participant