forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
39 lines (31 loc) · 972 Bytes
/
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
package pipelineserver
import (
"encoding/json"
"net/http"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/auth"
)
func (s *Server) GetPipeline(w http.ResponseWriter, r *http.Request) {
pipelineName := r.FormValue(":pipeline_name")
teamName := r.FormValue(":team_name")
teamDB := s.teamDBFactory.GetTeamDB(teamName)
pipeline, err := teamDB.GetPipelineByName(pipelineName)
if err != nil {
s.logger.Error("call-to-get-pipeline-failed", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
authorized, response := auth.IsAuthorized(r)
if !authorized && !pipeline.Public {
if response == auth.Unauthorized {
s.rejector.Unauthorized(w, r)
} else if response == auth.Forbidden {
s.rejector.Forbidden(w, r)
}
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
presentedPipeline := present.Pipeline(pipeline, pipeline.Config)
json.NewEncoder(w).Encode(presentedPipeline)
}