diff --git a/CHANGELOG.md b/CHANGELOG.md index df3b31c1dd..abc6918a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,8 @@ Main (unreleased) - Add Prometheus bearer authentication to a `prometheus.write.queue` component (@freak12techno) +- Enhance getComponentHandler for selective data retrieval exposing options (@daxroc) + ### Bugfixes - Fixed a bug in `import.git` which caused a `"non-fast-forward update"` error message. (@ptodev) diff --git a/internal/component/component_provider.go b/internal/component/component_provider.go index 1f2c981447..f645351a04 100644 --- a/internal/component/component_provider.go +++ b/internal/component/component_provider.go @@ -57,6 +57,11 @@ func ParseID(input string) ID { } } +// ParseBool parses a string value into a boolean. If the value is "false", +func ParseBool(value string) bool { + return value != "false" +} + // InfoOptions is used by to determine how much information to return with // [Info]. type InfoOptions struct { diff --git a/internal/web/api/api.go b/internal/web/api/api.go index 3c6688d04e..f075d44b50 100644 --- a/internal/web/api/api.go +++ b/internal/web/api/api.go @@ -82,12 +82,16 @@ func getComponentHandler(host service.Host) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) requestedComponent := component.ParseID(vars["id"]) + requestedHealth := component.ParseBool(r.URL.Query().Get("health")) + requestedArguments := component.ParseBool(r.URL.Query().Get("arguments")) + requestedExports := component.ParseBool(r.URL.Query().Get("exports")) + requestedDebugInfo := component.ParseBool(r.URL.Query().Get("debugInfo")) component, err := host.GetComponent(requestedComponent, component.InfoOptions{ - GetHealth: true, - GetArguments: true, - GetExports: true, - GetDebugInfo: true, + GetHealth: requestedHealth, + GetArguments: requestedArguments, + GetExports: requestedExports, + GetDebugInfo: requestedDebugInfo, }) if err != nil { http.NotFound(w, r)