Files
Muse 5a9c9837e1 Remove panel API token system (panel-only, V2.7.1)
Delete the whole ApiToken stack from the panel: the api_tokens table
model and seed/migrate/normalize paths, the Bearer auth and
admin/monitor scope chain in the panel API (session login is now the
only panel API credential), the settings token-management endpoints,
the CLI -getApiToken bootstrap command, and the SecurityTab token
management UI plus its models/schemas/i18n keys. Regenerate the
frontend OpenAPI files (31 -> 26 schemas).

Agent side untouched: agent runtime, agent version (A2.6.0),
install-agent.sh, subscription/probe paths and node behavior are
unchanged. The /panel/api/agent group never went through checkAPIAuth
and is unaffected.

Also drop provably dead weight found in the same pass: the unimported
internal/xray/geodata package and its generated schemas, the retired
SPA shell routes (/groups, /xray, /outbound, /routing, /api-docs;
unregistered paths still reach the shell via the NoRoute fallback),
the never-set SettingController.xrayService field, and the CSRF
api_authed exemption whose only setter was the deleted Bearer branch.

Deliberately NOT dropped: the api_tokens table itself (left dormant
and empty in existing databases; a DROP migration needs a separate
decision) and the session apiAuthUserKey helper (test-only use remains).
2026-10-24 15:04:06 +00:00

156 lines
3.5 KiB
Go

package main
import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"
)
func main() {
root := flag.String("root", ".", "repository root containing internal/database/model and internal/web/entity")
outDir := flag.String("out", "frontend/src/generated", "output directory relative to root")
flag.Parse()
if err := run(*root, *outDir); err != nil {
fmt.Fprintln(os.Stderr, "openapigen:", err)
os.Exit(1)
}
}
func run(root, outDir string) error {
requests := []packageRequest{
{
Path: resolveRel(root, "internal/database/model"),
StructAllow: setOf(
"User",
"Inbound",
"FallbackParentInfo",
"OutboundTraffics",
"InboundClientIps",
"HistoryOfSeeders",
"Setting",
"Node",
"ClientReverse",
"Client",
"ClientRecord",
"ClientInbound",
"InboundFallback",
"Host",
"SubBalancer",
),
AliasAllow: setOf("Protocol"),
Overrides: map[string][]walkOverride{
"Inbound": {
{Field: "Settings", Kind: KindAny},
{Field: "StreamSettings", Kind: KindAny},
{Field: "Sniffing", Kind: KindAny},
},
"ClientRecord": {
{Field: "Reverse", Kind: KindAny},
},
"InboundClientIps": {
{Field: "Ips", Kind: KindAny},
},
"Host": {
{Field: "MuxParams", Kind: KindAny},
{Field: "SockoptParams", Kind: KindAny},
},
},
},
{
Path: resolveRel(root, "internal/web/entity"),
StructAllow: setOf(
"Msg",
"AllSetting",
"AllSettingView",
"HostGroup",
),
},
{
Path: resolveRel(root, "internal/xray"),
StructAllow: setOf(
"ClientTraffic",
),
},
{
Path: resolveRel(root, "internal/web/service"),
StructAllow: setOf(
"InboundOption",
"NodeMutationRequest",
"NodeView",
"ProbeResultUI",
"RealityScanResult",
"GeodataTokenIssue",
"AmneziaWGLogs",
"PeerActivity",
),
},
{
Path: resolveRel(root, "internal/web/service/panel"),
StructAllow: setOf("PanelUpdateStatus"),
},
{
Path: resolveRel(root, "internal/amneziawg"),
StructAllow: setOf("ServerSettings"),
},
}
schemas, aliases, err := walkPackages(requests)
if err != nil {
return err
}
schemas = flattenEmbedded(schemas)
if len(schemas) == 0 {
return fmt.Errorf("no schemas produced; nothing to write")
}
target := filepath.Join(root, outDir)
if err := os.MkdirAll(target, 0o755); err != nil {
return err
}
zodBuf := &bytes.Buffer{}
if err := emitZod(zodBuf, schemas, aliases); err != nil {
return err
}
typesBuf := &bytes.Buffer{}
if err := emitTypes(typesBuf, schemas, aliases); err != nil {
return err
}
examplesBuf := &bytes.Buffer{}
if err := emitExamples(examplesBuf, schemas, aliases); err != nil {
return err
}
schemasBuf := &bytes.Buffer{}
if err := emitJSONSchema(schemasBuf, schemas, aliases); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(target, "zod.ts"), zodBuf.Bytes(), 0o644); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(target, "types.ts"), typesBuf.Bytes(), 0o644); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(target, "examples.ts"), examplesBuf.Bytes(), 0o644); err != nil {
return err
}
if err := os.WriteFile(filepath.Join(target, "schemas.ts"), schemasBuf.Bytes(), 0o644); err != nil {
return err
}
fmt.Printf("openapigen: wrote %d schemas to %s\n", len(schemas), target)
return nil
}
func setOf(names ...string) map[string]bool {
m := make(map[string]bool, len(names))
for _, n := range names {
m[n] = true
}
return m
}