Skip to content

Commit 30d6642

Browse files
Smithy reference architecture identity base APIs
1 parent e1b2513 commit 30d6642

13 files changed

+291
-0
lines changed

src/aws-cpp-sdk-core/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ file(GLOB CJSON_HEADERS "include/aws/core/external/cjson/*.h")
7474
file(GLOB TINYXML2_HEADERS "include/aws/core/external/tinyxml2/tinyxml2.h")
7575
file(GLOB SMITHY_HEADERS "include/smithy/*.h")
7676
file(GLOB SMITHY_TRACING_HEADERS "include/smithy/tracing/*.h")
77+
file(GLOB SMITHY_IDENTITY_HEADERS "include/smithy/identity/*.h")
78+
file(GLOB SMITHY_IDENTITY_IDENTITY_HEADERS "include/smithy/identity/identity/*.h" "include/smithy/identity/identity/impl/*.h")
79+
file(GLOB SMITHY_IDENTITY_RESOLVER_HEADERS "include/smithy/identity/resolver/*.h" "include/smithy/identity/resolver/impl/*.h")
7780

7881
file(GLOB AWS_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
7982
file(GLOB AWS_TINYXML2_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/external/tinyxml2/*.cpp")
@@ -106,6 +109,7 @@ file(GLOB UTILS_MEMORY_STL_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/memo
106109
file(GLOB UTILS_STREAM_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/stream/*.cpp")
107110
file(GLOB UTILS_CRYPTO_FACTORY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/crypto/factory/*.cpp")
108111
file(GLOB SMITHY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/*.cpp")
112+
file(GLOB SMITHY_IDENTITY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/identity/*.cpp")
109113
file(GLOB SMITHY_TRACING_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/tracing/*.cpp")
110114

111115
include(CheckCSourceCompiles)
@@ -283,6 +287,7 @@ file(GLOB AWS_NATIVE_SDK_COMMON_SRC
283287
${UTILS_MEMORY_STL_SOURCE}
284288
${UTILS_CRYPTO_CRT_SOURCE}
285289
${SMITHY_SOURCE}
290+
${SMITHY_IDENTITY_SOURCE}
286291
${SMITHY_TRACING_SOURCE}
287292
)
288293

@@ -324,6 +329,9 @@ file(GLOB AWS_NATIVE_SDK_COMMON_HEADERS
324329
${HTTP_WINDOWS_CLIENT_HEADERS}
325330
${SMITHY_HEADERS}
326331
${SMITHY_TRACING_HEADERS}
332+
${SMITHY_IDENTITY_HEADERS}
333+
${SMITHY_IDENTITY_IDENTITY_HEADERS}
334+
${SMITHY_IDENTITY_RESOLVER_HEADERS}
327335
${OPTEL_HEADERS}
328336
)
329337

@@ -441,6 +449,8 @@ if(MSVC)
441449
source_group("Header Files\\aws\\core\\external\\tinyxml2" FILES ${TINYXML2_HEADERS})
442450
source_group("Header Files\\smithy" FILES ${SMITHY_HEADERS})
443451
source_group("Header Files\\smithy\\tracing" FILES ${SMITHY_TRACING_HEADERS})
452+
source_group("Header Files\\smithy\\identity\\identity" FILES ${SMITHY_IDENTITY_IDENTITY_HEADERS})
453+
source_group("Header Files\\smithy\\identity\\resolver" FILES ${SMITHY_IDENTITY_RESOLVER_HEADERS})
444454

445455
# http client conditional headers
446456
if(ENABLE_CURL_CLIENT)
@@ -487,6 +497,7 @@ if(MSVC)
487497
source_group("Source Files\\utils\\component-registry" FILES ${UTILS_COMPONENT_REGISTRY_SOURCE})
488498
source_group("Source Files\\utils\\memory\\stl" FILES ${UTILS_MEMORY_STL_SOURCE})
489499
source_group("Source Files\\smithy" FILES ${SMITHY_SOURCE})
500+
source_group("Source Files\\smithy\\identity" FILES ${SMITHY_IDENTITY_SOURCE})
490501
source_group("Source Files\\smithy\\tracing" FILES ${SMITHY_TRACING_SOURCE})
491502

492503
# http client conditional source
@@ -697,6 +708,9 @@ install (FILES ${CJSON_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/extern
697708
install (FILES ${TINYXML2_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/external/tinyxml2)
698709
install (FILES ${SMITHY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy)
699710
install (FILES ${SMITHY_TRACING_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/tracing)
711+
install (FILES ${SMITHY_IDENTITY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity)
712+
install (FILES ${SMITHY_IDENTITY_IDENTITY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/identity)
713+
install (FILES ${SMITHY_IDENTITY_RESOLVER_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/resolver)
700714

701715
# android logcat headers
702716
if(PLATFORM_ANDROID)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
#include <aws/core/utils/Outcome.h>
9+
10+
namespace Aws
11+
{
12+
namespace Utils
13+
{
14+
15+
/**
16+
* Template class representing the std::future object of outcome of calling some other API.
17+
* It will contain a future of an either a successful result or the failure error.
18+
* The caller must check whether the outcome of the request was a success before attempting to access
19+
* the result or the error.
20+
*/
21+
template<typename R, typename E> // Result, Error
22+
using FutureOutcome = Aws::Utils::Outcome<R, E>;
23+
} // namespace Utils
24+
} // namespace Aws
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/identity/AwsBearerTokenIdentityBase.h>
8+
9+
namespace smithy {
10+
class AwsBearerTokenIdentity : public AwsBearerTokenIdentityBase {
11+
public:
12+
virtual Aws::String token() override;
13+
14+
virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override;
15+
16+
protected:
17+
Aws::String m_token;
18+
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
19+
};
20+
}
21+
22+
#include <smithy/identity/identity/impl/AwsBearerTokenIdentityImpl.h>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/identity/AwsIdentity.h>
8+
9+
namespace smithy {
10+
class AwsBearerTokenIdentityBase : public AwsIdentity {
11+
public:
12+
virtual Aws::String token() = 0;
13+
14+
virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override = 0 ;
15+
};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
8+
9+
namespace smithy {
10+
class AwsCredentialIdentity : public AwsCredentialIdentityBase {
11+
public:
12+
virtual Aws::String accessKeyId() override;
13+
virtual Aws::String secretAccessKey() override;
14+
virtual Aws::Crt::Optional<Aws::String> sessionToken() override;
15+
16+
virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override;
17+
18+
protected:
19+
Aws::String m_accessKeyId;
20+
Aws::String m_secretAccessKey;
21+
Aws::Crt::Optional<Aws::String> m_sessionToken;
22+
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
23+
};
24+
}
25+
26+
#include <smithy/identity/identity/impl/AwsCredentialIdentityImpl.h>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/identity/AwsIdentity.h>
8+
9+
namespace smithy {
10+
class AwsCredentialIdentityBase : public AwsIdentity {
11+
public:
12+
virtual Aws::String accessKeyId() = 0;
13+
virtual Aws::String secretAccessKey() = 0;
14+
virtual Aws::Crt::Optional<Aws::String> sessionToken() = 0;
15+
16+
virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override = 0 ;
17+
};
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <aws/crt/Optional.h>
8+
9+
#include <aws/core/utils/DateTime.h>
10+
11+
namespace smithy {
12+
class AwsIdentity {
13+
public:
14+
using DateTime = Aws::Utils::DateTime;
15+
16+
virtual ~AwsIdentity(){};
17+
virtual Aws::Crt::Optional<DateTime> expiration() {
18+
return Aws::Crt::Optional<DateTime>();
19+
};
20+
};
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
9+
10+
namespace smithy {
11+
Aws::String AwsBearerTokenIdentity::token() {
12+
return m_token;
13+
}
14+
15+
Aws::Crt::Optional<AwsIdentity::DateTime> AwsBearerTokenIdentity::expiration() {
16+
return m_expiration;
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
#include <smithy/identity/identity/AwsCredentialIdentity.h>
9+
10+
namespace smithy {
11+
Aws::String AwsCredentialIdentity::accessKeyId() {
12+
return m_accessKeyId;
13+
}
14+
15+
Aws::String AwsCredentialIdentity::secretAccessKey() {
16+
return m_secretAccessKey;
17+
}
18+
19+
Aws::Crt::Optional<Aws::String> AwsCredentialIdentity::sessionToken() {
20+
return m_sessionToken;
21+
}
22+
23+
Aws::Crt::Optional<AwsIdentity::DateTime> AwsCredentialIdentity::expiration() {
24+
return m_expiration;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>
8+
9+
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
10+
11+
namespace smithy {
12+
class AwsBearerTokenIdentityResolver : public IdentityResolverBase<AwsBearerTokenIdentity> {
13+
public:
14+
using IdentityT = AwsBearerTokenIdentity;
15+
virtual ~AwsBearerTokenIdentityResolver() = default;
16+
17+
virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
18+
};
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>
8+
9+
#include <smithy/identity/identity/AwsCredentialIdentity.h>
10+
11+
namespace smithy {
12+
class AwsCredentialIdentityResolver : public IdentityResolverBase<AwsCredentialIdentity> {
13+
public:
14+
using IdentityT = AwsCredentialIdentity;
15+
virtual ~AwsCredentialIdentityResolver() = default;
16+
17+
virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
18+
};
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <aws/crt/Optional.h>
8+
#include <aws/crt/Variant.h>
9+
10+
#include <aws/core/client/CoreErrors.h>
11+
#include <aws/core/utils/FutureOutcome.h>
12+
13+
#include <aws/core/utils/memory/stl/AWSString.h>
14+
#include <aws/core/utils/memory/stl/AWSMap.h>
15+
16+
#include <aws/core/utils/DateTime.h>
17+
18+
namespace smithy {
19+
template<typename IDENTITY_T>
20+
class IdentityResolverBase {
21+
public:
22+
using IdentityT = IDENTITY_T;
23+
24+
virtual ~IdentityResolverBase(){};
25+
26+
using IdentityProperties = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
27+
// IdentityResolvers are asynchronous.
28+
using ResolveIdentityFutureOutcome = Aws::Utils::FutureOutcome<IdentityT, Aws::Client::AWSError<Aws::Client::CoreErrors>>;
29+
using AdditionalParameters = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
30+
31+
// Each Identity has one or more identity resolvers that are able to load the customer’s
32+
// Identity. An identity resolver might load the identity from a remote service (e.g. STS), a local
33+
// service (e.g. IMDS), local disk (e.g. a configuration file) or local memory (e.g. environment variables).
34+
virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
35+
};
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/identity/AwsIdentity.h>
8+
9+
#include <aws/crt/Variant.h>
10+
#include <aws/core/client/AWSError.h>
11+
#include <aws/core/http/HttpRequest.h>
12+
#include <aws/core/utils/FutureOutcome.h>
13+
#include <aws/core/utils/memory/stl/AWSMap.h>
14+
15+
16+
namespace smithy {
17+
template<typename IDENTITY_T>
18+
class AwsSignerBase {
19+
public:
20+
using IdentityT = IDENTITY_T;
21+
static_assert(std::is_base_of<AwsIdentity, IDENTITY_T>::value_type, "Identity type should inherit AwsIdentity");
22+
using SigningProperties = Aws::UnorderedMap<Aws::String, Aws::String>;
23+
using AdditionalParameters = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
24+
using HttpRequest = Aws::Http::HttpRequest;
25+
using SigningFutureOutcome = Aws::Utils::FutureOutcome<HttpRequest, Aws::Client::AWSError<Aws::Client::CoreErrors>>;
26+
27+
28+
virtual SigningFutureOutcome sign(const HttpRequest& httpRequest, const IdentityT& identity, SigningProperties properties, const AdditionalParameters& additionalParameters) = 0;
29+
30+
virtual ~AwsSignerBase(){};
31+
};
32+
}

0 commit comments

Comments
 (0)