From a6f4f88fd2292975089e036033f8752e14efc56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Mej=C3=ADas=20Rodr=C3=ADguez?= Date: Thu, 15 Aug 2019 01:17:13 -0400 Subject: [PATCH] Add function to get endpoint by its name --- common/utils.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/utils.go b/common/utils.go index 93ec78b..44bd647 100644 --- a/common/utils.go +++ b/common/utils.go @@ -11,6 +11,7 @@ import ( const ( ErrStackNotFound = Error("Stack not found") ErrStackClusterNotFound = Error("Stack cluster not found") + ErrEndpointNotFound = Error("Endpoint not found") ErrSeveralEndpointsAvailable = Error("Several endpoints available") ErrNoEndpointsAvailable = Error("No endpoints available") ) @@ -71,6 +72,26 @@ func GetStackByName(name string, swarmId string, endpointId portainer.EndpointID return } +func GetEndpointByName(name string) (endpoint portainer.Endpoint, err error) { + portainerClient, err := GetClient() + if err != nil { + return + } + + endpoints, err := portainerClient.GetEndpoints() + if err != nil { + return + } + + for _, endpoint := range endpoints { + if endpoint.Name == name { + return endpoint, nil + } + } + err = ErrEndpointNotFound + return +} + func GetEndpointSwarmClusterId(endpointId portainer.EndpointID) (endpointSwarmClusterId string, err error) { // Get docker information for endpoint portainerClient, err := GetClient()