Skip to content

Commit

Permalink
streaming updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sbera87 committed Dec 10, 2024
1 parent 615c99a commit e780241
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Model
* href="http://docs.aws.amazon.com/goto/WebAPI/qbusiness-2023-11-27/ChatInputStream">AWS
* API Reference</a></p>
*/
class AWS_QBUSINESS_API ChatInputStream : public Aws::Utils::Event::SmithyEventEncoderStream<smithy::AwsCredentialIdentityBase>
class AWS_QBUSINESS_API ChatInputStream : public Aws::Utils::Event::SmithyEventEncoderStream
{
public:
ChatInputStream& WriteConfigurationEvent(const ConfigurationEvent& value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Model
* href="http://docs.aws.amazon.com/goto/WebAPI/transcribe-streaming-2017-10-26/AudioStream">AWS
* API Reference</a></p>
*/
class AWS_TRANSCRIBESTREAMINGSERVICE_API AudioStream : public Aws::Utils::Event::SmithyEventEncoderStream<smithy::AwsCredentialIdentityBase>
class AWS_TRANSCRIBESTREAMINGSERVICE_API AudioStream : public Aws::Utils::Event::SmithyEventEncoderStream
{
public:
AudioStream& WriteAudioEvent(const AudioEvent& value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,9 @@ namespace Aws
return PresignRequest(ioRequest, expirationInSeconds);
}

std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase> BearerTokenProvider() const
{
return m_bearerTokenProvider;
}
protected:
std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase> BearerTokenProvider() const { return m_bearerTokenProvider; }

protected:
std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase> m_bearerTokenProvider;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ namespace Aws
EventStreamEncoder m_encoder;
};

template <typename IdentityT>
class AWS_CORE_API SmithyEventEncoderStream : public EventEncoderStream {
public:
explicit SmithyEventEncoderStream(size_t bufferSize = DEFAULT_BUF_SIZE) : EventEncoderStream(bufferSize) {}
virtual ~SmithyEventEncoderStream() {}
void SetSigner(std::shared_ptr<smithy::AwsSignerBase<IdentityT> > signer, Aws::UniquePtr<IdentityT> identity) {
void SetSigner(std::shared_ptr<smithy::AwsSignerBase<smithy::AwsCredentialIdentityBase> > signer,
Aws::UniquePtr<smithy::AwsCredentialIdentityBase> identity) {
m_evtEncoder.SetSigner(signer, std::move(identity));
}
void SetSignatureSeed(const Aws::String& seed) override { m_evtEncoder.SetSignatureSeed(seed); }
Expand All @@ -89,7 +89,7 @@ namespace Aws
Aws::Vector<unsigned char> EncodeAndSign(const Aws::Utils::Event::Message& msg) override {
return m_evtEncoder.EncodeAndSign(msg);
}
SmithyEventStreamEncoder<IdentityT> m_evtEncoder;
SmithyEventStreamEncoder<smithy::AwsCredentialIdentityBase> m_evtEncoder;
};
} // namespace Event
}
Expand Down
12 changes: 7 additions & 5 deletions src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ namespace client
return m_serializer->Deserialize(std::move(httpResponseOutcome), GetServiceClientName(), requestName);
}

