From 77542b706834bc1d19ec2390447fc6e71b66c74a Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Thu, 12 Mar 2026 16:40:39 -0400 Subject: [PATCH] refactor: update API plugins version retrieval Refactor getPluginVersion to accept PluginConfig parameter: - Change signature from getPluginVersion(pluginName) to getPluginVersion(pluginName, cfg) - Update all call sites to pass config - Add TODO comment for future implementation querying actual plugin binary/container Update plugin handlers to use dynamic version retrieval: - GetV1Plugins: Use h.getPluginVersion(name, cfg) instead of hardcoded "1.0.0" - PutV1PluginsPluginNameConfig: Pass newConfig to version retrieval - GetV1PluginsPluginNameHealth: Use actual version from config This prepares the API for dynamic version reporting while maintaining backward compatibility with the current placeholder implementation. --- internal/api/plugins/handlers.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/api/plugins/handlers.go b/internal/api/plugins/handlers.go index bfc8504..16db9ff 100644 --- a/internal/api/plugins/handlers.go +++ b/internal/api/plugins/handlers.go @@ -82,8 +82,8 @@ func (h *Handler) GetV1Plugins(w http.ResponseWriter, r *http.Request) { Mode: cfg.Mode, Status: "unknown", Config: cfg, - RequiresRestart: false, // Default: plugins support hot-reload - Version: "1.0.0", // Placeholder + RequiresRestart: false, // Default: plugins support hot-reload + Version: h.getPluginVersion(name, cfg), } // Check if plugin is registered @@ -196,7 +196,7 @@ func (h *Handler) PutV1PluginsPluginNameConfig(w http.ResponseWriter, r *http.Re h.logger.Info("updated plugin config", "plugin", pluginName, "user", user.Name) // Return updated plugin info with actual version - version := h.getPluginVersion(pluginName) + version := h.getPluginVersion(pluginName, newConfig) info := PluginInfo{ Name: pluginName, Enabled: newConfig.Enabled, @@ -268,7 +268,7 @@ func (h *Handler) GetV1PluginsPluginNameHealth(w http.ResponseWriter, r *http.Re response := map[string]any{ "status": status, - "version": "1.0.0", + "version": h.getPluginVersion(pluginName, cfg), "timestamp": time.Now().UTC(), } @@ -301,9 +301,10 @@ func (h *Handler) checkPermission(user *auth.User, permission string) bool { // getPluginVersion retrieves the version for a plugin // TODO: Implement actual version query from plugin binary/container -func (h *Handler) getPluginVersion(pluginName string) string { +func (h *Handler) getPluginVersion(pluginName string, cfg PluginConfig) string { // In production, this should query the actual plugin binary/container - // For now, return a default version based on plugin name hash - _ = pluginName // Unused until actual implementation + // For now, return a default version + _ = pluginName + _ = cfg return "1.0.0" }