forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
53 lines (43 loc) · 1.28 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
49
50
51
52
53
package volumeserver
import (
"encoding/json"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
"github.com/concourse/atc/dbng"
)
func (s *Server) ListVolumes(teamDB db.TeamDB, team dbng.Team) http.Handler {
hLog := s.logger.Session("list-volumes")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hLog.Debug("listing")
team, found, err := teamDB.GetTeam()
if err != nil {
hLog.Error("failed-to-find-team", err)
w.WriteHeader(http.StatusInternalServerError)
}
if !found {
hLog.Error("team-does-not-exist", err)
w.WriteHeader(http.StatusUnauthorized)
}
volumes, err := s.factory.GetTeamVolumes(team.ID)
if err != nil {
hLog.Error("failed-to-find-volumes", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
hLog.Debug("listed", lager.Data{"volume-count": len(volumes)})
presentedVolumes := make([]atc.Volume, len(volumes))
for i := 0; i < len(volumes); i++ {
volume := volumes[i]
presentedVolumes[i], err = present.Volume(volume)
if err != nil {
hLog.Error("failed-to-present-volume", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
}
json.NewEncoder(w).Encode(presentedVolumes)
})
}