1
#pragma once
2

            
3
#include "source/common/secret/secret_provider_impl.h"
4

            
5
namespace Envoy {
6
namespace Extensions {
7
namespace Http {
8
namespace InjectedCredentials {
9
namespace Common {
10
// Helper class used to fetch secrets (usually from SDS).
11
class SecretReader {
12
public:
13
106
  virtual ~SecretReader() = default;
14
  virtual const std::string& credential() const PURE;
15
};
16

            
17
using SecretReaderConstSharedPtr = std::shared_ptr<const SecretReader>;
18

            
19
class SDSSecretReader : public SecretReader {
20
public:
21
  SDSSecretReader(Secret::GenericSecretConfigProviderSharedPtr secret_provider,
22
                  ThreadLocal::SlotAllocator& tls, Api::Api& api)
23
66
      : credential_(THROW_OR_RETURN_VALUE(
24
            Secret::ThreadLocalGenericSecretProvider::create(std::move(secret_provider), tls, api),
25
66
            std::unique_ptr<Secret::ThreadLocalGenericSecretProvider>)) {}
26
160
  const std::string& credential() const override { return credential_->secret(); }
27

            
28
private:
29
  std::unique_ptr<Secret::ThreadLocalGenericSecretProvider> credential_;
30
};
31

            
32
} // namespace Common
33
} // namespace InjectedCredentials
34
} // namespace Http
35
} // namespace Extensions
36
} // namespace Envoy