Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E/get component handler #1950

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/component/component_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions internal/web/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down