Ask/catalog 权限与审计加固、量表读权限统一,以及未提交的 ops hardening 变更。 Co-authored-by: Cursor <cursoragent@cursor.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
// ToolDefinitionRow is ToolDefinition catalog row.
|
|
type ToolDefinitionRow struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Code string `json:"code"`
|
|
Title string `json:"title"`
|
|
Description *string `json:"description,omitempty"`
|
|
Active bool `json:"active"`
|
|
System bool `json:"system"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// ListToolDefinitions returns ToolDefinition catalog.
|
|
func (r *AdminRepo) ListToolDefinitions(ctx context.Context) ([]ToolDefinitionRow, error) {
|
|
rows, err := r.Pool.Query(ctx, `
|
|
SELECT id, code, title, description, active, system, updated_at
|
|
FROM tool_definitions
|
|
ORDER BY active DESC, code ASC LIMIT 500`)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var out []ToolDefinitionRow
|
|
for rows.Next() {
|
|
var row ToolDefinitionRow
|
|
if err := rows.Scan(&row.ID, &row.Code, &row.Title, &row.Description, &row.Active, &row.System, &row.UpdatedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// GetToolDefinition loads one by id.
|
|
func (r *AdminRepo) GetToolDefinition(ctx context.Context, id uuid.UUID) (*ToolDefinitionRow, error) {
|
|
var row ToolDefinitionRow
|
|
err := r.Pool.QueryRow(ctx, `
|
|
SELECT id, code, title, description, active, system, updated_at
|
|
FROM tool_definitions WHERE id=$1`, id,
|
|
).Scan(&row.ID, &row.Code, &row.Title, &row.Description, &row.Active, &row.System, &row.UpdatedAt)
|
|
if errors.Is(err, pgx.ErrNoRows) {
|
|
return nil, err
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &row, nil
|
|
}
|