AWS IoT Device SDK C++ v2  1.34.0
AWS IoT Device SDK C++ v2
ImdsClient.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <aws/crt/DateTime.h>
8 #include <aws/crt/Exports.h>
9 #include <aws/crt/Types.h>
10 #include <functional>
11 
12 struct aws_credentials;
13 struct aws_imds_client;
14 struct aws_imds_instance_info;
15 struct aws_imds_iam_profile;
16 
17 namespace 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 
37  {
38  ImdsClientConfig() : Bootstrap(nullptr) {}
39 
48 
49  /* Should add retry strategy support once that is available */
50  };
51 
56  {
60  };
61 
66  {
68  IamProfile(const IamProfileView &other);
69 
70  IamProfile &operator=(const IamProfileView &other);
71 
75  };
76 
83  {
84  /* an array of StringView */
90  /* an array of StringView */
100  };
101 
106  {
108  InstanceInfo(const InstanceInfoView &other);
109 
110  InstanceInfo &operator=(const InstanceInfoView &other);
111 
112  /* an array of StringView */
118  /* an array of StringView */
128  };
129 
130  using OnResourceAcquired = std::function<void(const StringView &resource, int errorCode, void *userData)>;
132  std::function<void(const Vector<StringView> &resource, int errorCode, void *userData)>;
134  std::function<void(const Auth::Credentials &credentials, int errorCode, void *userData)>;
136  std::function<void(const IamProfileView &iamProfile, int errorCode, void *userData)>;
138  std::function<void(const InstanceInfoView &instanceInfo, int errorCode, void *userData)>;
139 
141  {
142  public:
143  ImdsClient(const ImdsClientConfig &config, Allocator *allocator = ApiAllocator()) noexcept;
144 
145  ~ImdsClient();
146 
147  ImdsClient(const ImdsClient &) = delete;
148  ImdsClient(ImdsClient &&) = delete;
149  ImdsClient &operator=(const ImdsClient &) = delete;
151 
152  aws_imds_client *GetUnderlyingHandle() { return m_client; }
153 
162  int GetResource(const StringView &resourcePath, OnResourceAcquired callback, void *userData);
163 
171  int GetAmiId(OnResourceAcquired callback, void *userData);
172 
180  int GetAmiLaunchIndex(OnResourceAcquired callback, void *userData);
181 
189  int GetAmiManifestPath(OnResourceAcquired callback, void *userData);
190 
198  int GetAncestorAmiIds(OnVectorResourceAcquired callback, void *userData);
199 
207  int GetInstanceAction(OnResourceAcquired callback, void *userData);
208 
216  int GetInstanceId(OnResourceAcquired callback, void *userData);
217 
225  int GetInstanceType(OnResourceAcquired callback, void *userData);
226 
234  int GetMacAddress(OnResourceAcquired callback, void *userData);
235 
243  int GetPrivateIpAddress(OnResourceAcquired callback, void *userData);
244 
252  int GetAvailabilityZone(OnResourceAcquired callback, void *userData);
253 
261  int GetProductCodes(OnResourceAcquired callback, void *userData);
262 
270  int GetPublicKey(OnResourceAcquired callback, void *userData);
271 
279  int GetRamDiskId(OnResourceAcquired callback, void *userData);
280 
288  int GetReservationId(OnResourceAcquired callback, void *userData);
289 
297  int GetSecurityGroups(OnVectorResourceAcquired callback, void *userData);
298 
306  int GetBlockDeviceMapping(OnVectorResourceAcquired callback, void *userData);
307 
315  int GetAttachedIamRole(OnResourceAcquired callback, void *userData);
316 
325  int GetCredentials(const StringView &iamRoleName, OnCredentialsAcquired callback, void *userData);
326 
334  int GetIamProfile(OnIamProfileAcquired callback, void *userData);
335 
343  int GetUserData(OnResourceAcquired callback, void *userData);
344 
352  int GetInstanceSignature(OnResourceAcquired callback, void *userData);
353 
361  int GetInstanceInfo(OnInstanceInfoAcquired callback, void *userData);
362 
363  private:
364  static void s_onResourceAcquired(const aws_byte_buf *resource, int erroCode, void *userData);
365 
366  static void s_onVectorResourceAcquired(const aws_array_list *array, int errorCode, void *userData);
367 
368  static void s_onCredentialsAcquired(const aws_credentials *credentials, int errorCode, void *userData);
369 
370  static void s_onIamProfileAcquired(
371  const aws_imds_iam_profile *iamProfileInfo,
372  int errorCode,
373  void *userData);
374 
375  static void s_onInstanceInfoAcquired(
376  const aws_imds_instance_info *instanceInfo,
377  int error_code,
378  void *userData);
379 
380  aws_imds_client *m_client;
381  Allocator *m_allocator;
382  };
383 
384  } // namespace Imds
385  } // namespace Crt
386 } // namespace Aws
Aws::Crt::Imds::InstanceInfoView::billingProducts
Vector< StringView > billingProducts
Definition: ImdsClient.h:91
Aws::Crt::Imds::InstanceInfo::InstanceInfo
InstanceInfo()
Definition: ImdsClient.h:107
Aws::Crt::Imds::InstanceInfo::privateIp
String privateIp
Definition: ImdsClient.h:115
Aws::Crt::Imds::InstanceInfo::accountId
String accountId
Definition: ImdsClient.h:121
Aws::Crt::Imds::OnCredentialsAcquired
std::function< void(const Auth::Credentials &credentials, int errorCode, void *userData)> OnCredentialsAcquired
Definition: ImdsClient.h:134
Aws::Crt::Imds::InstanceInfo::imageId
String imageId
Definition: ImdsClient.h:122
Aws::Crt::Imds::InstanceInfoView::instanceType
StringView instanceType
Definition: ImdsClient.h:92
Aws::Crt::Imds::IamProfileView::lastUpdated
DateTime lastUpdated
Definition: ImdsClient.h:57
Aws::Crt::ApiAllocator
AWS_CRT_CPP_API Allocator * ApiAllocator() noexcept
Definition: Allocator.cpp:24
Aws::Crt::Imds::ImdsClientConfig::ImdsClientConfig
ImdsClientConfig()
Definition: ImdsClient.h:38
Aws::Crt::Imds::ImdsClientConfig
Definition: ImdsClient.h:37
Aws::Crt::Imds::InstanceInfoView::kernelId
StringView kernelId
Definition: ImdsClient.h:97
DateTime.h
Aws::Crt::Imds::ImdsClient::ImdsClient
ImdsClient(const ImdsClient &)=delete
Aws::Crt::Imds::OnVectorResourceAcquired
std::function< void(const Vector< StringView > &resource, int errorCode, void *userData)> OnVectorResourceAcquired
Definition: ImdsClient.h:132
Aws::Crt::Imds::InstanceInfoView::instanceId
StringView instanceId
Definition: ImdsClient.h:89
Aws::Crt::Imds::InstanceInfoView::pendingTime
DateTime pendingTime
Definition: ImdsClient.h:95
Aws::Crt::Imds::InstanceInfoView::privateIp
StringView privateIp
Definition: ImdsClient.h:87
Aws::Crt::Imds::InstanceInfo::instanceType
String instanceType
Definition: ImdsClient.h:120
Aws::Crt::Imds::OnIamProfileAcquired
std::function< void(const IamProfileView &iamProfile, int errorCode, void *userData)> OnIamProfileAcquired
Definition: ImdsClient.h:136
Aws::Crt::Imds::InstanceInfoView::architecture
StringView architecture
Definition: ImdsClient.h:96
Aws::Crt::Imds::InstanceInfoView::accountId
StringView accountId
Definition: ImdsClient.h:93
Aws::Crt::Imds::ImdsClient
Definition: ImdsClient.h:141
Aws::Crt::Imds::ImdsClient::operator=
ImdsClient & operator=(ImdsClient &&)=delete
Aws::Crt::Imds::IamProfileView::instanceProfileId
StringView instanceProfileId
Definition: ImdsClient.h:59
Aws::Crt::Imds::InstanceInfo::instanceId
String instanceId
Definition: ImdsClient.h:117
Aws::Crt::Imds::InstanceInfo::ramdiskId
String ramdiskId
Definition: ImdsClient.h:126
Aws::Crt::Imds::ImdsClientConfig::Bootstrap
Io::ClientBootstrap * Bootstrap
Definition: ImdsClient.h:47
Aws::Crt::Imds::InstanceInfoView::availabilityZone
StringView availabilityZone
Definition: ImdsClient.h:86
Aws::Crt::Imds::IamProfile::instanceProfileArn
String instanceProfileArn
Definition: ImdsClient.h:73
Aws::Crt::Imds::ImdsClient::ImdsClient
ImdsClient(ImdsClient &&)=delete
Aws::Crt::Imds::OnInstanceInfoAcquired
std::function< void(const InstanceInfoView &instanceInfo, int errorCode, void *userData)> OnInstanceInfoAcquired
Definition: ImdsClient.h:138
Aws::Crt::Imds::InstanceInfo
Definition: ImdsClient.h:106
Aws::Crt::Imds::InstanceInfoView::version
StringView version
Definition: ImdsClient.h:88
Aws::Crt::Imds::IamProfileView::instanceProfileArn
StringView instanceProfileArn
Definition: ImdsClient.h:58
Aws::Crt::Imds::IamProfile::lastUpdated
DateTime lastUpdated
Definition: ImdsClient.h:72
Aws::Crt::Imds::IamProfile
Definition: ImdsClient.h:66
Aws::Crt::Imds::InstanceInfoView
Definition: ImdsClient.h:83
Aws::Crt::Imds::InstanceInfo::version
String version
Definition: ImdsClient.h:116
Aws::Crt::Imds::ImdsClient::operator=
ImdsClient & operator=(const ImdsClient &)=delete
Aws::Crt::Imds::InstanceInfo::pendingTime
DateTime pendingTime
Definition: ImdsClient.h:123
Types.h
Aws::Crt::Imds::InstanceInfo::region
String region
Definition: ImdsClient.h:127
Aws::Crt::DateTime
Definition: DateTime.h:53
Aws::Crt::Imds::InstanceInfoView::marketplaceProductCodes
Vector< StringView > marketplaceProductCodes
Definition: ImdsClient.h:85
Aws::Crt::Imds::IamProfileView
Definition: ImdsClient.h:56
Aws::Crt::Vector
std::vector< T, StlAllocator< T > > Vector
Definition: Types.h:53
Aws::Crt::basic_string_view
Definition: StringView.h:33
Aws::Crt::Auth::Credentials
Definition: Credentials.h:38
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Imds::InstanceInfo::architecture
String architecture
Definition: ImdsClient.h:124
Aws::Crt::Imds::InstanceInfoView::imageId
StringView imageId
Definition: ImdsClient.h:94
Aws
Definition: Allocator.h:11
Aws::Crt::Imds::OnResourceAcquired
std::function< void(const StringView &resource, int errorCode, void *userData)> OnResourceAcquired
Definition: ImdsClient.h:130
Aws::Crt::Imds::InstanceInfo::kernelId
String kernelId
Definition: ImdsClient.h:125
Aws::Crt::Imds::InstanceInfo::availabilityZone
String availabilityZone
Definition: ImdsClient.h:114
Aws::Crt::Imds::InstanceInfoView::ramdiskId
StringView ramdiskId
Definition: ImdsClient.h:98
Aws::Crt::Allocator
aws_allocator Allocator
Definition: Allocator.h:14
Exports.h
Aws::Crt::Io::ClientBootstrap
Definition: Bootstrap.h:35
Aws::Crt::Imds::InstanceInfo::marketplaceProductCodes
Vector< String > marketplaceProductCodes
Definition: ImdsClient.h:113
Aws::Crt::Imds::InstanceInfo::billingProducts
Vector< String > billingProducts
Definition: ImdsClient.h:119
Aws::Crt::Imds::IamProfile::instanceProfileId
String instanceProfileId
Definition: ImdsClient.h:74
Aws::Crt::String
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > String
Definition: Types.h:45
Aws::Crt::Imds::IamProfile::IamProfile
IamProfile()
Definition: ImdsClient.h:67
Aws::Crt::Imds::InstanceInfoView::region
StringView region
Definition: ImdsClient.h:99
Aws::Crt::Imds::ImdsClient::GetUnderlyingHandle
aws_imds_client * GetUnderlyingHandle()
Definition: ImdsClient.h:152