weldr/sourceInfo: move '*' out of the loop

The API returns all sources on the route `sources/info/*`, but shouldn't
when one of the sources in the comma-separated list is a `*`.
This commit is contained in:
Lars Karlitski 2019-11-17 10:37:56 +00:00 committed by Tom Gundersen
parent d1a6e2efb7
commit 1dac0a03d2

View file

@ -195,27 +195,30 @@ func (api *API) sourceInfoHandler(writer http.ResponseWriter, request *http.Requ
Errors []responseError `json:"errors"`
}
names := strings.Split(params.ByName("sources"), ",")
names := params.ByName("sources")
sources := map[string]store.SourceConfig{}
errors := []responseError{}
for _, name := range names {
// if name is "*" we want all sources from the store and the base repo
if name == "*" {
sources = api.store.GetAllSources()
}
// check if the source is in the base repo
if name == api.repo.Id || name == "*" {
sources[api.repo.Id] = store.NewSourceConfig(api.repo, true)
// check if the source is in the store
} else if source := api.store.GetSource(name); source != nil {
sources[source.Name] = *source
} else {
error := responseError{
ID: "UnknownSource",
Msg: fmt.Sprintf("%s is not a valid source", name),
// if names is "*" we want all sources
if names == "*" {
sources = api.store.GetAllSources()
sources[api.repo.Id] = store.NewSourceConfig(api.repo, true)
} else {
for _, name := range strings.Split(names, ",") {
// check if the source is in the base repo
if name == api.repo.Id {
sources[api.repo.Id] = store.NewSourceConfig(api.repo, true)
// check if the source is in the store
} else if source := api.store.GetSource(name); source != nil {
sources[source.Name] = *source
} else {
error := responseError{
ID: "UnknownSource",
Msg: fmt.Sprintf("%s is not a valid source", name),
}
errors = append(errors, error)
}
errors = append(errors, error)
}
}