From cb257da15be75c97cf48e103b00ca2faf77e299c Mon Sep 17 00:00:00 2001 From: Vitaliy Saveliev <70613571+milkrage@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:03:47 +0300 Subject: [PATCH] Return only public endpoints from a CatalogService (#165) --- selvpcclient/clients/services/catalog.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/selvpcclient/clients/services/catalog.go b/selvpcclient/clients/services/catalog.go index 7b9a96a..0987c78 100644 --- a/selvpcclient/clients/services/catalog.go +++ b/selvpcclient/clients/services/catalog.go @@ -81,18 +81,31 @@ func (cs *CatalogService) GetCatalog() (*tokens.ServiceCatalog, error) { return catalog, nil } -// findServiceTypeEndpoints - returns all endpoints for ServiceType from endpoints catalog. +// findServiceTypeEndpoints - returns all public endpoints for ServiceType from endpoints catalog. func (cs *CatalogService) findServiceTypeEndpoints(serviceType string) ([]tokens.Endpoint, error) { for _, service := range cs.catalog.Entries { if service.Type == serviceType { - return service.Endpoints, nil + return cs.findPublicEndpoints(service.Endpoints), nil } } return nil, ErrServiceTypeNotFound } -// findRegionalEndpoint - returns one endpoint for service in the specified region. +// findPublicEndpoints - returns all public endpoints from input endpoints slice. +func (cs *CatalogService) findPublicEndpoints(endpoints []tokens.Endpoint) []tokens.Endpoint { + publicEndpoints := make([]tokens.Endpoint, 0) + + for _, endpoint := range endpoints { + if endpoint.Interface == publicInterface { + publicEndpoints = append(publicEndpoints, endpoint) + } + } + + return publicEndpoints +} + +// findRegionalEndpoint - returns single public endpoint for service in the specified region. func (cs *CatalogService) findRegionalEndpoint(endpoints []tokens.Endpoint, regionName string) (tokens.Endpoint, error) { for _, endpoint := range endpoints { if endpoint.Interface == publicInterface && endpoint.RegionID == regionName {