mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-12-23 01:24:24 +00:00
Add API endpoint to retrieve sanitized server configuration
This commit is contained in:
@@ -610,3 +610,20 @@ func getDefaultConfigLocations() []string {
|
||||
|
||||
return locations
|
||||
}
|
||||
|
||||
// SanitizedCopy returns a copy of the AppConfig with sensitive information removed
|
||||
func (cfg *AppConfig) SanitizedCopy() AppConfig {
|
||||
// Create a copy of the config
|
||||
sanitized := *cfg
|
||||
|
||||
// Clear sensitive information
|
||||
sanitized.Auth.InferenceKeys = []string{}
|
||||
sanitized.Auth.ManagementKeys = []string{}
|
||||
|
||||
for nodeName, node := range sanitized.Nodes {
|
||||
node.APIKey = ""
|
||||
sanitized.Nodes[nodeName] = node
|
||||
}
|
||||
|
||||
return sanitized
|
||||
}
|
||||
|
||||
@@ -20,3 +20,20 @@ func (h *Handler) VersionHandler() http.HandlerFunc {
|
||||
writeText(w, http.StatusOK, versionInfo)
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigHandler godoc
|
||||
// @Summary Get server configuration
|
||||
// @Description Returns the current server configuration (sanitized)
|
||||
// @Tags System
|
||||
// @Security ApiKeyAuth
|
||||
// @Produces application/json
|
||||
// @Success 200 {object} config.AppConfig "Sanitized configuration"
|
||||
// @Failure 500 {string} string "Internal Server Error"
|
||||
// @Router /api/v1/config [get]
|
||||
func (h *Handler) ConfigHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Return a sanitized copy of the configuration
|
||||
sanitizedConfig := h.cfg.SanitizedCopy()
|
||||
writeJSON(w, http.StatusOK, sanitizedConfig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ func SetupRouter(handler *Handler) *chi.Mux {
|
||||
r.Use(authMiddleware.AuthMiddleware(KeyTypeManagement))
|
||||
}
|
||||
|
||||
r.Get("/version", handler.VersionHandler()) // Get server version
|
||||
r.Get("/version", handler.VersionHandler())
|
||||
|
||||
r.Get("/config", handler.ConfigHandler())
|
||||
|
||||
// Backend-specific endpoints
|
||||
r.Route("/backends", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user