AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/ImdsClient.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

ImdsClient.h
Go to the documentation of this file.
1#pragma once
7#include <aws/crt/DateTime.h>
8#include <aws/crt/Exports.h>
9#include <aws/crt/Types.h>
10#include <functional>
11
12struct aws_credentials;
13struct aws_imds_client;
14struct aws_imds_instance_info;
15struct aws_imds_iam_profile;
16
17namespace Aws
18{
19
20 namespace Crt
21 {
22
23 namespace Io
24 {
25 class ClientBootstrap;
26 }
27
28 namespace Auth
29 {
30 class Credentials;
31 }
32
33 namespace Imds
34 {
35
36 struct AWS_CRT_CPP_API ImdsClientConfig
37 {
38 ImdsClientConfig() : Bootstrap(nullptr) {}
39
44 Io::ClientBootstrap *Bootstrap;
45
46 /* Should add retry strategy support once that is available */
47 };
48
52 struct AWS_CRT_CPP_API IamProfileView
53 {
54 DateTime lastUpdated;
55 StringView instanceProfileArn;
56 StringView instanceProfileId;
57 };
58
62 struct AWS_CRT_CPP_API IamProfile
63 {
64 IamProfile() {}
65 IamProfile(const IamProfileView &other);
66
67 IamProfile &operator=(const IamProfileView &other);
68
69 DateTime lastUpdated;
70 String instanceProfileArn;
71 String instanceProfileId;
72 };
73
79 struct AWS_CRT_CPP_API InstanceInfoView
80 {
81 /* an array of StringView */
82 Vector<StringView> marketplaceProductCodes;
83 StringView availabilityZone;
84 StringView privateIp;
85 StringView version;
86 StringView instanceId;
87 /* an array of StringView */
88 Vector<StringView> billingProducts;
89 StringView instanceType;
90 StringView accountId;
91 StringView imageId;
92 DateTime pendingTime;
93 StringView architecture;
94 StringView kernelId;
95 StringView ramdiskId;
96 StringView region;
97 };
98
102 struct AWS_CRT_CPP_API InstanceInfo
103 {
104 InstanceInfo() {}
105 InstanceInfo(const InstanceInfoView &other);
106
107 InstanceInfo &operator=(const InstanceInfoView &other);
108
109 /* an array of StringView */
110 Vector<String> marketplaceProductCodes;
111 String availabilityZone;
112 String privateIp;
113 String version;
114 String instanceId;
115 /* an array of StringView */
116 Vector<String> billingProducts;
117 String instanceType;
118 String accountId;
119 String imageId;
120 DateTime pendingTime;
121 String architecture;
122 String kernelId;
123 String ramdiskId;
124 String region;
125 };
126
127 using OnResourceAcquired = std::function<void(const StringView &resource, int errorCode, void *userData)>;
128 using OnVectorResourceAcquired =
129 std::function<void(const Vector<StringView> &resource, int errorCode, void *userData)>;
130 using OnCredentialsAcquired =
131 std::function<void(const Auth::Credentials &credentials, int errorCode, void *userData)>;
132 using OnIamProfileAcquired =
133 std::function<void(const IamProfileView &iamProfile, int errorCode, void *userData)>;
134 using OnInstanceInfoAcquired =
135 std::function<void(const InstanceInfoView &instanceInfo, int errorCode, void *userData)>;
136
137 class AWS_CRT_CPP_API ImdsClient
138 {
139 public:
140 ImdsClient(const ImdsClientConfig &config, Allocator *allocator = g_allocator) noexcept;
141
142 ~ImdsClient();
143
144 ImdsClient(const ImdsClient &) = delete;
145 ImdsClient(ImdsClient &&) = delete;
146 ImdsClient &operator=(const ImdsClient &) = delete;
147 ImdsClient &operator=(ImdsClient &&) = delete;
148
149 aws_imds_client *GetUnderlyingHandle() { return m_client; }
150
159 int GetResource(const StringView &resourcePath, OnResourceAcquired callback, void *userData);
160
168 int GetAmiId(OnResourceAcquired callback, void *userData);
169
177 int GetAmiLaunchIndex(OnResourceAcquired callback, void *userData);
178
186 int GetAmiManifestPath(OnResourceAcquired callback, void *userData);
187
195 int GetAncestorAmiIds(OnVectorResourceAcquired callback, void *userData);
196
204 int GetInstanceAction(OnResourceAcquired callback, void *userData);
205
213 int GetInstanceId(OnResourceAcquired callback, void *userData);
214
222 int GetInstanceType(OnResourceAcquired callback, void *userData);
223
231 int GetMacAddress(OnResourceAcquired callback, void *userData);
232
240 int GetPrivateIpAddress(OnResourceAcquired callback, void *userData);
241
249 int GetAvailabilityZone(OnResourceAcquired callback, void *userData);
250
258 int GetProductCodes(OnResourceAcquired callback, void *userData);
259
267 int GetPublicKey(OnResourceAcquired callback, void *userData);
268
276 int GetRamDiskId(OnResourceAcquired callback, void *userData);
277
285 int GetReservationId(OnResourceAcquired callback, void *userData);
286
294 int GetSecurityGroups(OnVectorResourceAcquired callback, void *userData);
295
303 int GetBlockDeviceMapping(OnVectorResourceAcquired callback, void *userData);
304
312 int GetAttachedIamRole(OnResourceAcquired callback, void *userData);
313
322 int GetCredentials(const StringView &iamRoleName, OnCredentialsAcquired callback, void *userData);
323
331 int GetIamProfile(OnIamProfileAcquired callback, void *userData);
332
340 int GetUserData(OnResourceAcquired callback, void *userData);
341
349 int GetInstanceSignature(OnResourceAcquired callback, void *userData);
350
358 int GetInstanceInfo(OnInstanceInfoAcquired callback, void *userData);
359
360 private:
361 static void s_onResourceAcquired(const aws_byte_buf *resource, int erroCode, void *userData);
362
363 static void s_onVectorResourceAcquired(const aws_array_list *array, int errorCode, void *userData);
364
365 static void s_onCredentialsAcquired(const aws_credentials *credentials, int errorCode, void *userData);
366
367 static void s_onIamProfileAcquired(
368 const aws_imds_iam_profile *iamProfileInfo,
369 int errorCode,
370 void *userData);
371
372 static void s_onInstanceInfoAcquired(
373 const aws_imds_instance_info *instanceInfo,
374 int error_code,
375 void *userData);
376
377 aws_imds_client *m_client;
378 Allocator *m_allocator;
379 };
380
381 } // namespace Imds
382 } // namespace Crt
383} // namespace Aws
DateTime.h
Types.h
Aws::Crt::Auth::Credentials
Definition: Credentials.h:38
Aws::Crt::DateTime
Definition: DateTime.h:53
Aws::Crt::Imds::ImdsClient
Definition: ImdsClient.h:138
Aws::Crt::Imds::ImdsClient::ImdsClient
ImdsClient(ImdsClient &&)=delete
Aws::Crt::Imds::ImdsClient::GetUnderlyingHandle
aws_imds_client * GetUnderlyingHandle()
Definition: ImdsClient.h:149
Aws::Crt::Imds::ImdsClient::operator=
ImdsClient & operator=(ImdsClient &&)=delete
Aws::Crt::Imds::ImdsClient::ImdsClient
ImdsClient(const ImdsClient &)=delete
Aws::Crt::Imds::ImdsClient::operator=
ImdsClient & operator=(const ImdsClient &)=delete
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::basic_string_view
Definition: StringView.h:32
Exports.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Imds::OnResourceAcquired
std::function< void(const StringView &resource, int errorCode, void *userData)> OnResourceAcquired
Definition: ImdsClient.h:127
Aws::Crt::Imds::OnVectorResourceAcquired
std::function< void(const Vector< StringView > &resource, int errorCode, void *userData)> OnVectorResourceAcquired
Definition: ImdsClient.h:129
Aws::Crt::Imds::OnCredentialsAcquired
std::function< void(const Auth::Credentials &credentials, int errorCode, void *userData)> OnCredentialsAcquired
Definition: ImdsClient.h:131
Aws::Crt::Imds::OnInstanceInfoAcquired
std::function< void(const InstanceInfoView &instanceInfo, int errorCode, void *userData)> OnInstanceInfoAcquired
Definition: ImdsClient.h:135
Aws::Crt::Imds::OnIamProfileAcquired
std::function< void(const IamProfileView &iamProfile, int errorCode, void *userData)> OnIamProfileAcquired
Definition: ImdsClient.h:133
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::g_allocator
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:47
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:55
Aws
Definition: Api.h:17
Aws::Crt::Imds::IamProfile
Definition: ImdsClient.h:63
Aws::Crt::Imds::IamProfile::lastUpdated
DateTime lastUpdated
Definition: ImdsClient.h:69
Aws::Crt::Imds::IamProfile::instanceProfileArn
String instanceProfileArn
Definition: ImdsClient.h:70
Aws::Crt::Imds::IamProfile::IamProfile
IamProfile()
Definition: ImdsClient.h:64
Aws::Crt::Imds::IamProfile::instanceProfileId
String instanceProfileId
Definition: ImdsClient.h:71
Aws::Crt::Imds::IamProfileView
Definition: ImdsClient.h:53
Aws::Crt::Imds::IamProfileView::lastUpdated
DateTime lastUpdated
Definition: ImdsClient.h:54
Aws::Crt::Imds::IamProfileView::instanceProfileArn
StringView instanceProfileArn
Definition: ImdsClient.h:55
Aws::Crt::Imds::IamProfileView::instanceProfileId
StringView instanceProfileId
Definition: ImdsClient.h:56
Aws::Crt::Imds::ImdsClientConfig
Definition: ImdsClient.h:37
Aws::Crt::Imds::ImdsClientConfig::Bootstrap
Io::ClientBootstrap * Bootstrap
Definition: ImdsClient.h:44
Aws::Crt::Imds::ImdsClientConfig::ImdsClientConfig
ImdsClientConfig()
Definition: ImdsClient.h:38
Aws::Crt::Imds::InstanceInfo
Definition: ImdsClient.h:103
Aws::Crt::Imds::InstanceInfo::availabilityZone
String availabilityZone
Definition: ImdsClient.h:111
Aws::Crt::Imds::InstanceInfo::marketplaceProductCodes
Vector< String > marketplaceProductCodes
Definition: ImdsClient.h:110
Aws::Crt::Imds::InstanceInfo::region
String region
Definition: ImdsClient.h:124
Aws::Crt::Imds::InstanceInfo::imageId
String imageId
Definition: ImdsClient.h:119
Aws::Crt::Imds::InstanceInfo::instanceType
String instanceType
Definition: ImdsClient.h:117
Aws::Crt::Imds::InstanceInfo::version
String version
Definition: ImdsClient.h:113
Aws::Crt::Imds::InstanceInfo::ramdiskId
String ramdiskId
Definition: ImdsClient.h:123
Aws::Crt::Imds::InstanceInfo::privateIp
String privateIp
Definition: ImdsClient.h:112
Aws::Crt::Imds::InstanceInfo::InstanceInfo
InstanceInfo()
Definition: ImdsClient.h:104
Aws::Crt::Imds::InstanceInfo::architecture
String architecture
Definition: ImdsClient.h:121
Aws::Crt::Imds::InstanceInfo::instanceId
String instanceId
Definition: ImdsClient.h:114
Aws::Crt::Imds::InstanceInfo::billingProducts
Vector< String > billingProducts
Definition: ImdsClient.h:116
Aws::Crt::Imds::InstanceInfo::accountId
String accountId
Definition: ImdsClient.h:118
Aws::Crt::Imds::InstanceInfo::kernelId
String kernelId
Definition: ImdsClient.h:122
Aws::Crt::Imds::InstanceInfo::pendingTime
DateTime pendingTime
Definition: ImdsClient.h:120
Aws::Crt::Imds::InstanceInfoView
Definition: ImdsClient.h:80
Aws::Crt::Imds::InstanceInfoView::marketplaceProductCodes
Vector< StringView > marketplaceProductCodes
Definition: ImdsClient.h:82
Aws::Crt::Imds::InstanceInfoView::ramdiskId
StringView ramdiskId
Definition: ImdsClient.h:95
Aws::Crt::Imds::InstanceInfoView::imageId
StringView imageId
Definition: ImdsClient.h:91
Aws::Crt::Imds::InstanceInfoView::privateIp
StringView privateIp
Definition: ImdsClient.h:84
Aws::Crt::Imds::InstanceInfoView::region
StringView region
Definition: ImdsClient.h:96
Aws::Crt::Imds::InstanceInfoView::version
StringView version
Definition: ImdsClient.h:85
Aws::Crt::Imds::InstanceInfoView::kernelId
StringView kernelId
Definition: ImdsClient.h:94
Aws::Crt::Imds::InstanceInfoView::billingProducts
Vector< StringView > billingProducts
Definition: ImdsClient.h:88
Aws::Crt::Imds::InstanceInfoView::architecture
StringView architecture
Definition: ImdsClient.h:93
Aws::Crt::Imds::InstanceInfoView::instanceType
StringView instanceType
Definition: ImdsClient.h:89
Aws::Crt::Imds::InstanceInfoView::instanceId
StringView instanceId
Definition: ImdsClient.h:86
Aws::Crt::Imds::InstanceInfoView::availabilityZone
StringView availabilityZone
Definition: ImdsClient.h:83
Aws::Crt::Imds::InstanceInfoView::accountId
StringView accountId
Definition: ImdsClient.h:90
Aws::Crt::Imds::InstanceInfoView::pendingTime
DateTime pendingTime
Definition: ImdsClient.h:92