From ae7f46c8ef32c10e527fa8e88b3b5e304ca5ebff Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Thu, 26 Mar 2020 07:44:27 +0200 Subject: [PATCH] feat(endpoints): filter by endpoint type (#3646) --- api/http/handler/endpoints/endpoint_list.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/http/handler/endpoints/endpoint_list.go b/api/http/handler/endpoints/endpoint_list.go index b89899d16..403a3f668 100644 --- a/api/http/handler/endpoints/endpoint_list.go +++ b/api/http/handler/endpoints/endpoint_list.go @@ -28,6 +28,7 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht groupID, _ := request.RetrieveNumericQueryParameter(r, "groupId", true) limit, _ := request.RetrieveNumericQueryParameter(r, "limit", true) + endpointType, _ := request.RetrieveNumericQueryParameter(r, "type", true) endpointGroups, err := handler.EndpointGroupService.EndpointGroups() if err != nil { @@ -54,6 +55,10 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht filteredEndpoints = filterEndpointsBySearchCriteria(filteredEndpoints, endpointGroups, search) } + if endpointType != 0 { + filteredEndpoints = filterEndpointsByType(filteredEndpoints, portainer.EndpointType(endpointType)) + } + filteredEndpointCount := len(filteredEndpoints) paginatedEndpoints := paginateEndpoints(filteredEndpoints, start, limit) @@ -156,3 +161,14 @@ func endpointGroupMatchSearchCriteria(endpoint *portainer.Endpoint, endpointGrou return false } + +func filterEndpointsByType(endpoints []portainer.Endpoint, endpointType portainer.EndpointType) []portainer.Endpoint { + filteredEndpoints := make([]portainer.Endpoint, 0) + + for _, endpoint := range endpoints { + if endpoint.Type == endpointType { + filteredEndpoints = append(filteredEndpoints, endpoint) + } + } + return filteredEndpoints +}