-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Added AWS region provider #7172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| #include "absl/types/optional.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| /** | ||
| * Interface for classes capable of discovering the AWS region from the execution environment. | ||
| */ | ||
| class RegionProvider { | ||
| public: | ||
| virtual ~RegionProvider() = default; | ||
|
|
||
| /** | ||
| * Discover and return the AWS region. | ||
| * @return AWS region, or nullopt if unable to discover the region. | ||
| */ | ||
| virtual absl::optional<std::string> getRegion() PURE; | ||
| }; | ||
|
|
||
| typedef std::shared_ptr<RegionProvider> RegionProviderSharedPtr; | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include "extensions/filters/http/common/aws/region_provider_impl.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| static const char AWS_REGION[] = "AWS_REGION"; | ||
|
|
||
| StaticRegionProvider::StaticRegionProvider(const std::string& region) : region_(region) {} | ||
|
|
||
| absl::optional<std::string> StaticRegionProvider::getRegion() { | ||
| return absl::optional<std::string>(region_); | ||
| } | ||
|
|
||
| absl::optional<std::string> EnvironmentRegionProvider::getRegion() { | ||
| const auto region = std::getenv(AWS_REGION); | ||
| if (region == nullptr) { | ||
| return absl::nullopt; | ||
| } | ||
| ENVOY_LOG(debug, "Found environment region {}={}", AWS_REGION, region); | ||
| return absl::optional<std::string>(region); | ||
| } | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #pragma once | ||
|
|
||
| #include "common/common/logger.h" | ||
|
|
||
| #include "extensions/filters/http/common/aws/region_provider.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| /** | ||
| * Retrieve AWS region name from the environment | ||
| */ | ||
| class EnvironmentRegionProvider : public RegionProvider, public Logger::Loggable<Logger::Id::aws> { | ||
| public: | ||
| absl::optional<std::string> getRegion() override; | ||
| }; | ||
|
|
||
| /** | ||
| * Return statically configured AWS region name | ||
| */ | ||
| class StaticRegionProvider : public RegionProvider { | ||
|
||
| public: | ||
| StaticRegionProvider(const std::string& region); | ||
|
|
||
| absl::optional<std::string> getRegion() override; | ||
|
|
||
| private: | ||
| const std::string region_; | ||
| }; | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "extensions/filters/http/common/aws/region_provider_impl.h" | ||
|
|
||
| #include "test/test_common/environment.h" | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Common { | ||
| namespace Aws { | ||
|
|
||
| class EnvironmentRegionProviderTest : public testing::Test { | ||
| public: | ||
| virtual ~EnvironmentRegionProviderTest() { TestEnvironment::unsetEnvVar("AWS_REGION"); } | ||
|
|
||
| EnvironmentRegionProvider provider_; | ||
| }; | ||
|
|
||
| class StaticRegionProviderTest : public testing::Test { | ||
| public: | ||
| StaticRegionProviderTest() : provider_("test-region") {} | ||
|
|
||
| StaticRegionProvider provider_; | ||
| }; | ||
|
|
||
| TEST_F(EnvironmentRegionProviderTest, SomeRegion) { | ||
| TestEnvironment::setEnvVar("AWS_REGION", "test-region", 1); | ||
| EXPECT_EQ("test-region", provider_.getRegion().value()); | ||
| } | ||
|
|
||
| TEST_F(EnvironmentRegionProviderTest, NoRegion) { EXPECT_FALSE(provider_.getRegion().has_value()); } | ||
|
|
||
| TEST_F(StaticRegionProviderTest, SomeRegion) { | ||
| EXPECT_EQ("test-region", provider_.getRegion().value()); | ||
| } | ||
|
|
||
| } // namespace Aws | ||
| } // namespace Common | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a TODO to figure out some way for extensions to register new logger IDs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been looking at these PRs but just wanted to note that in #5580 we decided to not add aws: #5580 (comment)
So I'm surprised this got back in. @ivitjuk It would make sense to have the sigv4 signer use it again since the logging the signer does it very AWS-specific.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. I'll make a PR to switch signer to the AWS logger.