github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/infoserver/creds.go (about)

     1  package infoserver
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  
     7  	"github.com/pf-qiu/concourse/v6/atc/creds"
     8  )
     9  
    10  // Creds returns information on the credential manager attached to this instance of concourse.
    11  // If no credential manager is configured the response will be empty.
    12  // No actual credentials are shown in the response.
    13  func (s *Server) Creds(w http.ResponseWriter, r *http.Request) {
    14  	logger := s.logger.Session("creds")
    15  
    16  	w.Header().Set("Content-Type", "application/json")
    17  
    18  	configuredManagers := make(creds.Managers)
    19  
    20  	for name, manager := range s.credsManagers {
    21  		if manager.IsConfigured() {
    22  			configuredManagers[name] = manager
    23  		}
    24  	}
    25  
    26  	err := json.NewEncoder(w).Encode(configuredManagers)
    27  	if err != nil {
    28  		logger.Error("failed-to-encode-info", err)
    29  		w.WriteHeader(http.StatusInternalServerError)
    30  	}
    31  }