github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/pipelineserver/list_all.go (about) 1 package pipelineserver 2 3 import ( 4 "encoding/json" 5 "net/http" 6 7 "github.com/pf-qiu/concourse/v6/atc/api/accessor" 8 "github.com/pf-qiu/concourse/v6/atc/api/present" 9 "github.com/pf-qiu/concourse/v6/atc/db" 10 ) 11 12 // show all public pipelines and team private pipelines if authorized 13 func (s *Server) ListAllPipelines(w http.ResponseWriter, r *http.Request) { 14 logger := s.logger.Session("list-all-pipelines") 15 16 acc := accessor.GetAccessor(r) 17 18 var pipelines []db.Pipeline 19 var err error 20 21 if acc.IsAdmin() { 22 pipelines, err = s.pipelineFactory.AllPipelines() 23 } else { 24 pipelines, err = s.pipelineFactory.VisiblePipelines(acc.TeamNames()) 25 } 26 27 if err != nil { 28 logger.Error("failed-to-get-all-visible-pipelines", err) 29 w.WriteHeader(http.StatusInternalServerError) 30 return 31 } 32 33 w.Header().Set("Content-Type", "application/json") 34 err = json.NewEncoder(w).Encode(present.Pipelines(pipelines)) 35 if err != nil { 36 logger.Error("failed-to-encode-pipelines", err) 37 w.WriteHeader(http.StatusInternalServerError) 38 } 39 }