Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3721016
D4513.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4513.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D4513: [services] Tunnelbroker - Change in `getAwsRegion()` function to use `.aws/credentials`
Attached
Detach File
Event Timeline
Log In to Comment