Skip to content

Commit

Permalink
Smithy reference architecture identity base APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Mar 21, 2024
1 parent 53259b8 commit ffea689
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/aws-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ file(GLOB CJSON_HEADERS "include/aws/core/external/cjson/*.h")
file(GLOB TINYXML2_HEADERS "include/aws/core/external/tinyxml2/tinyxml2.h")
file(GLOB SMITHY_HEADERS "include/smithy/*.h")
file(GLOB SMITHY_TRACING_HEADERS "include/smithy/tracing/*.h")
file(GLOB SMITHY_IDENTITY_HEADERS "include/smithy/identity/*.h")
file(GLOB SMITHY_IDENTITY_IDENTITY_HEADERS "include/smithy/identity/identity/*.h" "include/smithy/identity/identity/impl/*.h")
file(GLOB SMITHY_IDENTITY_RESOLVER_HEADERS "include/smithy/identity/resolver/*.h" "include/smithy/identity/resolver/impl/*.h")

file(GLOB AWS_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
file(GLOB AWS_TINYXML2_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/external/tinyxml2/*.cpp")
Expand Down Expand Up @@ -106,6 +109,7 @@ file(GLOB UTILS_MEMORY_STL_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/memo
file(GLOB UTILS_STREAM_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/stream/*.cpp")
file(GLOB UTILS_CRYPTO_FACTORY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/utils/crypto/factory/*.cpp")
file(GLOB SMITHY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/*.cpp")
file(GLOB SMITHY_IDENTITY_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/identity/*.cpp")
file(GLOB SMITHY_TRACING_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/source/smithy/tracing/*.cpp")

include(CheckCSourceCompiles)
Expand Down Expand Up @@ -271,6 +275,7 @@ file(GLOB AWS_NATIVE_SDK_COMMON_SRC
${UTILS_CRYPTO_OPENSSL_SOURCE}
${UTILS_CRYPTO_COMMONCRYPTO_SOURCE}
${SMITHY_SOURCE}
${SMITHY_IDENTITY_SOURCE}
${SMITHY_TRACING_SOURCE}
)

Expand Down Expand Up @@ -315,6 +320,9 @@ file(GLOB AWS_NATIVE_SDK_COMMON_HEADERS
${UTILS_CRYPTO_COMMONCRYPTO_HEADERS}
${SMITHY_HEADERS}
${SMITHY_TRACING_HEADERS}
${SMITHY_IDENTITY_HEADERS}
${SMITHY_IDENTITY_IDENTITY_HEADERS}
${SMITHY_IDENTITY_RESOLVER_HEADERS}
${OPTEL_HEADERS}
)

Expand Down Expand Up @@ -431,6 +439,8 @@ if(MSVC)
source_group("Header Files\\aws\\core\\external\\tinyxml2" FILES ${TINYXML2_HEADERS})
source_group("Header Files\\smithy" FILES ${SMITHY_HEADERS})
source_group("Header Files\\smithy\\tracing" FILES ${SMITHY_TRACING_HEADERS})
source_group("Header Files\\smithy\\identity\\identity" FILES ${SMITHY_IDENTITY_IDENTITY_HEADERS})
source_group("Header Files\\smithy\\identity\\resolver" FILES ${SMITHY_IDENTITY_RESOLVER_HEADERS})

# http client conditional headers
if(ENABLE_CURL_CLIENT)
Expand Down Expand Up @@ -487,6 +497,7 @@ if(MSVC)
source_group("Source Files\\utils\\component-registry" FILES ${UTILS_COMPONENT_REGISTRY_SOURCE})
source_group("Source Files\\utils\\memory\\stl" FILES ${UTILS_MEMORY_STL_SOURCE})
source_group("Source Files\\smithy" FILES ${SMITHY_SOURCE})
source_group("Source Files\\smithy\\identity" FILES ${SMITHY_IDENTITY_SOURCE})
source_group("Source Files\\smithy\\tracing" FILES ${SMITHY_TRACING_SOURCE})

# http client conditional source
Expand Down Expand Up @@ -688,6 +699,9 @@ install (FILES ${CJSON_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/extern
install (FILES ${TINYXML2_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/aws/core/external/tinyxml2)
install (FILES ${SMITHY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy)
install (FILES ${SMITHY_TRACING_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/tracing)
install (FILES ${SMITHY_IDENTITY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity)
install (FILES ${SMITHY_IDENTITY_IDENTITY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/identity)
install (FILES ${SMITHY_IDENTITY_RESOLVER_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/resolver)

# android logcat headers
if(PLATFORM_ANDROID)
Expand Down
24 changes: 24 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/utils/FutureOutcome.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <aws/core/utils/Outcome.h>

namespace Aws
{
namespace Utils
{

/**
* Template class representing the std::future object of outcome of calling some other API.
* It will contain a future of an either a successful result or the failure error.
* The caller must check whether the outcome of the request was a success before attempting to access
* the result or the error.
*/
template<typename R, typename E> // Result, Error
using FutureOutcome = Aws::Utils::Outcome<R, E>;
} // namespace Utils
} // namespace Aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/identity/AwsBearerTokenIdentityBase.h>

namespace smithy {
class AwsBearerTokenIdentity : public AwsBearerTokenIdentityBase {
public:
virtual Aws::String token() override;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override;

protected:
Aws::String m_token;
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
};
}

