From b4f6dd7476e635f1497e81712de160e7de92e317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Sat, 17 Aug 2019 16:37:41 -0400 Subject: [PATCH] Add function to get endpoint group by name --- common/utils.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/utils.go b/common/utils.go index aa01a76..b8dbd5a 100644 --- a/common/utils.go +++ b/common/utils.go @@ -12,6 +12,7 @@ const ( ErrStackNotFound = Error("Stack not found") ErrStackClusterNotFound = Error("Stack cluster not found") ErrEndpointNotFound = Error("Endpoint not found") + ErrEndpointGroupNotFound = Error("Endpoint group not found") ErrSeveralEndpointsAvailable = Error("Several endpoints available") ErrNoEndpointsAvailable = Error("No endpoints available") ) @@ -92,6 +93,26 @@ func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) { return } +func GetEndpointGroupByName(name string) (endpointGroup portainer.EndpointGroup, err error) { + portainerClient, err := GetClient() + if err != nil { + return + } + + endpointGroups, err := portainerClient.GetEndpointGroups() + if err != nil { + return + } + + for _, endpointGroup := range endpointGroups { + if endpointGroup.Name == name { + return endpointGroup, nil + } + } + err = ErrEndpointGroupNotFound + return +} + func GetEndpointFromListById(endpoints []portainer.Endpoint, id portainer.EndpointID) (endpoint portainer.Endpoint, err error) { for i := range endpoints { if endpoints[i].ID == id {