diff --git a/wxdata/include/scwx/util/environment.hpp b/wxdata/include/scwx/util/environment.hpp new file mode 100644 index 00000000..e90b8515 --- /dev/null +++ b/wxdata/include/scwx/util/environment.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace scwx +{ +namespace util +{ + +void SetEnvironment(const std::string& name, const std::string& value); + +} // namespace util +} // namespace scwx diff --git a/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp b/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp index c23e1e25..7745a502 100644 --- a/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp +++ b/wxdata/source/scwx/provider/aws_nexrad_data_provider.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -51,6 +52,9 @@ public: lastModified_ {}, updatePeriod_ {} { + // Disable HTTP request for region + util::SetEnvironment("AWS_EC2_METADATA_DISABLED", "true"); + Aws::Client::ClientConfiguration config; config.region = region_; diff --git a/wxdata/source/scwx/util/environment.cpp b/wxdata/source/scwx/util/environment.cpp new file mode 100644 index 00000000..0958a395 --- /dev/null +++ b/wxdata/source/scwx/util/environment.cpp @@ -0,0 +1,31 @@ +#include +#include + +#ifndef _WIN32 +# include +#endif + +namespace scwx +{ +namespace util +{ + +static const std::string logPrefix_ {"scwx::util::environment"}; +static const auto logger_ = util::Logger::Create(logPrefix_); + +void SetEnvironment(const std::string& name, const std::string& value) +{ +#ifdef _WIN32 + errno_t error = _putenv_s(name.c_str(), value.c_str()); +#else + int error = setenv(name.c_str(), value.c_str(), 1); +#endif + + if (error != 0) + { + logger_->warn("Could not set environment variable: {}={}", name, value); + } +} + +} // namespace util +} // namespace scwx diff --git a/wxdata/wxdata.cmake b/wxdata/wxdata.cmake index f1d63f0f..4adbc60d 100644 --- a/wxdata/wxdata.cmake +++ b/wxdata/wxdata.cmake @@ -44,7 +44,8 @@ set(SRC_PROVIDER source/scwx/provider/aws_level2_data_provider.cpp source/scwx/provider/aws_nexrad_data_provider.cpp source/scwx/provider/nexrad_data_provider.cpp source/scwx/provider/nexrad_data_provider_factory.cpp) -set(HDR_UTIL include/scwx/util/float.hpp +set(HDR_UTIL include/scwx/util/environment.hpp + include/scwx/util/float.hpp include/scwx/util/iterator.hpp include/scwx/util/logger.hpp include/scwx/util/map.hpp @@ -53,7 +54,8 @@ set(HDR_UTIL include/scwx/util/float.hpp include/scwx/util/threads.hpp include/scwx/util/time.hpp include/scwx/util/vectorbuf.hpp) -set(SRC_UTIL source/scwx/util/float.cpp +set(SRC_UTIL source/scwx/util/environment.cpp + source/scwx/util/float.cpp source/scwx/util/logger.cpp source/scwx/util/rangebuf.cpp source/scwx/util/streams.cpp