Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : #include <string> 5 : 6 : #include "envoy/common/pure.h" 7 : #include "envoy/http/message.h" 8 : #include "envoy/upstream/cluster_manager.h" 9 : 10 : #include "source/common/http/message_impl.h" 11 : #include "source/extensions/common/aws/utility.h" 12 : 13 : #include "absl/strings/string_view.h" 14 : #include "absl/types/optional.h" 15 : 16 : namespace Envoy { 17 : namespace Extensions { 18 : namespace Common { 19 : namespace Aws { 20 : 21 : class MetadataFetcher; 22 : using MetadataFetcherPtr = std::unique_ptr<MetadataFetcher>; 23 : 24 : /** 25 : * MetadataFetcher interface can be used to retrieve AWS Metadata from various providers. 26 : * An instance of this interface is designed to retrieve one AWS Metadata at a time. 27 : * The implementation of AWS Metadata Fetcher is similar to JwksFetcher. 28 : */ 29 : 30 : class MetadataFetcher { 31 : public: 32 : class MetadataReceiver { 33 : public: 34 : enum class Failure { 35 : /* A network error occurred causing AWS Metadata retrieval failure. */ 36 : Network, 37 : /* A failure occurred when trying to parse the retrieved AWS Metadata data. */ 38 : InvalidMetadata, 39 : /* A missing config causing AWS Metadata retrieval failure. */ 40 : MissingConfig, 41 : }; 42 : 43 6 : virtual ~MetadataReceiver() = default; 44 : 45 : /** 46 : * @brief Successful retrieval callback of returned AWS Metadata. 47 : * @param body Fetched AWS Metadata. 48 : */ 49 : virtual void onMetadataSuccess(const std::string&& body) PURE; 50 : 51 : /** 52 : * @brief Retrieval error callback. 53 : * @param reason the failure reason. 54 : */ 55 : virtual void onMetadataError(Failure reason) PURE; 56 : }; 57 : 58 0 : virtual ~MetadataFetcher() = default; 59 : 60 : /** 61 : * @brief Cancel any in-flight request. 62 : */ 63 : virtual void cancel() PURE; 64 : 65 : /** 66 : * @brief Retrieve a AWS Metadata from a remote HTTP host. 67 : * At most one outstanding request may be in-flight. 68 : * i.e. from the invocation of `fetch()` until either 69 : * a callback or `cancel()` is invoked, no additional 70 : * `fetch()` may be issued. The URI to fetch is to pre 71 : * determined based on the credentials provider source. 72 : * 73 : * @param receiver the receiver of the fetched AWS Metadata or error 74 : */ 75 : virtual void fetch(Http::RequestMessage& message, Tracing::Span& parent_span, 76 : MetadataReceiver& receiver) PURE; 77 : 78 : /** 79 : * @brief Return MetadataReceiver Failure enum as a string. 80 : * 81 : * @return absl::string_view 82 : */ 83 : virtual absl::string_view failureToString(MetadataReceiver::Failure) PURE; 84 : 85 : /** 86 : * @brief Factory method for creating a Metadata Fetcher. 87 : * 88 : * @param cm the cluster manager to use during AWS Metadata retrieval 89 : * @param provider the AWS Metadata provider 90 : * @return a MetadataFetcher instance 91 : */ 92 : static MetadataFetcherPtr create(Upstream::ClusterManager& cm, absl::string_view cluster_name); 93 : }; 94 : } // namespace Aws 95 : } // namespace Common 96 : } // namespace Extensions 97 : } // namespace Envoy