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.
This commit is contained in:
Jeremie Fraeys 2026-03-12 16:40:39 -04:00
parent 96dd604789
commit 77542b7068
No known key found for this signature in database

View file

@ -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"
}