MCPcopy
hub / github.com/PatchMon/PatchMon / GetDebug

Method GetDebug

server-source-code/internal/handler/ai.go:165–204  ·  view source on GitHub ↗

GetDebug returns encryption debug info (admin only).

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

163
164// GetDebug returns encryption debug info (admin only).
165func (h *AIHandler) GetDebug(w http.ResponseWriter, r *http.Request) {
166 s, err := h.settings.GetFirst(r.Context())
167 if err != nil {
168 Error(w, http.StatusInternalServerError, "Failed to load settings")
169 return
170 }
171
172 // Round-trip test
173 testVal := "test-" + time.Now().Format("20060102150405")
174 encrypted, encErr := h.enc.Encrypt(testVal)
175 roundTripOk := false
176 if encErr == nil {
177 decrypted, decErr := h.enc.Decrypt(encrypted)
178 roundTripOk = decErr == nil && decrypted == testVal
179 }
180
181 existingKeyStatus := "not_set"
182 if s.AiAPIKey != nil && *s.AiAPIKey != "" {
183 _, err := h.enc.Decrypt(*s.AiAPIKey)
184 if err == nil {
185 existingKeyStatus = "valid"
186 } else {
187 existingKeyStatus = "invalid_cannot_decrypt"
188 }
189 }
190
191 roundTripResult := "failed"
192 if roundTripOk {
193 roundTripResult = "passed"
194 }
195
196 recommendation := "Configuration looks good"
197 // We don't have getEncryptionStatus in Go - use a simple message
198 JSON(w, http.StatusOK, map[string]interface{}{
199 "encryption": "configured",
200 "roundTripTest": roundTripResult,
201 "existingApiKey": existingKeyStatus,
202 "recommendation": recommendation,
203 })
204}
205
206// TestConnection tests the AI connection (admin only).
207func (h *AIHandler) TestConnection(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 5

ErrorFunction · 0.85
GetFirstMethod · 0.80
EncryptMethod · 0.80
DecryptMethod · 0.80
JSONFunction · 0.70

Tested by

no test coverage detected