aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Loading...
Searching...
No Matches
Credentials.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/Exports.h>
8#include <aws/crt/Types.h>
11
12#include <chrono>
13#include <functional>
14
15struct aws_credentials;
16struct aws_credentials_provider;
17
18namespace Aws
19{
20 namespace Crt
21 {
22 namespace Io
23 {
24 class ClientBootstrap;
25 }
26
27 namespace Http
28 {
30 }
31
32 namespace Auth
33 {
38 {
39 public:
40 Credentials(const aws_credentials *credentials) noexcept;
42 ByteCursor access_key_id,
43 ByteCursor secret_access_key,
44 ByteCursor session_token,
45 uint64_t expiration_timepoint_in_seconds,
46 Allocator *allocator = ApiAllocator()) noexcept;
47
53 Credentials(Allocator *allocator = ApiAllocator()) noexcept;
54
56
57 Credentials(const Credentials &) = delete;
59 Credentials &operator=(const Credentials &) = delete;
61
65 ByteCursor GetAccessKeyId() const noexcept;
66
70 ByteCursor GetSecretAccessKey() const noexcept;
71
75 ByteCursor GetSessionToken() const noexcept;
76
80 uint64_t GetExpirationTimepointInSeconds() const noexcept;
81
85 ByteCursor GetAccountId() const noexcept;
86
90 explicit operator bool() const noexcept;
91
95 const aws_credentials *GetUnderlyingHandle() const noexcept { return m_credentials; }
96
97 private:
98 const aws_credentials *m_credentials;
99 };
100
105 using OnCredentialsResolved = std::function<void(std::shared_ptr<Credentials>, int errorCode)>;
106
110 using GetCredentialsHandler = std::function<std::shared_ptr<Credentials>()>;
111
116 class AWS_CRT_CPP_API ICredentialsProvider : public std::enable_shared_from_this<ICredentialsProvider>
117 {
118 public:
119 virtual ~ICredentialsProvider() = default;
120
124 virtual bool GetCredentials(const OnCredentialsResolved &onCredentialsResolved) const = 0;
125
132 virtual aws_credentials_provider *GetUnderlyingHandle() const noexcept = 0;
133
137 virtual bool IsValid() const noexcept = 0;
138 };
139
144 {
146 {
147 AWS_ZERO_STRUCT(AccessKeyId);
148 AWS_ZERO_STRUCT(SecretAccessKey);
149 AWS_ZERO_STRUCT(SessionToken);
150 }
151
156
161
166 };
167
172 {
173 CredentialsProviderProfileConfig() : Bootstrap(nullptr), TlsContext(nullptr)
174 {
175 AWS_ZERO_STRUCT(ProfileNameOverride);
176 AWS_ZERO_STRUCT(ConfigFileNameOverride);
177 AWS_ZERO_STRUCT(CredentialsFileNameOverride);
178 }
179
184
190
196
202
214
219 };
220
237
252
257 {
258 CredentialsProviderCachedConfig() : Provider(), CachedCredentialTTL() {}
259
263 std::shared_ptr<ICredentialsProvider> Provider;
264
268 std::chrono::milliseconds CachedCredentialTTL;
269 };
270
298
303 {
305 : Bootstrap(nullptr), TlsOptions(), ThingName(), RoleAlias(), Endpoint(), ProxyOptions()
306 {
307 }
308
317
318 /* TLS connection options that have been initialized with your x509 certificate and private key */
320
321 /* IoT thing name you registered with AWS IOT for your device, it will be used in http request header */
323
324 /* Iot role alias you created with AWS IoT for your IAM role, it will be used in http request path */
326
334
339 };
340
345 {
346 /* handler to provider credentials */
348 };
349
366
414
461
508
546
554 {
555 public:
556 CredentialsProvider(aws_credentials_provider *provider, Allocator *allocator = ApiAllocator()) noexcept;
557
558 virtual ~CredentialsProvider();
559
564
568 virtual bool GetCredentials(const OnCredentialsResolved &onCredentialsResolved) const override;
569
573 virtual aws_credentials_provider *GetUnderlyingHandle() const noexcept override { return m_provider; }
574
578 virtual bool IsValid() const noexcept override { return m_provider != nullptr; }
579
580 /*
581 * Factory methods for all of the basic credentials provider types
582 */
583
587 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderStatic(
589 Allocator *allocator = ApiAllocator());
590
595 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderAnonymous(
596 Allocator *allocator = ApiAllocator());
597
601 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderEnvironment(
602 Allocator *allocator = ApiAllocator());
603
607 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderProfile(
609 Allocator *allocator = ApiAllocator());
610
614 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderImds(
615 const CredentialsProviderImdsConfig &config,
616 Allocator *allocator = ApiAllocator());
617
622 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderChain(
623 const CredentialsProviderChainConfig &config,
624 Allocator *allocator = ApiAllocator());
625
626 /*
627 * Creates a provider that puts a simple time-based cache in front of its queries
628 * to a subordinate provider.
629 */
630 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderCached(
632 Allocator *allocator = ApiAllocator());
633
640 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderChainDefault(
642 Allocator *allocator = ApiAllocator());
643
648 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderX509(
649 const CredentialsProviderX509Config &config,
650 Allocator *allocator = ApiAllocator());
651
656 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderDelegate(
658 Allocator *allocator = ApiAllocator());
659
663 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderCognito(
665 Allocator *allocator = ApiAllocator());
666
670 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderSTS(
671 const CredentialsProviderSTSConfig &config,
672 Allocator *allocator = ApiAllocator());
673
674 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderSTSWebIdentity(
676 Allocator *allocator = ApiAllocator());
677
681 static std::shared_ptr<ICredentialsProvider> CreateCredentialsProviderLogin(
682 const CredentialsProviderLoginConfig &config,
683 Allocator *allocator = ApiAllocator());
684
685 private:
686 static void s_onCredentialsResolved(aws_credentials *credentials, int error_code, void *user_data);
687
688 Allocator *m_allocator;
689 aws_credentials_provider *m_provider;
690 };
691 } // namespace Auth
692 } // namespace Crt
693} // namespace Aws
#define AWS_CRT_CPP_API
Definition Exports.h:36
Definition Credentials.h:38
Credentials & operator=(Credentials &&)=delete
Credentials & operator=(const Credentials &)=delete
Credentials(const Credentials &)=delete
Credentials(Credentials &&)=delete
Definition Credentials.h:554
CredentialsProvider & operator=(CredentialsProvider &&)=delete
virtual aws_credentials_provider * GetUnderlyingHandle() const noexcept override
Definition Credentials.h:573
CredentialsProvider(const CredentialsProvider &)=delete
virtual bool IsValid() const noexcept override
Definition Credentials.h:578
CredentialsProvider(CredentialsProvider &&)=delete
CredentialsProvider & operator=(const CredentialsProvider &)=delete
Definition Credentials.h:117
virtual bool GetCredentials(const OnCredentialsResolved &onCredentialsResolved) const =0
virtual aws_credentials_provider * GetUnderlyingHandle() const noexcept=0
Definition Bootstrap.h:35
Definition TlsOptions.h:293
Definition TlsOptions.h:350
Definition Optional.h:19
std::function< void(std::shared_ptr< Credentials >, int errorCode)> OnCredentialsResolved
Definition Credentials.h:105
std::function< std::shared_ptr< Credentials >()> GetCredentialsHandler
Definition Credentials.h:110
aws_byte_cursor ByteCursor
Definition Types.h:31
aws_allocator Allocator
Definition Allocator.h:14
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition Allocator.cpp:24
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition Types.h:45
std::vector< T, StlAllocator< T > > Vector
Definition Types.h:53
Definition Allocator.h:11
Definition Credentials.h:354
String IdentityProviderName
Definition Credentials.h:359
String IdentityProviderToken
Definition Credentials.h:364
std::shared_ptr< ICredentialsProvider > Provider
Definition Credentials.h:263
CredentialsProviderCachedConfig()
Definition Credentials.h:258
std::chrono::milliseconds CachedCredentialTTL
Definition Credentials.h:268
CredentialsProviderChainConfig()
Definition Credentials.h:245
Vector< std::shared_ptr< ICredentialsProvider > > Providers
Definition Credentials.h:250
Io::TlsContext * TlsContext
Definition Credentials.h:296
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:287
CredentialsProviderChainDefaultConfig()
Definition Credentials.h:279
Optional< Vector< CognitoLoginPair > > Logins
Definition Credentials.h:387
Optional< String > CustomRoleArn
Definition Credentials.h:393
Optional< Http::HttpClientConnectionProxyOptions > ProxyOptions
Definition Credentials.h:412
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:402
String Endpoint
Definition Credentials.h:377
Io::TlsContext TlsCtx
Definition Credentials.h:407
String Identity
Definition Credentials.h:382
GetCredentialsHandler Handler
Definition Credentials.h:347
CredentialsProviderImdsConfig()
Definition Credentials.h:226
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:235
String LoginCacheOverride
Definition Credentials.h:525
Io::TlsConnectionOptions TlsConnectionOptions
Definition Credentials.h:544
String LoginRegion
Definition Credentials.h:530
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:539
String LoginSession
Definition Credentials.h:519
ByteCursor ConfigFileNameOverride
Definition Credentials.h:189
ByteCursor CredentialsFileNameOverride
Definition Credentials.h:195
ByteCursor ProfileNameOverride
Definition Credentials.h:183
Optional< Http::ProxyEnvVarOptions > ProxyEnvVarOptions
Definition Credentials.h:218
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:201
Io::TlsConnectionOptions TlsConnectionOptions
Definition Credentials.h:213
CredentialsProviderProfileConfig()
Definition Credentials.h:173
Io::TlsContext * TlsContext
Definition Credentials.h:212
Optional< Http::HttpClientConnectionProxyOptions > ProxyOptions
Definition Credentials.h:459
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:449
uint16_t DurationSeconds
Definition Credentials.h:440
std::shared_ptr< ICredentialsProvider > Provider
Definition Credentials.h:425
String SessionName
Definition Credentials.h:435
Io::TlsContext TlsCtx
Definition Credentials.h:454
String RoleArn
Definition Credentials.h:430
Io::TlsConnectionOptions TlsConnectionOptions
Definition Credentials.h:501
String TokenFilePath
Definition Credentials.h:487
Optional< Http::ProxyEnvVarOptions > ProxyEnvVarOptions
Definition Credentials.h:506
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:496
String SessionName
Definition Credentials.h:477
ByteCursor SecretAccessKey
Definition Credentials.h:160
ByteCursor AccessKeyId
Definition Credentials.h:155
CredentialsProviderStaticConfig()
Definition Credentials.h:145
ByteCursor SessionToken
Definition Credentials.h:165
Optional< Http::HttpClientConnectionProxyOptions > ProxyOptions
Definition Credentials.h:338
CredentialsProviderX509Config()
Definition Credentials.h:304
String Endpoint
Definition Credentials.h:333
String ThingName
Definition Credentials.h:322
String RoleAlias
Definition Credentials.h:325
Io::ClientBootstrap * Bootstrap
Definition Credentials.h:316
Io::TlsConnectionOptions TlsOptions
Definition Credentials.h:319