ResponseT MakeEventStreamRequestDeserialize(Aws::AmazonWebServiceRequest const* const request, const char* requestName,
Aws::Http::HttpMethod method, EndpointUpdateCallback&& endpointCallback,
std::shared_ptr<Aws::Utils::Event::EventEncoderStream> eventEncoderStream_sp) const {
ResponseT MakeEventStreamRequestDeserialize(
Aws::AmazonWebServiceRequest const* const request, const char* requestName, Aws::Http::HttpMethod method,
EndpointUpdateCallback&& endpointCallback,
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> eventEncoderStream_sp) const {
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor =
Aws::MakeShared<Aws::Utils::Threading::SameThreadExecutor>("AwsSmithyClient");
assert(pExecutor);
Expand All @@ -149,8 +150,9 @@ namespace client
}

protected:
void SetSignerInEventStreamRequest(std::shared_ptr<AwsSmithyClientAsyncRequestContext>& pRequestCtx,
std::shared_ptr<Aws::Utils::Event::EventEncoderStream>& eventEncoderStreamSp) const override {
void SetSignerInEventStreamRequest(
std::shared_ptr<AwsSmithyClientAsyncRequestContext>& pRequestCtx,
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream>& eventEncoderStreamSp) const override {
if (pRequestCtx && pRequestCtx->m_pRequest && eventEncoderStreamSp) {
if (AwsClientRequestSigning<AuthSchemesVariantT>::SetSignerInEventStream(eventEncoderStreamSp, pRequestCtx->m_authSchemeOption,
m_authSchemes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace client
void MakeRequestAsync(Aws::AmazonWebServiceRequest const* const request, const char* requestName, Aws::Http::HttpMethod method,
EndpointUpdateCallback&& endpointCallback, ResponseHandlerFunc&& responseHandler,
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
std::shared_ptr<Aws::Utils::Event::EventEncoderStream> eventEncoderStream_sp = nullptr) const;
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> eventEncoderStream_sp = nullptr) const;

HttpResponseOutcome MakeRequestSync(Aws::AmazonWebServiceRequest const* const request, const char* requestName,
Aws::Http::HttpMethod method, EndpointUpdateCallback&& endpointCallback) const;
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace client

protected:
virtual void SetSignerInEventStreamRequest(std::shared_ptr<AwsSmithyClientAsyncRequestContext>&,
std::shared_ptr<Aws::Utils::Event::EventEncoderStream>&) const {};
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream>&) const {};
Aws::UniquePtr<Aws::Client::ClientConfiguration> m_clientConfig;
Aws::String m_serviceName;
Aws::String m_userAgent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <aws/core/utils/memory/stl/AWSMap.h>

#include <cassert>
#include <smithy/identity/auth/built-in/SigV4AuthScheme.h>


namespace smithy
Expand Down Expand Up @@ -80,7 +81,7 @@ namespace smithy
return visitor.m_resultShouldWait;
}

static bool SetSignerInEventStream(std::shared_ptr<Aws::Utils::Event::EventEncoderStream> eventEncoderStreamSp,
static bool SetSignerInEventStream(std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> eventEncoderStreamSp,
const AuthSchemeOption& authSchemeOption,
const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes) {
bool result = false;
Expand Down Expand Up @@ -197,7 +198,7 @@ namespace smithy
<< ", while client time is "
<< DateTime::Now().ToGmtString(DateFormat::RFC822));
auto diff = DateTime::Diff(m_serverTime, signingTimestamp);
//only try again if clock skew was the cause of the error.
// only try again if clock skew was the cause of the error.
if (diff >= TIME_DIFF_MAX || diff <= TIME_DIFF_MIN) {
diff = DateTime::Diff(m_serverTime, DateTime::Now());
AWS_LOGSTREAM_INFO(AWS_SMITHY_CLIENT_SIGNING_TAG,
Expand All @@ -213,22 +214,23 @@ namespace smithy
};

struct EventStreamSignerVisitor {
explicit EventStreamSignerVisitor(std::shared_ptr<Aws::Utils::Event::EventEncoderStream> evSp,
explicit EventStreamSignerVisitor(std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> evSp,
const AuthSchemeOption& targetAuthSchemeOption)
: m_eventEncoderStreamSp(evSp), m_targetAuthSchemeOption(targetAuthSchemeOption) {}

std::shared_ptr<Aws::Utils::Event::EventEncoderStream> m_eventEncoderStreamSp;
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> m_eventEncoderStreamSp;
const AuthSchemeOption& m_targetAuthSchemeOption;

template <typename AuthSchemeAlternativeT>
void operator()(AuthSchemeAlternativeT& authScheme) {
void operator()(AuthSchemeAlternativeT&) {}

template <>
void operator()<smithy::SigV4AuthScheme>(smithy::SigV4AuthScheme& authScheme) {
// Auth Scheme Variant alternative contains the requested auth option
assert(strcmp(authScheme.schemeId, m_targetAuthSchemeOption.schemeId) == 0);

using IdentityT = typename std::remove_reference<decltype(authScheme)>::type::IdentityT;
using IdentityT = smithy::SigV4AuthScheme::IdentityT;
using IdentityResolver = IdentityResolverBase<IdentityT>;
using Signer = AwsSignerBase<IdentityT>;

std::shared_ptr<Signer> signer = authScheme.signer(m_targetAuthSchemeOption.isEventStreaming);
if (!signer) {
AWS_LOGSTREAM_ERROR(AWS_SMITHY_CLIENT_SIGNING_TAG, "Failed to adjust signing clock skew. Signer is null.");
Expand All @@ -251,8 +253,7 @@ namespace smithy
}

// typecast to streaming type as we know this visitor is for smithy types
(std::dynamic_pointer_cast<Aws::Utils::Event::SmithyEventEncoderStream<IdentityT>>(m_eventEncoderStreamSp))
->SetSigner(signer, std::move(identityResult.GetResultWithOwnership()));
m_eventEncoderStreamSp->SetSigner(signer, std::move(identityResult.GetResultWithOwnership()));
}
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#include <aws/core/auth/bearer-token-provider/AWSBearerTokenProviderBase.h>
#include <aws/core/auth/bearer-token-provider/SSOBearerTokenProvider.h>
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>
#include <aws/core/auth/signer-provider/BearerTokenAuthSignerProvider.h>
#include <aws/core/auth/signer/AWSAuthBearerSigner.h>
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>
namespace smithy
{

Expand All @@ -32,17 +32,11 @@ class AwsBearerTokenIdentityResolver
{
}

AwsBearerTokenIdentityResolver(
const Aws::Auth::BearerTokenAuthSignerProvider& bearerTokenProvider
)
{
auto signer = bearerTokenProvider.GetSigner(Aws::Auth::BEARER_SIGNER);
if(signer)
{
m_providerChainLegacy.emplace_back(
std::dynamic_pointer_cast<Aws::Client::AWSAuthBearerSigner>(signer)->BearerTokenProvider()
);
}
AwsBearerTokenIdentityResolver(const Aws::Auth::BearerTokenAuthSignerProvider &bearerTokenProvider) {
auto signer = bearerTokenProvider.GetSigner(Aws::Auth::BEARER_SIGNER);
if (signer) {
m_providerChainLegacy.emplace_back(std::dynamic_pointer_cast<Aws::Client::AWSAuthBearerSigner>(signer)->BearerTokenProvider());
}
}

ResolveIdentityFutureOutcome
Expand Down Expand Up @@ -100,9 +94,8 @@ class DefaultAwsBearerTokenIdentityResolver
virtual ~DefaultAwsBearerTokenIdentityResolver() = default;

DefaultAwsBearerTokenIdentityResolver()
: AwsBearerTokenIdentityResolver(
Aws::Vector<std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase>>{Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>(
"SSOBearerTokenProvider")}){};
: AwsBearerTokenIdentityResolver(Aws::Vector<std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase>>{
Aws::MakeShared<Aws::Auth::SSOBearerTokenProvider>("SSOBearerTokenProvider")}){};
};
const char
AwsBearerTokenIdentityResolver::BEARER_TOKEN_PROVIDER_CHAIN_LOG_TAG[] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <aws/core/auth/AWSCredentials.h>
#include <aws/core/auth/AWSCredentialsProviderChain.h>

#include <smithy/identity/auth/AuthSchemeResolverBase.h>
namespace smithy {
constexpr char ALLOC_ID[] = "DefaultAwsCredentialIdentityResolver";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void AwsSmithyClientBase::MakeRequestAsync(Aws::AmazonWebServiceRequest const* c
Aws::Http::HttpMethod method, EndpointUpdateCallback&& endpointCallback,
ResponseHandlerFunc&& responseHandler,
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
std::shared_ptr<Aws::Utils::Event::EventEncoderStream> eventEncoderStreamSp) const {
std::shared_ptr<Aws::Utils::Event::SmithyEventEncoderStream> eventEncoderStreamSp) const {
if (!responseHandler) {
assert(!"Missing a mandatory response handler!");
AWS_LOGSTREAM_FATAL(AWS_SMITHY_CLIENT_LOG, "Unable to continue AWSClient request: response handler is missing!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Model
* $shape.documentation
*/
#end
class $typeInfo.exportValue $typeInfo.className : public Aws::Utils::Event::SmithyEventEncoderStream<smithy::AwsCredentialIdentityBase>
class $typeInfo.exportValue $typeInfo.className : public Aws::Utils::Event::SmithyEventEncoderStream
{
public:
#foreach($entry in $shape.members.entrySet())
Expand Down

0 comments on commit e780241

Please sign in to comment.