AWS SDK for C++  1.8.55
AWS SDK for C++
AWSCredentialsProvider.h
Go to the documentation of this file.
1 
7 #pragma once
8 
19 #include <memory>
20 
21 namespace Aws
22 {
23  namespace Auth
24  {
25  constexpr int REFRESH_THRESHOLD = 1000 * 60 * 5;
26 
30  AWS_CORE_API Aws::String GetConfigProfileFilename(); //defaults to "config"
31 
39  AWS_CORE_API Aws::String GetConfigProfileName(); //defaults to "default"
40 
41  /*
42  * Fetches credentials by executing the process in the parameter
43  */
45 
51  {
52  public:
57  AWSCredentialsProvider() : m_lastLoadedMs(0)
58  {
59  }
60 
61  virtual ~AWSCredentialsProvider() = default;
62 
66  virtual AWSCredentials GetAWSCredentials() = 0;
67 
68  protected:
73  virtual bool IsTimeToRefresh(long reloadFrequency);
74  virtual void Reload();
76  private:
77  long long m_lastLoadedMs;
78  };
79 
85  {
86  public:
90  inline AWSCredentials GetAWSCredentials() override { return AWSCredentials(); }
91  };
92 
99  {
100  public:
104  inline SimpleAWSCredentialsProvider(const Aws::String& awsAccessKeyId, const Aws::String& awsSecretAccessKey, const Aws::String& sessionToken = "")
105  : m_credentials(awsAccessKeyId, awsSecretAccessKey, sessionToken)
106  { }
107 
111  inline SimpleAWSCredentialsProvider(const AWSCredentials& credentials)
112  : m_credentials(credentials)
113  { }
114 
119  {
120  return m_credentials;
121  }
122 
123  private:
124  AWSCredentials m_credentials;
125  };
126 
132  {
133  public:
138  AWSCredentials GetAWSCredentials() override;
139  };
140 
149  {
150  public:
151 
155  ProfileConfigFileAWSCredentialsProvider(long refreshRateMs = REFRESH_THRESHOLD);
156 
161  ProfileConfigFileAWSCredentialsProvider(const char* profile, long refreshRateMs = REFRESH_THRESHOLD);
162 
166  AWSCredentials GetAWSCredentials() override;
167 
171  static Aws::String GetCredentialsProfileFilename();
172 
176  static Aws::String GetProfileDirectory();
177 
178  protected:
179  void Reload() override;
180  private:
181 
185  void RefreshIfExpired();
186 
187  Aws::String m_profileToUse;
188  Aws::Config::AWSConfigFileProfileConfigLoader m_credentialsFileLoader;
189  long m_loadFrequencyMs;
190  };
191 
197  {
198  public:
203  InstanceProfileCredentialsProvider(long refreshRateMs = REFRESH_THRESHOLD);
204 
209  InstanceProfileCredentialsProvider(const std::shared_ptr<Aws::Config::EC2InstanceProfileConfigLoader>&, long refreshRateMs = REFRESH_THRESHOLD);
210 
214  AWSCredentials GetAWSCredentials() override;
215 
216  protected:
217  void Reload() override;
218 
219  private:
220  void RefreshIfExpired();
221 
222  std::shared_ptr<Aws::Config::AWSProfileConfigLoader> m_ec2MetadataConfigLoader;
223  long m_loadFrequencyMs;
224  };
225 
231  {
232  public:
239  TaskRoleCredentialsProvider(const char* resourcePath, long refreshRateMs = REFRESH_THRESHOLD);
240 
248  TaskRoleCredentialsProvider(const char* endpoint, const char* token, long refreshRateMs = REFRESH_THRESHOLD);
249 
255  TaskRoleCredentialsProvider(const std::shared_ptr<Aws::Internal::ECSCredentialsClient>& client,
256  long refreshRateMs = REFRESH_THRESHOLD);
260  AWSCredentials GetAWSCredentials() override;
261 
262  protected:
263  void Reload() override;
264  private:
265  bool ExpiresSoon() const;
266  void RefreshIfExpired();
267 
268  private:
269  std::shared_ptr<Aws::Internal::ECSCredentialsClient> m_ecsCredentialsClient;
270  long m_loadFrequencyMs;
271  Aws::Auth::AWSCredentials m_credentials;
272  };
273 
288  {
289  public:
294 
299  ProcessCredentialsProvider(const Aws::String& profile);
300 
304  AWSCredentials GetAWSCredentials() override;
305 
306  protected:
307  void Reload() override;
308  private:
309  void RefreshIfExpired();
310 
311  private:
312  Aws::String m_profileToUse;
313  Aws::Auth::AWSCredentials m_credentials;
314  };
315  } // namespace Auth
316 } // namespace Aws
AWS_CORE_API AWSCredentials GetCredentialsFromProcess(const Aws::String &process)
constexpr int REFRESH_THRESHOLD
Aws::Utils::Threading::ReaderWriterLock m_reloadLock
SimpleAWSCredentialsProvider(const AWSCredentials &credentials)
AWS_CORE_API Aws::String GetConfigProfileName()
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
AWS_CORE_API Aws::String GetConfigProfileFilename()
SimpleAWSCredentialsProvider(const Aws::String &awsAccessKeyId, const Aws::String &awsSecretAccessKey, const Aws::String &sessionToken="")
#define AWS_CORE_API
Definition: Core_EXPORTS.h:25