Skip to content

Commit

Permalink
Smithy client operation request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Jul 25, 2024
1 parent 2b5a550 commit 59eeba3
Show file tree
Hide file tree
Showing 44 changed files with 2,119 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ namespace Aws {
return m_expiration;
}

String accessKeyId() override
String accessKeyId() const override
{
return getAccessKeyId();
}

String secretAccessKey() override
String secretAccessKey() const override
{
return getSecretKeyId();
}

Crt::Optional<String> sessionToken() override
Crt::Optional<String> sessionToken() const override
{
return getSessionToken();
}

Crt::Optional<DateTime> expiration() override
Crt::Optional<DateTime> expiration() const override
{
return getExpiration();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ S3ExpressIdentityProvider::getIdentity(
return {};
});
}
const auto identity = GetS3ExpressIdentity(params);
return identity;
auto identity = GetS3ExpressIdentity(params);
return Aws::MakeUnique<S3ExpressIdentity>(S3_EXPRESS_IDENTITY_PROVIDER, std::move(identity));
}

S3ExpressIdentity S3ExpressIdentityProvider::getIdentity(const Aws::String &bucketName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ namespace Aws {
return m_expiration;
}

String accessKeyId() override
String accessKeyId() const override
{
return getAccessKeyId();
}

String secretAccessKey() override
String secretAccessKey() const override
{
return getSecretKeyId();
}

Crt::Optional<String> sessionToken() override
Crt::Optional<String> sessionToken() const override
{
return getSessionToken();
}

Crt::Optional<DateTime> expiration() override
Crt::Optional<DateTime> expiration() const override
{
return getExpiration();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ S3ExpressIdentityProvider::getIdentity(
return {};
});
}
const auto identity = GetS3ExpressIdentity(params);
return identity;
auto identity = GetS3ExpressIdentity(params);
return Aws::MakeUnique<S3ExpressIdentity>(S3_EXPRESS_IDENTITY_PROVIDER, std::move(identity));
}

