Page MenuHomePhabricator

D4513.diff
No OneTemporary

D4513.diff

diff --git a/services/tunnelbroker/src/Tools/AwsTools.h b/services/tunnelbroker/src/Tools/AwsTools.h
--- a/services/tunnelbroker/src/Tools/AwsTools.h
+++ b/services/tunnelbroker/src/Tools/AwsTools.h
@@ -10,7 +10,7 @@
namespace comm {
namespace network {
-Aws::String getAwsRegion();
+Aws::String getAwsRegionFromCredentials();
} // namespace network
} // namespace comm
diff --git a/services/tunnelbroker/src/Tools/AwsTools.cpp b/services/tunnelbroker/src/Tools/AwsTools.cpp
--- a/services/tunnelbroker/src/Tools/AwsTools.cpp
+++ b/services/tunnelbroker/src/Tools/AwsTools.cpp
@@ -1,19 +1,38 @@
#include "AwsTools.h"
#include "Constants.h"
+#include <boost/program_options.hpp>
+
+#include <fstream>
+
namespace comm {
namespace network {
-Aws::String getAwsRegion() {
- auto profileName = Aws::Auth::GetConfigProfileName();
- if (Aws::Config::HasCachedConfigProfile(profileName)) {
- auto profile = Aws::Config::GetCachedConfigProfile(profileName);
- Aws::String profileRegion = profile.GetRegion();
- if (!profileRegion.empty()) {
- return profileRegion;
- }
+Aws::String getAwsRegionFromCredentials() {
+ const std::string regionParameter = "default.region";
+ const std::string awsCredentialsPath = "~/.aws/credentials";
+ std::ifstream fileStream;
+ fileStream.open(awsCredentialsPath, std::ifstream::in);
+ if (!fileStream.is_open()) {
+ throw std::runtime_error(
+ "Error: can not open AWS credentials file " + awsCredentialsPath);
}
- return {};
+
+ boost::program_options::options_description optionDescription{
+ "AWS credentials options"};
+ optionDescription.add_options()(
+ regionParameter.c_str(),
+ boost::program_options::value<std::string>(),
+ "AWS region");
+
+ boost::program_options::parsed_options parsedDescription =
+ boost::program_options::parse_config_file(
+ fileStream, optionDescription, true);
+ boost::program_options::variables_map variablesMap;
+ boost::program_options::store(parsedDescription, variablesMap);
+ boost::program_options::notify(variablesMap);
+ fileStream.close();
+ return variablesMap[regionParameter].as<std::string>();
}
} // namespace network

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 9, 1:04 PM (9 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2835199
Default Alt Text
D4513.diff (2 KB)

Event Timeline