From 671f74ce0debaea083dd74e7612a35847c8846ab Mon Sep 17 00:00:00 2001
From: matias-portainer <104775949+matias-portainer@users.noreply.github.com>
Date: Mon, 2 Oct 2023 11:37:39 -0300
Subject: [PATCH] fix(edge/groups): include only user trusted endpoints in
endpoint count EE-5964 (#10378)
---
.../handler/edgegroups/associated_endpoints.go | 18 ++++++++++++++++++
api/http/handler/edgegroups/edgegroup_list.go | 15 ++++++++++++---
.../groups-datatable/groupsDatatable.html | 8 ++++----
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/api/http/handler/edgegroups/associated_endpoints.go b/api/http/handler/edgegroups/associated_endpoints.go
index 6b5ae3d87..d03618c56 100644
--- a/api/http/handler/edgegroups/associated_endpoints.go
+++ b/api/http/handler/edgegroups/associated_endpoints.go
@@ -49,6 +49,24 @@ func GetEndpointsByTags(tx dataservices.DataStoreTx, tagIDs []portainer.TagID, p
return results, nil
}
+func getTrustedEndpoints(tx dataservices.DataStoreTx, endpointIDs []portainer.EndpointID) ([]portainer.EndpointID, error) {
+ results := []portainer.EndpointID{}
+ for _, endpointID := range endpointIDs {
+ endpoint, err := tx.Endpoint().Endpoint(endpointID)
+ if err != nil {
+ return nil, err
+ }
+
+ if !endpoint.UserTrusted {
+ continue
+ }
+
+ results = append(results, endpoint.ID)
+ }
+
+ return results, nil
+}
+
func mapEndpointGroupToEndpoints(endpoints []portainer.Endpoint) map[portainer.EndpointGroupID]endpointSetType {
groupEndpoints := map[portainer.EndpointGroupID]endpointSetType{}
diff --git a/api/http/handler/edgegroups/edgegroup_list.go b/api/http/handler/edgegroups/edgegroup_list.go
index 82b91368b..785fb551e 100644
--- a/api/http/handler/edgegroups/edgegroup_list.go
+++ b/api/http/handler/edgegroups/edgegroup_list.go
@@ -12,9 +12,10 @@ import (
type decoratedEdgeGroup struct {
portainer.EdgeGroup
- HasEdgeStack bool `json:"HasEdgeStack"`
- HasEdgeJob bool `json:"HasEdgeJob"`
- EndpointTypes []portainer.EndpointType
+ HasEdgeStack bool `json:"HasEdgeStack"`
+ HasEdgeJob bool `json:"HasEdgeJob"`
+ EndpointTypes []portainer.EndpointType
+ TrustedEndpoints []portainer.EndpointID `json:"TrustedEndpoints"`
}
// @id EdgeGroupList
@@ -85,6 +86,14 @@ func getEdgeGroupList(tx dataservices.DataStoreTx) ([]decoratedEdgeGroup, error)
}
edgeGroup.Endpoints = endpointIDs
+ edgeGroup.TrustedEndpoints = endpointIDs
+ } else {
+ trustedEndpoints, err := getTrustedEndpoints(tx, edgeGroup.Endpoints)
+ if err != nil {
+ return nil, httperror.InternalServerError("Unable to retrieve environments for Edge group", err)
+ }
+
+ edgeGroup.TrustedEndpoints = trustedEndpoints
}
endpointTypes, err := getEndpointTypes(tx, edgeGroup.Endpoints)
diff --git a/app/edge/components/groups-datatable/groupsDatatable.html b/app/edge/components/groups-datatable/groupsDatatable.html
index 331aec6f2..271c37a12 100644
--- a/app/edge/components/groups-datatable/groupsDatatable.html
+++ b/app/edge/components/groups-datatable/groupsDatatable.html
@@ -56,9 +56,9 @@