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

Allow configuring the host address binding for the local resource API. #171

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ MetadataAgent::~MetadataAgent() {}

void MetadataAgent::Start() {
metadata_api_server_.reset(new MetadataApiServer(
config_, &health_checker_, store_, config_.MetadataApiNumThreads(), "0.0.0.0",
config_.MetadataApiPort()));
config_, &health_checker_, store_, config_.MetadataApiNumThreads(),
config_.MetadataApiHostAddress(), config_.MetadataApiPort()));
reporter_.reset(new MetadataReporter(
config_, &store_, config_.MetadataReporterIntervalSeconds()));
}
Expand Down
5 changes: 5 additions & 0 deletions src/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ constexpr const char kDefaultProjectId[] = "";
constexpr const char kDefaultCredentialsFile[] = "";
constexpr const int kMetadataApiDefaultNumThreads = 3;
constexpr const int kMetadataApiDefaultPort = 8000;
constexpr const char kMetadataApiDefaultHostAddress[] = "0.0.0.0";
constexpr const char kMetadataApiDefaultResourceTypeSeparator[] = ".";
constexpr const int kMetadataReporterDefaultIntervalSeconds = 60;
constexpr const int kMetadataReporterDefaultPurgeDeleted = false;
Expand Down Expand Up @@ -85,6 +86,7 @@ Configuration::Configuration()
verbose_logging_(false),
metadata_api_num_threads_(kMetadataApiDefaultNumThreads),
metadata_api_port_(kMetadataApiDefaultPort),
metadata_api_host_address_(kMetadataApiDefaultHostAddress),
metadata_api_resource_type_separator_(
kMetadataApiDefaultResourceTypeSeparator),
metadata_reporter_interval_seconds_(
Expand Down Expand Up @@ -222,6 +224,9 @@ void Configuration::ParseConfiguration(std::istream& input) {
config["MetadataApiNumThreads"].as<int>(metadata_api_num_threads_);
metadata_api_port_ =
config["MetadataApiPort"].as<int>(metadata_api_port_);
metadata_api_host_address_ =
config["MetadataApiHostAddress"].as<std::string>(
metadata_api_host_address_);
metadata_api_resource_type_separator_ =
config["MetadataApiResourceTypeSeparator"].as<std::string>(
metadata_api_resource_type_separator_);
Expand Down
5 changes: 5 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Configuration {
std::lock_guard<std::mutex> lock(mutex_);
return metadata_api_port_;
}
const std::string& MetadataApiHostAddress() const {
std::lock_guard<std::mutex> lock(mutex_);
return metadata_api_host_address_;
}
const std::string& MetadataApiResourceTypeSeparator() const {
std::lock_guard<std::mutex> lock(mutex_);
return metadata_api_resource_type_separator_;
Expand Down Expand Up @@ -186,6 +190,7 @@ class Configuration {
bool verbose_logging_;
int metadata_api_num_threads_;
int metadata_api_port_;
std::string metadata_api_host_address_;
std::string metadata_api_resource_type_separator_;
int metadata_reporter_interval_seconds_;
bool metadata_reporter_purge_deleted_;
Expand Down
1 change: 1 addition & 0 deletions test/configuration_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void VerifyDefaultConfig(const Configuration& config) {
EXPECT_EQ("", config.CredentialsFile());
EXPECT_EQ(3, config.MetadataApiNumThreads());
EXPECT_EQ(8000, config.MetadataApiPort());
EXPECT_EQ("0.0.0.0", config.MetadataApiHostAddress());
EXPECT_EQ(".", config.MetadataApiResourceTypeSeparator());
EXPECT_EQ(60, config.MetadataReporterIntervalSeconds());
EXPECT_EQ(false, config.MetadataReporterPurgeDeleted());
Expand Down