#include <smithy/identity/identity/impl/AwsBearerTokenIdentityImpl.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/identity/AwsIdentity.h>

namespace smithy {
class AwsBearerTokenIdentityBase : public AwsIdentity {
public:
virtual Aws::String token() = 0;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override = 0 ;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/identity/AwsCredentialIdentityBase.h>

namespace smithy {
class AwsCredentialIdentity : public AwsCredentialIdentityBase {
public:
virtual Aws::String accessKeyId() override;
virtual Aws::String secretAccessKey() override;
virtual Aws::Crt::Optional<Aws::String> sessionToken() override;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override;

protected:
Aws::String m_accessKeyId;
Aws::String m_secretAccessKey;
Aws::Crt::Optional<Aws::String> m_sessionToken;
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
};
}

#include <smithy/identity/identity/impl/AwsCredentialIdentityImpl.h>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/identity/AwsIdentity.h>

namespace smithy {
class AwsCredentialIdentityBase : public AwsIdentity {
public:
virtual Aws::String accessKeyId() = 0;
virtual Aws::String secretAccessKey() = 0;
virtual Aws::Crt::Optional<Aws::String> sessionToken() = 0;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() override = 0 ;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <aws/crt/Optional.h>

#include <aws/core/utils/DateTime.h>

namespace smithy {
class AwsIdentity {
public:
using DateTime = Aws::Utils::DateTime;

virtual ~AwsIdentity(){};
virtual Aws::Crt::Optional<DateTime> expiration() {
return Aws::Crt::Optional<DateTime>();
};
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <smithy/identity/identity/AwsBearerTokenIdentity.h>

namespace smithy {
Aws::String AwsBearerTokenIdentity::token() {
return m_token;
}

Aws::Crt::Optional<AwsIdentity::DateTime> AwsBearerTokenIdentity::expiration() {
return m_expiration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <smithy/identity/identity/AwsCredentialIdentity.h>

namespace smithy {
Aws::String AwsCredentialIdentity::accessKeyId() {
return m_accessKeyId;
}

Aws::String AwsCredentialIdentity::secretAccessKey() {
return m_secretAccessKey;
}

Aws::Crt::Optional<Aws::String> AwsCredentialIdentity::sessionToken() {
return m_sessionToken;
}

Aws::Crt::Optional<AwsIdentity::DateTime> AwsCredentialIdentity::expiration() {
return m_expiration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/resolver/AwsIdentityResolverBase.h>

#include <smithy/identity/identity/AwsBearerTokenIdentity.h>

namespace smithy {
class AwsBearerTokenIdentityResolver : public IdentityResolverBase<AwsBearerTokenIdentity> {
public:
using IdentityT = AwsBearerTokenIdentity;
virtual ~AwsBearerTokenIdentityResolver() = default;

virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/resolver/AwsIdentityResolverBase.h>

#include <smithy/identity/identity/AwsCredentialIdentity.h>

namespace smithy {
class AwsCredentialIdentityResolver : public IdentityResolverBase<AwsCredentialIdentity> {
public:
using IdentityT = AwsCredentialIdentity;
virtual ~AwsCredentialIdentityResolver() = default;

virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <aws/crt/Optional.h>
#include <aws/crt/Variant.h>

#include <aws/core/client/CoreErrors.h>
#include <aws/core/utils/FutureOutcome.h>

#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>

#include <aws/core/utils/DateTime.h>

namespace smithy {
template<typename IDENTITY_T>
class IdentityResolverBase {
public:
using IdentityT = IDENTITY_T;

virtual ~IdentityResolverBase(){};

using IdentityProperties = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
// IdentityResolvers are asynchronous.
using ResolveIdentityFutureOutcome = Aws::Utils::FutureOutcome<IdentityT, Aws::Client::AWSError<Aws::Client::CoreErrors>>;
using AdditionalParameters = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;

// Each Identity has one or more identity resolvers that are able to load the customer’s
// Identity. An identity resolver might load the identity from a remote service (e.g. STS), a local
// service (e.g. IMDS), local disk (e.g. a configuration file) or local memory (e.g. environment variables).
virtual ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) = 0;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#pragma once

#include <smithy/identity/identity/AwsIdentity.h>

#include <aws/crt/Variant.h>
#include <aws/core/client/AWSError.h>
#include <aws/core/http/HttpRequest.h>
#include <aws/core/utils/FutureOutcome.h>
#include <aws/core/utils/memory/stl/AWSMap.h>


namespace smithy {
template<typename IDENTITY_T>
class AwsSignerBase {
public:
using IdentityT = IDENTITY_T;
static_assert(std::is_base_of<AwsIdentity, IDENTITY_T>::value_type, "Identity type should inherit AwsIdentity");
using SigningProperties = Aws::UnorderedMap<Aws::String, Aws::String>;
using AdditionalParameters = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
using HttpRequest = Aws::Http::HttpRequest;
using SigningFutureOutcome = Aws::Utils::FutureOutcome<HttpRequest, Aws::Client::AWSError<Aws::Client::CoreErrors>>;


virtual SigningFutureOutcome sign(const HttpRequest& httpRequest, const IdentityT& identity, SigningProperties properties, const AdditionalParameters& additionalParameters) = 0;

virtual ~AwsSignerBase(){};
};
}

0 comments on commit ffea689

Please sign in to comment.