forked from concourse/concourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
36 lines (30 loc) · 911 Bytes
/
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
package teamserver
import (
"encoding/json"
"errors"
"net/http"
"github.com/pf-qiu/concourse/v6/atc"
"github.com/pf-qiu/concourse/v6/atc/api/accessor"
"github.com/pf-qiu/concourse/v6/atc/api/present"
)
func (s *Server) ListTeams(w http.ResponseWriter, r *http.Request) {
hLog := s.logger.Session("list-teams")
teams, err := s.teamFactory.GetTeams()
if err != nil {
hLog.Error("failed-to-get-teams", errors.New("sorry"))
w.WriteHeader(http.StatusInternalServerError)
}
acc := accessor.GetAccessor(r)
presentedTeams := make([]atc.Team, 0)
for _, team := range teams {
if acc.IsAuthorized(team.Name()) {
presentedTeams = append(presentedTeams, present.Team(team))
}
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(presentedTeams)
if err != nil {
hLog.Error("failed-to-encode-teams", err)
w.WriteHeader(http.StatusInternalServerError)
}
}