S3ExpressIdentity S3ExpressIdentityProvider::getIdentity(const Aws::String &bucketName) {
Expand Down
44 changes: 40 additions & 4 deletions src/aws-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ file(GLOB UTILS_STREAM_HEADERS "include/aws/core/utils/stream/*.h")
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_CLIENT_HEADERS "include/smithy/client/*.h" "include/smithy/client/impl/*.h")
file(GLOB SMITHY_CLIENT_HEADERS "include/smithy/client/*.h")
file(GLOB SMITHY_CLIENT_IMPL_HEADERS "include/smithy/client/impl/*.h")
file(GLOB SMITHY_CLIENT_COMMON_HEADERS "include/smithy/client/common/*.h")
file(GLOB SMITHY_CLIENT_FEATURES_HEADERS "include/smithy/client/features/*.h")
file(GLOB SMITHY_TRACING_HEADERS "include/smithy/tracing/*.h")
file(GLOB SMITHY_IDENTITY_HEADERS "include/smithy/identity/*.h")
file(GLOB SMITHY_IDENTITY_AUTH_HEADERS "include/smithy/identity/auth/*.h" "include/smithy/identity/auth/impl/*.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 SMITHY_IDENTITY_AUTH_HEADERS "include/smithy/identity/auth/*.h")
file(GLOB SMITHY_IDENTITY_AUTH_IMPL_HEADERS "include/smithy/identity/auth/impl/*.h")
file(GLOB SMITHY_IDENTITY_AUTH_BUILTIN_HEADERS "include/smithy/identity/auth/built-in/*.h")
file(GLOB SMITHY_IDENTITY_IDENTITY_HEADERS "include/smithy/identity/identity/*.h")
file(GLOB SMITHY_IDENTITY_RESOLVER_HEADERS "include/smithy/identity/resolver/*.h")
file(GLOB SMITHY_IDENTITY_RESOLVER_BUILTIN_HEADERS "include/smithy/identity/resolver/built-in/*.h")
file(GLOB SMITHY_IDENTITY_IDENTITY_IMPL_HEADERS "include/smithy/identity/identity/impl/*.h")
file(GLOB SMITHY_IDENTITY_RESOLVER_IMPL_HEADERS "include/smithy/identity/resolver/impl/*.h")
file(GLOB SMITHY_IDENTITY_SIGNER_HEADERS "include/smithy/identity/signer/*.h")
file(GLOB SMITHY_IDENTITY_SIGNER_BUILTIN_HEADERS "include/smithy/identity/signer/built-in/*.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 @@ -333,11 +343,21 @@ file(GLOB AWS_NATIVE_SDK_COMMON_HEADERS
${HTTP_WINDOWS_CLIENT_HEADERS}
${SMITHY_HEADERS}
${SMITHY_CLIENT_HEADERS}
${SMITHY_CLIENT_IMPL_HEADERS}
${SMITHY_CLIENT_COMMON_HEADERS}
${SMITHY_CLIENT_FEATURES_HEADERS}
${SMITHY_TRACING_HEADERS}
${SMITHY_IDENTITY_HEADERS}
${SMITHY_IDENTITY_AUTH_HEADERS}
${SMITHY_IDENTITY_AUTH_IMPL_HEADERS}
${SMITHY_IDENTITY_AUTH_BUILTIN_HEADERS}
${SMITHY_IDENTITY_IDENTITY_HEADERS}
${SMITHY_IDENTITY_SIGNER_HEADERS}
${SMITHY_IDENTITY_IDENTITY_IMPL_HEADERS}
${SMITHY_IDENTITY_SIGNER_IMPL_HEADERS}
${SMITHY_IDENTITY_SIGNER_BUILTIN_HEADERS}
${SMITHY_IDENTITY_RESOLVER_HEADERS}
${SMITHY_IDENTITY_RESOLVER_BUILTIN_HEADERS}
${OPTEL_HEADERS}
)

Expand Down Expand Up @@ -455,10 +475,20 @@ 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\\client" FILES ${SMITHY_CLIENT_HEADERS})
source_group("Header Files\\smithy\\client" FILES ${SMITHY_CLIENT_IMPL_HEADERS})
source_group("Header Files\\smithy\\client" FILES ${SMITHY_CLIENT_COMMON_HEADERS})
source_group("Header Files\\smithy\\client" FILES ${SMITHY_CLIENT_FEATURES_HEADERS})
source_group("Header Files\\smithy\\tracing" FILES ${SMITHY_TRACING_HEADERS})
source_group("Header Files\\smithy\\identity\\auth" FILES ${SMITHY_IDENTITY_AUTH_HEADERS})
source_group("Header Files\\smithy\\identity\\auth\\impl" FILES ${SMITHY_IDENTITY_AUTH_IMPL_HEADERS})
source_group("Header Files\\smithy\\identity\\auth\\built-in" FILES ${SMITHY_IDENTITY_AUTH_BUILTIN_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})
source_group("Header Files\\smithy\\identity\\resolver\\built-in" FILES ${SMITHY_IDENTITY_RESOLVER_BUILTIN_HEADERS})
source_group("Header Files\\smithy\\identity\\identity\\impl" FILES ${SMITHY_IDENTITY_IDENTITY_IMPL_HEADERS})
source_group("Header Files\\smithy\\identity\\resolver\\impl" FILES ${SMITHY_IDENTITY_RESOLVER_IMPL_HEADERS})
source_group("Header Files\\smithy\\identity\\signer" FILES ${SMITHY_IDENTITY_SIGNER_HEADERS})
source_group("Header Files\\smithy\\identity\\signer\\built-in" FILES ${SMITHY_IDENTITY_SIGNER_BUILTIN_HEADERS})

# http client conditional headers
if(ENABLE_CURL_CLIENT)
Expand Down Expand Up @@ -724,8 +754,14 @@ install (FILES ${SMITHY_CLIENT_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_AUTH_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/auth)
install (FILES ${SMITHY_IDENTITY_AUTH_IMPL_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/auth/impl)
install (FILES ${SMITHY_IDENTITY_AUTH_BUILTIN_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/auth/built-in)
install (FILES ${SMITHY_IDENTITY_IDENTITY_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/identity)
install (FILES ${SMITHY_IDENTITY_RESOLVER_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/resolver)
install (FILES ${SMITHY_IDENTITY_IDENTITY_IMPL_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/identity/impl)
install (FILES ${SMITHY_IDENTITY_RESOLVER_IMPL_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/resolver/impl)
install (FILES ${SMITHY_IDENTITY_SIGNER_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/signer)
install (FILES ${SMITHY_IDENTITY_SIGNER_BUILTIN_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/smithy/identity/signer/built-in)

# android logcat headers
if(PLATFORM_ANDROID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

#include <memory>

namespace smithy
{
class AwsSigV4Signer;
}

namespace Aws
{
namespace Http
Expand Down Expand Up @@ -178,7 +183,6 @@ namespace Aws
bool m_includeSha256HashHeader;

private:

Aws::String GenerateSignature(const Aws::Auth::AWSCredentials& credentials,
const Aws::String& stringToSign, const Aws::String& simpleDate, const Aws::String& region,
const Aws::String& serviceName) const;
Expand All @@ -193,6 +197,14 @@ namespace Aws
bool SignRequestWithSigV4a(Aws::Http::HttpRequest& request, const char* region, const char* serviceName,
bool signBody, long long expirationTimeInSeconds, Aws::Crt::Auth::SignatureType signatureType) const;

friend class smithy::AwsSigV4Signer;
/**
* Temporary method added for migration to the smithy architecture. Please do not use.
*/
bool SignRequestWithCreds(Aws::Http::HttpRequest& request, const Auth::AWSCredentials& credentials,
const char* region, const char* serviceName, bool signBody) const;


Aws::Auth::AWSSigningAlgorithm m_signingAlgorithm;
std::shared_ptr<Auth::AWSCredentialsProvider> m_credentialsProvider;
const Aws::String m_serviceName;
Expand Down
4 changes: 4 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/client/AWSError.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ namespace Aws
* Return whether or not the error should throttle retry strategies.
*/
inline bool ShouldThrottle() const { return m_retryableType == RetryableType::RETRYABLE_THROTTLING; }
/**
* Sets the response code from the http response
*/
inline void SetRetryableType(const RetryableType retryableType) { m_retryableType = retryableType; }

protected:
inline ErrorPayloadType GetErrorPayloadType() { return m_errorPayloadType; }
Expand Down
15 changes: 15 additions & 0 deletions src/aws-cpp-sdk-core/include/aws/core/client/AWSErrorMarshaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include <aws/core/Core_EXPORTS.h>
#include <aws/core/client/AWSError.h>
#include <aws/core/client/CoreErrors.h>
#include <aws/core/utils/memory/stl/AWSString.h>

namespace Aws
Expand Down Expand Up @@ -53,6 +55,15 @@ namespace Aws
*/
virtual AWSError<CoreErrors> FindErrorByName(const char* exceptionName) const;
virtual AWSError<CoreErrors> FindErrorByHttpResponseCode(Aws::Http::HttpResponseCode code) const;

/**
* Deserialize http error payload to an error object.
*/
virtual AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Http::HttpResponse>&) const
{
return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
}

