github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/pipelineserver/list.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  func (s *Server) ListPipelines(w http.ResponseWriter, r *http.Request) {
    13  	logger := s.logger.Session("list-pipelines")
    14  	requestTeamName := r.FormValue(":team_name")
    15  	team, found, err := s.teamFactory.FindTeam(requestTeamName)
    16  	if err != nil {
    17  		logger.Error("failed-to-get-team", err)
    18  		w.WriteHeader(http.StatusInternalServerError)
    19  		return
    20  	}
    21  
    22  	if !found {
    23  		logger.Info("team-not-found")
    24  		w.WriteHeader(http.StatusNotFound)
    25  		return
    26  	}
    27  
    28  	var pipelines []db.Pipeline
    29  	acc := accessor.GetAccessor(r)
    30  
    31  	if acc.IsAuthorized(requestTeamName) {
    32  		pipelines, err = team.Pipelines()
    33  	} else {
    34  		pipelines, err = team.PublicPipelines()
    35  	}
    36  
    37  	if err != nil {
    38  		logger.Error("failed-to-get-all-active-pipelines", err)
    39  		w.WriteHeader(http.StatusInternalServerError)
    40  		return
    41  	}
    42  
    43  	w.Header().Set("Content-Type", "application/json")
    44  
    45  	err = json.NewEncoder(w).Encode(present.Pipelines(pipelines))
    46  	if err != nil {
    47  		logger.Error("failed-to-encode-pipelines", err)
    48  		w.WriteHeader(http.StatusInternalServerError)
    49  	}
    50  }