forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
48 lines (41 loc) · 1.1 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package resourceserver
import (
"encoding/json"
"net/http"
"github.com/concourse/atc"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/auth"
"github.com/concourse/atc/db"
"github.com/concourse/atc/dbng"
)
func (s *Server) ListResources(pipelineDB db.PipelineDB, _ dbng.Pipeline) http.Handler {
logger := s.logger.Session("list-resources")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resources, found, err := pipelineDB.GetResources()
if err != nil {
logger.Error("failed-to-get-dashboard-resources", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
showCheckErr := auth.IsAuthenticated(r)
teamName := r.FormValue(":team_name")
var presentedResources []atc.Resource
for _, resource := range resources {
presentedResources = append(
presentedResources,
present.Resource(
resource,
pipelineDB.Config().Groups,
showCheckErr,
teamName,
),
)
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(presentedResources)
})
}