wangxq ff40167dac The first initialization of the project 2 months ago
..
README.md ff40167dac The first initialization of the project 2 months ago
__init__.py ff40167dac The first initialization of the project 2 months ago
routes.py ff40167dac The first initialization of the project 2 months ago

README.md

系统管理API接口模块

本模块提供系统管理相关的API接口,包括系统健康检查、配置管理、系统信息获取和用户认证等功能,为前端应用和其他服务提供系统级别的支持。

功能概述

系统管理API模块主要提供以下功能的HTTP接口:

  1. 系统健康检查:提供系统和依赖组件的健康状态监控
  2. 配置管理:获取和验证系统配置信息
  3. 系统信息:获取系统运行环境的详细信息
  4. 用户认证:提供用户注册、登录等功能

API接口

1. 健康检查接口 (/system/health)

  • URL: /system/health
  • 方法: GET
  • 描述: 检查系统及其依赖组件的健康状态
  • 返回数据:

    {
    "code": 200,
    "success": true,
    "message": "success",
    "data": {
      "service": "DataOps-platform",
      "status": "UP",
      "version": "1.0.0",
      "time": "2023-03-17 12:34:56",
      "dependencies": {
        "neo4j": {
          "status": "UP",
          "details": {
            "url": "bolt://localhost:7687",
            "encrypted": false
          }
        }
      }
    }
    }
    

    2. 系统配置信息 (/system/config)

    • URL: /system/config
    • 方法: GET
    • 描述: 获取系统配置信息(非敏感信息)
    • 返回数据: json { "code": 200, "success": true, "message": "success", "data": { "environment": "development", "debug_mode": true, "port": 5000, "platform": "DataOps", "upload_folder": "/path/to/upload", "bucket_name": "dev", "prefix": "data", "neo4j_uri": "bolt://localhost:7687", "neo4j_encrypted": false } }

3. 系统信息接口 (/system/info)

  • URL: /system/info
  • 方法: GET
  • 描述: 获取系统运行环境的详细信息
  • 返回数据:

    {
    "code": 200,
    "success": true,
    "message": "success",
    "data": {
      "os": {
        "name": "Windows",
        "version": "10.0.19045",
        "platform": "Windows-10-10.0.19045-SP0"
      },
      "python": {
        "version": "3.9.10",
        "implementation": "CPython"
      },
      "network": {
        "hostname": "DESKTOP-12345",
        "ip": "192.168.1.100"
      },
      "resources": {
        "cpu": {
          "cores": 8,
          "logical_cores": 16,
          "usage_percent": 25.5
        },
        "memory": {
          "total": "16.00 GB",
          "available": "8.50 GB",
          "used": "7.50 GB",
          "percent": 46.9
        },
        "disk": {
          "total": "512.00 GB",
          "used": "256.00 GB",
          "free": "256.00 GB",
          "percent": 50.0
        }
      },
      "application": {
        "environment": "development",
        "debug_mode": true,
        "port": 5000,
        "platform": "DataOps"
      }
    }
    }
    

    4. 配置验证接口 (/system/config/validate)

    • URL: /system/config/validate
    • 方法: GET
    • 描述: 验证系统配置的有效性
    • 返回数据: json { "code": 200, "success": true, "message": "success", "data": { "valid": true, "errors": [] } }

5. 用户注册接口 (/system/auth/register)

  • URL: /system/auth/register
  • 方法: POST
  • 描述: 注册新用户
  • 请求参数:

    {
    "username": "用户名",
    "password": "密码"
    }
    
    • 返回数据: json { "code": 200, "message": "注册成功", "data": null }
  • 错误响应:

    {
    "code": 400,
    "message": "用户名已存在",
    "data": null
    }
    

    6. 用户登录接口 (/system/auth/login)

    • URL: /system/auth/login
    • 方法: POST
    • 描述: 用户登录验证
    • 请求参数: json { "username": "用户名", "password": "密码" }
  • 返回数据:

    {
    "code": 200,
    "message": "登录成功",
    "data": {
      "id": "用户ID",
      "username": "用户名",
      "created_at": 1679047342.123456,
      "last_login": 1679047400.654321
    }
    }
    
    • 错误响应: json { "code": 401, "message": "用户名或密码错误", "data": null }

7. 获取用户信息接口 (/system/auth/user/{username})

  • URL: /system/auth/user/{username}
  • 方法: GET
  • 描述: 获取指定用户的信息
  • 参数:
    • username: 要查询的用户名
  • 返回数据:

    {
    "code": 200,
    "message": "success",
    "data": {
      "id": "用户ID",
      "username": "用户名",
      "created_at": 1679047342.123456,
      "last_login": 1679047400.654321
    }
    }
    
    • 错误响应: json { "code": 404, "message": "用户不存在", "data": null }

技术实现

本模块基于Flask框架实现API接口,并使用core/system模块提供的核心功能。主要技术点包括:

  • RESTful API设计原则
  • 标准化的响应格式
  • 异常处理与错误日志记录
  • JSON序列化
  • Base64加密保护用户密码

依赖关系

本模块依赖于core/system模块中的核心功能实现:

from app.core.system import (
    check_neo4j_connection,
    check_system_health,
    get_system_info,
    get_system_config,
    validate_config,
    register_user,
    login_user,
    get_user_by_username
)