Skip to content

Commit a910dca

Browse files
author
Andrew Tang
authored
IMDSv2 Client Integration.
1 parent 65e50dd commit a910dca

File tree

12 files changed

+1113
-13
lines changed

12 files changed

+1113
-13
lines changed

include/aws/crt/DateTime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace Aws
5858
DateTime() noexcept;
5959

6060
/**
61-
* Initializes time point to any other arbirtrary timepoint
61+
* Initializes time point to any other arbitrary timepoint
6262
*/
6363
DateTime(const std::chrono::system_clock::time_point &timepointToAssign) noexcept;
6464

include/aws/crt/ImdsClient.h

Lines changed: 335 additions & 0 deletions
Large diffs are not rendered by default.

include/aws/crt/Types.h

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
44
* SPDX-License-Identifier: Apache-2.0.
55
*/
6+
#include <aws/common/common.h>
67
#include <aws/crt/Exports.h>
78
#include <aws/crt/Optional.h>
89
#include <aws/crt/StlAllocator.h>
9-
10-
#include <aws/common/common.h>
10+
#include <aws/crt/StringView.h>
1111
#include <aws/io/socket.h>
1212
#include <aws/mqtt/mqtt.h>
1313
#include <functional>
@@ -70,6 +70,75 @@ namespace Aws
7070
AWS_CRT_CPP_API Vector<uint8_t> Base64Decode(const String &decode);
7171
AWS_CRT_CPP_API String Base64Encode(const Vector<uint8_t> &encode);
7272

73+
template <typename RawType, typename TargetType> using TypeConvertor = std::function<TargetType(RawType)>;
74+
75+
/**
76+
* Template function to convert an aws_array_list of RawType to a C++ like Vector of TargetType.
77+
* A conversion function should be provided to do the type conversion
78+
*/
79+
template <typename RawType, typename TargetType>
80+
AWS_CRT_CPP_API Vector<TargetType> ArrayListToVector(
81+
const aws_array_list *array,
82+
TypeConvertor<RawType, TargetType> conv)
83+
{
84+
Vector<TargetType> v;
85+
size_t cnt = aws_array_list_length(array);
86+
for (size_t i = 0; i < cnt; i++)
87+
{
88+
RawType t;
89+
aws_array_list_get_at(array, &t, i);
90+
v.emplace_back(conv(t));
91+
}
92+
return v;
93+
}
94+
95+
/**
96+
* Template function to convert an aws_array_list of RawType to a C++ like Vector of TargetType.
97+
* This template assumes a direct constructor: TargetType(RawType) is available
98+
*/
99+
template <typename RawType, typename TargetType>
100+
AWS_CRT_CPP_API Vector<TargetType> ArrayListToVector(const aws_array_list *array)
101+
{
102+
Vector<TargetType> v;
103+
size_t cnt = aws_array_list_length(array);
104+
for (size_t i = 0; i < cnt; i++)
105+
{
106+
RawType t;
107+
aws_array_list_get_at(array, &t, i);
108+
v.emplace_back(TargetType(t));
109+
}
110+
return v;
111+
}
112+
113+
/**
114+
* Template function to convert an aws_array_list of Type to a C++ like Vector of Type.
115+
*/
116+
template <typename Type> AWS_CRT_CPP_API Vector<Type> ArrayListToVector(const aws_array_list *array)
117+
{
118+
Vector<Type> v;
119+
size_t cnt = aws_array_list_length(array);
120+
for (size_t i = 0; i < cnt; i++)
121+
{
122+
Type t;
123+
aws_array_list_get_at(array, &t, i);
124+
v.emplace_back(t);
125+
}
126+
return v;
127+
}
128+
129+
AWS_CRT_CPP_API inline StringView ByteCursorToStringView(const ByteCursor &bc)
130+
{
131+
return StringView(reinterpret_cast<char *>(bc.ptr), bc.len);
132+
}
133+
134+
AWS_CRT_CPP_API inline ByteCursor StringViewToByteCursor(const StringView &sv)
135+
{
136+
ByteCursor bc;
137+
bc.ptr = (uint8_t *)(sv.data());
138+
bc.len = sv.size();
139+
return bc;
140+
}
141+
73142
template <typename T> void Delete(T *t, Allocator *allocator)
74143
{
75144
t->~T();

include/aws/crt/auth/Credentials.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace Aws
3737
class AWS_CRT_CPP_API Credentials
3838
{
3939
public:
40-
Credentials(aws_credentials *credentials) noexcept;
40+
Credentials(const aws_credentials *credentials) noexcept;
4141
Credentials(
4242
ByteCursor access_key_id,
4343
ByteCursor secret_access_key,
@@ -80,10 +80,10 @@ namespace Aws
8080
/**
8181
* Returns the underlying credentials implementation.
8282
*/
83-
aws_credentials *GetUnderlyingHandle() const noexcept { return m_credentials; }
83+
const aws_credentials *GetUnderlyingHandle() const noexcept { return m_credentials; }
8484

8585
private:
86-
aws_credentials *m_credentials;
86+
const aws_credentials *m_credentials;
8787
};
8888

8989
/**

0 commit comments

Comments
 (0)