Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Commit 035d02c

Browse files
committed
Update the location format for GCP resources.
1 parent 0cc6a47 commit 035d02c

1 file changed

Lines changed: 6 additions & 20 deletions

File tree

src/reporter.cc

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "reporter.h"
1818

19-
#include <boost/algorithm/string/split.hpp>
2019
#define BOOST_NETWORK_ENABLE_HTTPS
2120
#include <boost/network/protocol/http/client.hpp>
2221

@@ -34,10 +33,8 @@ constexpr const char kMultipartBoundary[] = "publishMultipartPost";
3433
constexpr const char kPublishPathFormat[] =
3534
"/v1beta3/projects/{{project_id}}/resourceMetadata:publish";
3635

37-
constexpr const char kRegionalLocationFormat[] =
38-
"//cloud.google.com/locations/regions/{{region}}";
39-
constexpr const char kZonalLocationFormat[] =
40-
"//cloud.google.com/locations/regions/{{region}}/zones/{{zone}}";
36+
constexpr const char kGcpLocationFormat[] =
37+
"//cloud.google.com/locations/{{location_type}}/{{location}}";
4138

4239
MetadataReporter::MetadataReporter(const Configuration& config,
4340
MetadataStore* store, double period_s)
@@ -176,22 +173,11 @@ void SendMetadataRequest(std::vector<json::value>&& entries,
176173

177174
const std::string MetadataReporter::FullyQualifiedResourceLocation(
178175
const std::string location) const {
179-
180176
int num_dashes = std::count(location.begin(), location.end(), '-');
181-
if (num_dashes == 2) {
182-
// location is a zone.
183-
std::vector<std::string> dash_split;
184-
boost::algorithm::split(
185-
dash_split, location, boost::algorithm::is_any_of("-"));
186-
const std::string region = dash_split[0] + "-" + dash_split[1];
187-
return format::Substitute(std::string(kZonalLocationFormat),
188-
{{"region", region}, {"zone", location}});
189-
190-
} else {
191-
// location is a region.
192-
return format::Substitute(std::string(kRegionalLocationFormat),
193-
{{"region", location}});
194-
}
177+
const std::string location_type = num_dashes == 2 ? "zones" : "regions";
178+
return format::Substitute(
179+
std::string(kGcpLocationFormat),
180+
{{"location_type", location_type}, {"location", location}});
195181
}
196182

197183
void MetadataReporter::SendMetadata(

0 commit comments

Comments
 (0)