package endpoints import ( "net/http" httperror "github.com/portainer/libhttp/error" "github.com/portainer/libhttp/response" "github.com/portainer/portainer/http/security" ) // GET request on /api/endpoints func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError { endpoints, err := handler.EndpointService.Endpoints() if err != nil { return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoints from the database", err} } endpointGroups, err := handler.EndpointGroupService.EndpointGroups() if err != nil { return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve endpoint groups from the database", err} } securityContext, err := security.RetrieveRestrictedRequestContext(r) if err != nil { return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err} } filteredEndpoints := security.FilterEndpoints(endpoints, endpointGroups, securityContext) for idx := range filteredEndpoints { hideFields(&filteredEndpoints[idx]) } return response.JSON(w, filteredEndpoints) }