Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : #include <string> 5 : 6 : #include "envoy/common/pure.h" 7 : 8 : #include "absl/strings/string_view.h" 9 : #include "absl/types/optional.h" 10 : 11 : namespace Envoy { 12 : namespace Extensions { 13 : namespace Common { 14 : namespace Aws { 15 : 16 : /** 17 : * AWS credentials container 18 : * 19 : * If a credential component was not found in the execution environment, it's getter method will 20 : * return absl::nullopt. Credential components with the empty string value are treated as not found. 21 : */ 22 : class Credentials { 23 : public: 24 : explicit Credentials(absl::string_view access_key_id = absl::string_view(), 25 : absl::string_view secret_access_key = absl::string_view(), 26 34 : absl::string_view session_token = absl::string_view()) { 27 : // TODO(suniltheta): Move credential expiration date in here 28 34 : if (!access_key_id.empty()) { 29 0 : access_key_id_ = std::string(access_key_id); 30 0 : if (!secret_access_key.empty()) { 31 0 : secret_access_key_ = std::string(secret_access_key); 32 0 : if (!session_token.empty()) { 33 0 : session_token_ = std::string(session_token); 34 0 : } 35 0 : } 36 0 : } 37 34 : } 38 : 39 20 : const absl::optional<std::string>& accessKeyId() const { return access_key_id_; } 40 : 41 0 : const absl::optional<std::string>& secretAccessKey() const { return secret_access_key_; } 42 : 43 0 : const absl::optional<std::string>& sessionToken() const { return session_token_; } 44 : 45 0 : bool operator==(const Credentials& other) const { 46 0 : return access_key_id_ == other.access_key_id_ && 47 0 : secret_access_key_ == other.secret_access_key_ && session_token_ == other.session_token_; 48 0 : } 49 : 50 : private: 51 : absl::optional<std::string> access_key_id_; 52 : absl::optional<std::string> secret_access_key_; 53 : absl::optional<std::string> session_token_; 54 : }; 55 : 56 : /** 57 : * Interface for classes able to fetch AWS credentials from the execution environment. 58 : */ 59 : class CredentialsProvider { 60 : public: 61 24 : virtual ~CredentialsProvider() = default; 62 : 63 : /** 64 : * Get credentials from the environment. 65 : * 66 : * @return AWS credentials 67 : */ 68 : virtual Credentials getCredentials() PURE; 69 : }; 70 : 71 : using CredentialsConstSharedPtr = std::shared_ptr<const Credentials>; 72 : using CredentialsConstUniquePtr = std::unique_ptr<const Credentials>; 73 : using CredentialsProviderSharedPtr = std::shared_ptr<CredentialsProvider>; 74 : 75 : } // namespace Aws 76 : } // namespace Common 77 : } // namespace Extensions 78 : } // namespace Envoy