209 lines
8.9 KiB
C++
209 lines
8.9 KiB
C++
|
|
/**
|
|||
|
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|||
|
|
* SPDX-License-Identifier: Apache-2.0.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include <aws/core/utils/Outcome.h>
|
|||
|
|
#include <aws/core/auth/AWSAuthSigner.h>
|
|||
|
|
#include <aws/core/client/CoreErrors.h>
|
|||
|
|
#include <aws/core/client/RetryStrategy.h>
|
|||
|
|
#include <aws/core/http/HttpClient.h>
|
|||
|
|
#include <aws/core/http/HttpResponse.h>
|
|||
|
|
#include <aws/core/http/HttpClientFactory.h>
|
|||
|
|
#include <aws/core/auth/AWSCredentialsProviderChain.h>
|
|||
|
|
#include <aws/core/utils/json/JsonSerializer.h>
|
|||
|
|
#include <aws/core/utils/memory/stl/AWSStringStream.h>
|
|||
|
|
#include <aws/core/utils/threading/Executor.h>
|
|||
|
|
#include <aws/core/utils/DNS.h>
|
|||
|
|
#include <aws/core/utils/logging/LogMacros.h>
|
|||
|
|
|
|||
|
|
#include <aws/dynamodbstreams/DynamoDBStreamsClient.h>
|
|||
|
|
#include <aws/dynamodbstreams/DynamoDBStreamsEndpoint.h>
|
|||
|
|
#include <aws/dynamodbstreams/DynamoDBStreamsErrorMarshaller.h>
|
|||
|
|
#include <aws/dynamodbstreams/model/DescribeStreamRequest.h>
|
|||
|
|
#include <aws/dynamodbstreams/model/GetRecordsRequest.h>
|
|||
|
|
#include <aws/dynamodbstreams/model/GetShardIteratorRequest.h>
|
|||
|
|
#include <aws/dynamodbstreams/model/ListStreamsRequest.h>
|
|||
|
|
|
|||
|
|
using namespace Aws;
|
|||
|
|
using namespace Aws::Auth;
|
|||
|
|
using namespace Aws::Client;
|
|||
|
|
using namespace Aws::DynamoDBStreams;
|
|||
|
|
using namespace Aws::DynamoDBStreams::Model;
|
|||
|
|
using namespace Aws::Http;
|
|||
|
|
using namespace Aws::Utils::Json;
|
|||
|
|
|
|||
|
|
static const char* SERVICE_NAME = "dynamodb";
|
|||
|
|
static const char* ALLOCATION_TAG = "DynamoDBStreamsClient";
|
|||
|
|
|
|||
|
|
|
|||
|
|
DynamoDBStreamsClient::DynamoDBStreamsClient(const Client::ClientConfiguration& clientConfiguration) :
|
|||
|
|
BASECLASS(clientConfiguration,
|
|||
|
|
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG),
|
|||
|
|
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
|
|||
|
|
Aws::MakeShared<DynamoDBStreamsErrorMarshaller>(ALLOCATION_TAG)),
|
|||
|
|
m_executor(clientConfiguration.executor)
|
|||
|
|
{
|
|||
|
|
init(clientConfiguration);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DynamoDBStreamsClient::DynamoDBStreamsClient(const AWSCredentials& credentials, const Client::ClientConfiguration& clientConfiguration) :
|
|||
|
|
BASECLASS(clientConfiguration,
|
|||
|
|
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials),
|
|||
|
|
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
|
|||
|
|
Aws::MakeShared<DynamoDBStreamsErrorMarshaller>(ALLOCATION_TAG)),
|
|||
|
|
m_executor(clientConfiguration.executor)
|
|||
|
|
{
|
|||
|
|
init(clientConfiguration);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DynamoDBStreamsClient::DynamoDBStreamsClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider,
|
|||
|
|
const Client::ClientConfiguration& clientConfiguration) :
|
|||
|
|
BASECLASS(clientConfiguration,
|
|||
|
|
Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider,
|
|||
|
|
SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)),
|
|||
|
|
Aws::MakeShared<DynamoDBStreamsErrorMarshaller>(ALLOCATION_TAG)),
|
|||
|
|
m_executor(clientConfiguration.executor)
|
|||
|
|
{
|
|||
|
|
init(clientConfiguration);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DynamoDBStreamsClient::~DynamoDBStreamsClient()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::init(const ClientConfiguration& config)
|
|||
|
|
{
|
|||
|
|
SetServiceClientName("streams.dynamodb");
|
|||
|
|
m_configScheme = SchemeMapper::ToString(config.scheme);
|
|||
|
|
if (config.endpointOverride.empty())
|
|||
|
|
{
|
|||
|
|
m_uri = m_configScheme + "://" + DynamoDBStreamsEndpoint::ForRegion(config.region, config.useDualStack);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
OverrideEndpoint(config.endpointOverride);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::OverrideEndpoint(const Aws::String& endpoint)
|
|||
|
|
{
|
|||
|
|
if (endpoint.compare(0, 7, "http://") == 0 || endpoint.compare(0, 8, "https://") == 0)
|
|||
|
|
{
|
|||
|
|
m_uri = endpoint;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
m_uri = m_configScheme + "://" + endpoint;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DescribeStreamOutcome DynamoDBStreamsClient::DescribeStream(const DescribeStreamRequest& request) const
|
|||
|
|
{
|
|||
|
|
Aws::Http::URI uri = m_uri;
|
|||
|
|
Aws::StringStream ss;
|
|||
|
|
ss << "/";
|
|||
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|||
|
|
return DescribeStreamOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DescribeStreamOutcomeCallable DynamoDBStreamsClient::DescribeStreamCallable(const DescribeStreamRequest& request) const
|
|||
|
|
{
|
|||
|
|
auto task = Aws::MakeShared< std::packaged_task< DescribeStreamOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->DescribeStream(request); } );
|
|||
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|||
|
|
m_executor->Submit(packagedFunction);
|
|||
|
|
return task->get_future();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::DescribeStreamAsync(const DescribeStreamRequest& request, const DescribeStreamResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
m_executor->Submit( [this, request, handler, context](){ this->DescribeStreamAsyncHelper( request, handler, context ); } );
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::DescribeStreamAsyncHelper(const DescribeStreamRequest& request, const DescribeStreamResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
handler(this, request, DescribeStream(request), context);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GetRecordsOutcome DynamoDBStreamsClient::GetRecords(const GetRecordsRequest& request) const
|
|||
|
|
{
|
|||
|
|
Aws::Http::URI uri = m_uri;
|
|||
|
|
Aws::StringStream ss;
|
|||
|
|
ss << "/";
|
|||
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|||
|
|
return GetRecordsOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GetRecordsOutcomeCallable DynamoDBStreamsClient::GetRecordsCallable(const GetRecordsRequest& request) const
|
|||
|
|
{
|
|||
|
|
auto task = Aws::MakeShared< std::packaged_task< GetRecordsOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->GetRecords(request); } );
|
|||
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|||
|
|
m_executor->Submit(packagedFunction);
|
|||
|
|
return task->get_future();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::GetRecordsAsync(const GetRecordsRequest& request, const GetRecordsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
m_executor->Submit( [this, request, handler, context](){ this->GetRecordsAsyncHelper( request, handler, context ); } );
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::GetRecordsAsyncHelper(const GetRecordsRequest& request, const GetRecordsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
handler(this, request, GetRecords(request), context);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GetShardIteratorOutcome DynamoDBStreamsClient::GetShardIterator(const GetShardIteratorRequest& request) const
|
|||
|
|
{
|
|||
|
|
Aws::Http::URI uri = m_uri;
|
|||
|
|
Aws::StringStream ss;
|
|||
|
|
ss << "/";
|
|||
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|||
|
|
return GetShardIteratorOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GetShardIteratorOutcomeCallable DynamoDBStreamsClient::GetShardIteratorCallable(const GetShardIteratorRequest& request) const
|
|||
|
|
{
|
|||
|
|
auto task = Aws::MakeShared< std::packaged_task< GetShardIteratorOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->GetShardIterator(request); } );
|
|||
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|||
|
|
m_executor->Submit(packagedFunction);
|
|||
|
|
return task->get_future();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::GetShardIteratorAsync(const GetShardIteratorRequest& request, const GetShardIteratorResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
m_executor->Submit( [this, request, handler, context](){ this->GetShardIteratorAsyncHelper( request, handler, context ); } );
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::GetShardIteratorAsyncHelper(const GetShardIteratorRequest& request, const GetShardIteratorResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
handler(this, request, GetShardIterator(request), context);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ListStreamsOutcome DynamoDBStreamsClient::ListStreams(const ListStreamsRequest& request) const
|
|||
|
|
{
|
|||
|
|
Aws::Http::URI uri = m_uri;
|
|||
|
|
Aws::StringStream ss;
|
|||
|
|
ss << "/";
|
|||
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|||
|
|
return ListStreamsOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ListStreamsOutcomeCallable DynamoDBStreamsClient::ListStreamsCallable(const ListStreamsRequest& request) const
|
|||
|
|
{
|
|||
|
|
auto task = Aws::MakeShared< std::packaged_task< ListStreamsOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->ListStreams(request); } );
|
|||
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|||
|
|
m_executor->Submit(packagedFunction);
|
|||
|
|
return task->get_future();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::ListStreamsAsync(const ListStreamsRequest& request, const ListStreamsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
m_executor->Submit( [this, request, handler, context](){ this->ListStreamsAsyncHelper( request, handler, context ); } );
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DynamoDBStreamsClient::ListStreamsAsyncHelper(const ListStreamsRequest& request, const ListStreamsResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|||
|
|
{
|
|||
|
|
handler(this, request, ListStreams(request), context);
|
|||
|
|
}
|
|||
|
|
|