/**
* Attempts to extract region from error.
*/
Expand All @@ -75,6 +86,8 @@ namespace Aws
*/
AWSError<CoreErrors> Marshall(const Aws::Http::HttpResponse& response) const override;

AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const override;

protected:
const Aws::Utils::Json::JsonValue& GetJsonPayloadFromError(const AWSError<CoreErrors>&) const;
};
Expand All @@ -89,6 +102,8 @@ namespace Aws
*/
AWSError<CoreErrors> Marshall(const Aws::Http::HttpResponse& response) const override;

AWSError<CoreErrors> BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const override;

protected:
const Aws::Utils::Xml::XmlDocument& GetXmlPayloadFromError(const AWSError<CoreErrors>&) const;
};
Expand Down
1 change: 1 addition & 0 deletions src/aws-cpp-sdk-core/include/aws/core/client/CoreErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Aws
INVALID_ACCESS_KEY_ID = 23,
REQUEST_TIMEOUT = 24,
NOT_INITIALIZED = 25,
MEMORY_ALLOCATION = 26,

NETWORK_CONNECTION = 99, // General failure to send message to service

Expand Down
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/core/utils/threading/Executor.h>

#include <aws/core/utils/memory/stl/AWSList.h>
#include <functional>

namespace Aws
{
namespace Utils
{
namespace Threading
{
/**
* An executor that does not spawn any thread, instead, tasks are executed in the current thread
* TODO: add await functionality to avoid deadlocking if thread waits for another async task.
*/
class AWS_CORE_API SameThreadExecutor : public Executor
{
public:
virtual ~SameThreadExecutor();
void WaitUntilStopped() override;
protected:
bool SubmitToThread(std::function<void()>&& task) override;

using TaskFunc = std::function<void()>;
Aws::List<TaskFunc> m_tasks;
};
} // namespace Threading
} // namespace Utils
} // namespace Aws
Loading

0 comments on commit 59eeba3

Please sign in to comment.