forked from concourse/concourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
49 lines (40 loc) · 1.11 KB
/
get.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
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) GetTeam(w http.ResponseWriter, r *http.Request) {
hLog := s.logger.Session("get-team")
hLog.Debug("getting-team")
teamName := r.FormValue(":team_name")
team, found, err := s.teamFactory.FindTeam(teamName)
if err != nil {
hLog.Error("failed-to-get-team", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
acc := accessor.GetAccessor(r)
var presentedTeam atc.Team
if acc.IsAdmin() || acc.IsAuthorized(team.Name()) {
presentedTeam = present.Team(team)
} else {
hLog.Error("unauthorized", errors.New("not authorized to "+team.Name()))
w.WriteHeader(http.StatusForbidden)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(presentedTeam); err != nil {
hLog.Error("failed-to-encode-team", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
return
}