MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiPatchConfig

Method apiPatchConfig

modules/clibridge/admin_api.go:50–78  ·  view source on GitHub ↗

apiPatchConfig handles PATCH /admin/api/v1/clibridge-config.

(r *http.Request)

Source from the content-addressed store, hash-verified

48
49// apiPatchConfig handles PATCH /admin/api/v1/clibridge-config.
50func (m *CLIBridgeModule) apiPatchConfig(r *http.Request) (int, bool, any) {
51 var body struct {
52 Enabled *bool `json:"Enabled"`
53 AllowedTools []string `json:"AllowedTools"`
54 AllowedPaths []string `json:"AllowedPaths"`
55 }
56
57 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
58 return http.StatusBadRequest, false, "malformed request body: " + err.Error()
59 }
60
61 if body.Enabled != nil {
62 val := "false"
63 if *body.Enabled {
64 val = "true"
65 }
66 _ = configs.SetVal("Modules.clibridge.Enabled", val)
67 }
68
69 lc := listConfig{
70 AllowedTools: body.AllowedTools,
71 AllowedPaths: body.AllowedPaths,
72 }
73 if err := m.saveListConfig(lc); err != nil {
74 return http.StatusInternalServerError, false, "failed to save config: " + err.Error()
75 }
76
77 return http.StatusOK, true, "saved"
78}

Callers

nothing calls this directly

Calls 2

saveListConfigMethod · 0.95
SetValFunction · 0.92

Tested by

no test coverage detected