Skip to content

Commit 16e1212

Browse files
Use service name for client's base URL (#1361)
Required for usage with DSP in order to not confuse different endpoints. This is an ugly hack. Relates-To: OAM-1783 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent 0bf7868 commit 16e1212

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 HERE Europe B.V.
2+
* Copyright (C) 2020-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,11 +55,21 @@ OlpClient CreateClient(const std::string& base_url,
5555

5656
olp::client::OlpClient GetStaticUrl(
5757
const olp::client::HRN& catalog,
58-
const olp::client::OlpClientSettings& settings) {
58+
const olp::client::OlpClientSettings& settings,
59+
const std::string& service) {
5960
const auto& provider = settings.api_lookup_settings.catalog_endpoint_provider;
6061
if (provider) {
6162
auto url = provider(catalog);
6263
if (!url.empty()) {
64+
if (!service.empty()) {
65+
// Ugly hack since blob service is the only place where URL component is
66+
// different from the API name
67+
if (service == "blob") {
68+
url += "/blobstore";
69+
} else {
70+
url += '/' + service;
71+
}
72+
}
6373
url += "/catalogs/" + catalog.ToCatalogHRNString();
6474
return CreateClient(url, settings);
6575
}
@@ -97,7 +107,7 @@ ApiLookupClientImpl::ApiLookupClientImpl(const HRN& catalog,
97107
ApiLookupClient::LookupApiResponse ApiLookupClientImpl::LookupApi(
98108
const std::string& service, const std::string& service_version,
99109
FetchOptions options, CancellationContext context) {
100-
auto result_client = GetStaticUrl(catalog_, settings_);
110+
auto result_client = GetStaticUrl(catalog_, settings_, service);
101111
if (!result_client.GetBaseUrl().empty()) {
102112
return result_client;
103113
}
@@ -155,7 +165,7 @@ ApiLookupClient::LookupApiResponse ApiLookupClientImpl::LookupApi(
155165
CancellationToken ApiLookupClientImpl::LookupApi(
156166
const std::string& service, const std::string& service_version,
157167
FetchOptions options, ApiLookupClient::LookupApiCallback callback) {
158-
auto result_client = GetStaticUrl(catalog_, settings_);
168+
auto result_client = GetStaticUrl(catalog_, settings_, service);
159169
if (!result_client.GetBaseUrl().empty()) {
160170
callback(result_client);
161171
return CancellationToken();

olp-cpp-sdk-core/tests/client/ApiLookupClientImplTest.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 HERE Europe B.V.
2+
* Copyright (C) 2020-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -470,7 +470,8 @@ TEST_F(ApiLookupClientImplTest, CustomCatalogProvider) {
470470
const std::string service_url = "http://random_service.com";
471471
const std::string service_version = "v8";
472472
const std::string provider_url = "https://some-lookup-url.com/lookup/v1";
473-
const std::string static_base_url = provider_url + "/catalogs/" + catalog;
473+
const std::string static_base_url =
474+
provider_url + '/' + service_name + "/catalogs/" + catalog;
474475
const std::string lookup_url =
475476
"https://api-lookup.data.api.platform.here.com/lookup/v1/resources/" +
476477
catalog + "/apis";
@@ -922,7 +923,8 @@ TEST_F(ApiLookupClientImplTest, CustomCatalogProviderAsync) {
922923
const std::string service_url = "http://random_service.com";
923924
const std::string service_version = "v8";
924925
const std::string provider_url = "https://some-lookup-url.com/lookup/v1";
925-
const std::string static_base_url = provider_url + "/catalogs/" + catalog;
926+
const std::string static_base_url =
927+
provider_url + '/' + service_name + "/catalogs/" + catalog;
926928
const std::string lookup_url =
927929
"https://api-lookup.data.api.platform.here.com/lookup/v1/resources/" +
928930
catalog + "/apis";

tests/common/PlatformUrlsGenerator.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 HERE Europe B.V.
2+
* Copyright (C) 2020-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,16 @@
2525
#include <olp/dataservice/read/model/VersionResponse.h>
2626
#include "ApiDefaultResponses.h"
2727

28+
namespace {
29+
std::string GetUrlForService(const std::string& service) {
30+
if (service == "blob") {
31+
return "/blobstore";
32+
}
33+
34+
return '/' + service;
35+
}
36+
} // namespace
37+
2838
PlatformUrlsGenerator::PlatformUrlsGenerator(olp::client::Apis apis,
2939
const std::string& layer)
3040
: apis_(std::make_shared<olp::client::Apis>(apis)), layer_(layer) {}
@@ -104,7 +114,7 @@ std::string PlatformUrlsGenerator::FullPath(const std::string& service,
104114
}
105115
url = "/" + service + "/" + v + "/catalogs/" + catalog_;
106116
} else {
107-
url = http_prefix_ + "/catalogs/" + catalog_;
117+
url = http_prefix_ + GetUrlForService(service) + "/catalogs/" + catalog_;
108118
}
109119
} else {
110120
auto it = find_if(apis_->begin(), apis_->end(), [&](olp::client::Api api) {

tests/integration/olp-cpp-sdk-core/ApiLookupClientTest.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 HERE Europe B.V.
2+
* Copyright (C) 2020-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -634,7 +634,8 @@ TEST_F(ApiLookupClientTest, CustomCatalogProvider) {
634634
const std::string service_url = "http://random_service.com";
635635
const std::string service_version = "v8";
636636
const std::string provider_url = "https://some-lookup-url.com/lookup/v1";
637-
const std::string static_base_url = provider_url + "/catalogs/" + catalog;
637+
const std::string static_base_url =
638+
provider_url + '/' + service_name + "/catalogs/" + catalog;
638639
const std::string lookup_url =
639640
"https://api-lookup.data.api.platform.here.com/lookup/v1/resources/" +
640641
catalog + "/apis";
@@ -692,7 +693,8 @@ TEST_F(ApiLookupClientTest, CustomCatalogProviderAsync) {
692693
const std::string service_url = "http://random_service.com";
693694
const std::string service_version = "v8";
694695
const std::string provider_url = "https://some-lookup-url.com/lookup/v1";
695-
const std::string static_base_url = provider_url + "/catalogs/" + catalog;
696+
const std::string static_base_url =
697+
provider_url + '/' + service_name + "/catalogs/" + catalog;
696698
const std::string lookup_url =
697699
"https://api-lookup.data.api.platform.here.com/lookup/v1/resources/" +
698700
catalog + "/apis";

tests/integration/olp-cpp-sdk-dataservice-read/CatalogClientCacheTest.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2022 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -170,11 +170,13 @@ TEST_P(CatalogClientCacheTest, GetCatalog) {
170170
TEST_P(CatalogClientCacheTest, GetCatalogUsingCatalogEndpointProvider) {
171171
olp::client::HRN hrn(GetTestCatalog());
172172

173+
std::string service_name = "/config";
173174
std::string provider_url =
174175
"https://api-lookup.data.api.platform.here.com/lookup/v1";
175-
EXPECT_CALL(*network_mock_, Send(IsGetRequest(provider_url + "/catalogs/" +
176-
hrn.ToCatalogHRNString()),
177-
_, _, _, _))
176+
EXPECT_CALL(*network_mock_,
177+
Send(IsGetRequest(provider_url + service_name + "/catalogs/" +
178+
hrn.ToCatalogHRNString()),
179+
_, _, _, _))
178180
.WillOnce(::testing::Return(
179181
olp::http::SendOutcome(olp::http::ErrorCode::SUCCESS)));
180182

0 commit comments

Comments
 (0)