199 lines
9.1 KiB
C++
199 lines
9.1 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/apigatewaymanagementapi/ApiGatewayManagementApiClient.h>
|
|
#include <aws/apigatewaymanagementapi/ApiGatewayManagementApiEndpoint.h>
|
|
#include <aws/apigatewaymanagementapi/ApiGatewayManagementApiErrorMarshaller.h>
|
|
#include <aws/apigatewaymanagementapi/model/DeleteConnectionRequest.h>
|
|
#include <aws/apigatewaymanagementapi/model/GetConnectionRequest.h>
|
|
#include <aws/apigatewaymanagementapi/model/PostToConnectionRequest.h>
|
|
|
|
using namespace Aws;
|
|
using namespace Aws::Auth;
|
|
using namespace Aws::Client;
|
|
using namespace Aws::ApiGatewayManagementApi;
|
|
using namespace Aws::ApiGatewayManagementApi::Model;
|
|
using namespace Aws::Http;
|
|
using namespace Aws::Utils::Json;
|
|
|
|
static const char* SERVICE_NAME = "execute-api";
|
|
static const char* ALLOCATION_TAG = "ApiGatewayManagementApiClient";
|
|
|
|
|
|
ApiGatewayManagementApiClient::ApiGatewayManagementApiClient(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<ApiGatewayManagementApiErrorMarshaller>(ALLOCATION_TAG)),
|
|
m_executor(clientConfiguration.executor)
|
|
{
|
|
init(clientConfiguration);
|
|
}
|
|
|
|
ApiGatewayManagementApiClient::ApiGatewayManagementApiClient(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<ApiGatewayManagementApiErrorMarshaller>(ALLOCATION_TAG)),
|
|
m_executor(clientConfiguration.executor)
|
|
{
|
|
init(clientConfiguration);
|
|
}
|
|
|
|
ApiGatewayManagementApiClient::ApiGatewayManagementApiClient(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<ApiGatewayManagementApiErrorMarshaller>(ALLOCATION_TAG)),
|
|
m_executor(clientConfiguration.executor)
|
|
{
|
|
init(clientConfiguration);
|
|
}
|
|
|
|
ApiGatewayManagementApiClient::~ApiGatewayManagementApiClient()
|
|
{
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::init(const ClientConfiguration& config)
|
|
{
|
|
SetServiceClientName("ApiGatewayManagementApi");
|
|
m_configScheme = SchemeMapper::ToString(config.scheme);
|
|
if (config.endpointOverride.empty())
|
|
{
|
|
m_uri = m_configScheme + "://" + ApiGatewayManagementApiEndpoint::ForRegion(config.region, config.useDualStack);
|
|
}
|
|
else
|
|
{
|
|
OverrideEndpoint(config.endpointOverride);
|
|
}
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::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;
|
|
}
|
|
}
|
|
|
|
DeleteConnectionOutcome ApiGatewayManagementApiClient::DeleteConnection(const DeleteConnectionRequest& request) const
|
|
{
|
|
if (!request.ConnectionIdHasBeenSet())
|
|
{
|
|
AWS_LOGSTREAM_ERROR("DeleteConnection", "Required field: ConnectionId, is not set");
|
|
return DeleteConnectionOutcome(Aws::Client::AWSError<ApiGatewayManagementApiErrors>(ApiGatewayManagementApiErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [ConnectionId]", false));
|
|
}
|
|
Aws::Http::URI uri = m_uri;
|
|
Aws::StringStream ss;
|
|
ss << "/@connections/";
|
|
ss << request.GetConnectionId();
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|
return DeleteConnectionOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_DELETE, Aws::Auth::SIGV4_SIGNER));
|
|
}
|
|
|
|
DeleteConnectionOutcomeCallable ApiGatewayManagementApiClient::DeleteConnectionCallable(const DeleteConnectionRequest& request) const
|
|
{
|
|
auto task = Aws::MakeShared< std::packaged_task< DeleteConnectionOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->DeleteConnection(request); } );
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|
m_executor->Submit(packagedFunction);
|
|
return task->get_future();
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::DeleteConnectionAsync(const DeleteConnectionRequest& request, const DeleteConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
m_executor->Submit( [this, request, handler, context](){ this->DeleteConnectionAsyncHelper( request, handler, context ); } );
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::DeleteConnectionAsyncHelper(const DeleteConnectionRequest& request, const DeleteConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
handler(this, request, DeleteConnection(request), context);
|
|
}
|
|
|
|
GetConnectionOutcome ApiGatewayManagementApiClient::GetConnection(const GetConnectionRequest& request) const
|
|
{
|
|
if (!request.ConnectionIdHasBeenSet())
|
|
{
|
|
AWS_LOGSTREAM_ERROR("GetConnection", "Required field: ConnectionId, is not set");
|
|
return GetConnectionOutcome(Aws::Client::AWSError<ApiGatewayManagementApiErrors>(ApiGatewayManagementApiErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [ConnectionId]", false));
|
|
}
|
|
Aws::Http::URI uri = m_uri;
|
|
Aws::StringStream ss;
|
|
ss << "/@connections/";
|
|
ss << request.GetConnectionId();
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|
return GetConnectionOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_GET, Aws::Auth::SIGV4_SIGNER));
|
|
}
|
|
|
|
GetConnectionOutcomeCallable ApiGatewayManagementApiClient::GetConnectionCallable(const GetConnectionRequest& request) const
|
|
{
|
|
auto task = Aws::MakeShared< std::packaged_task< GetConnectionOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->GetConnection(request); } );
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|
m_executor->Submit(packagedFunction);
|
|
return task->get_future();
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::GetConnectionAsync(const GetConnectionRequest& request, const GetConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
m_executor->Submit( [this, request, handler, context](){ this->GetConnectionAsyncHelper( request, handler, context ); } );
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::GetConnectionAsyncHelper(const GetConnectionRequest& request, const GetConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
handler(this, request, GetConnection(request), context);
|
|
}
|
|
|
|
PostToConnectionOutcome ApiGatewayManagementApiClient::PostToConnection(const PostToConnectionRequest& request) const
|
|
{
|
|
if (!request.ConnectionIdHasBeenSet())
|
|
{
|
|
AWS_LOGSTREAM_ERROR("PostToConnection", "Required field: ConnectionId, is not set");
|
|
return PostToConnectionOutcome(Aws::Client::AWSError<ApiGatewayManagementApiErrors>(ApiGatewayManagementApiErrors::MISSING_PARAMETER, "MISSING_PARAMETER", "Missing required field [ConnectionId]", false));
|
|
}
|
|
Aws::Http::URI uri = m_uri;
|
|
Aws::StringStream ss;
|
|
ss << "/@connections/";
|
|
ss << request.GetConnectionId();
|
|
uri.SetPath(uri.GetPath() + ss.str());
|
|
return PostToConnectionOutcome(MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER));
|
|
}
|
|
|
|
PostToConnectionOutcomeCallable ApiGatewayManagementApiClient::PostToConnectionCallable(const PostToConnectionRequest& request) const
|
|
{
|
|
auto task = Aws::MakeShared< std::packaged_task< PostToConnectionOutcome() > >(ALLOCATION_TAG, [this, request](){ return this->PostToConnection(request); } );
|
|
auto packagedFunction = [task]() { (*task)(); };
|
|
m_executor->Submit(packagedFunction);
|
|
return task->get_future();
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::PostToConnectionAsync(const PostToConnectionRequest& request, const PostToConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
m_executor->Submit( [this, request, handler, context](){ this->PostToConnectionAsyncHelper( request, handler, context ); } );
|
|
}
|
|
|
|
void ApiGatewayManagementApiClient::PostToConnectionAsyncHelper(const PostToConnectionRequest& request, const PostToConnectionResponseReceivedHandler& handler, const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context) const
|
|
{
|
|
handler(this, request, PostToConnection(request), context);
|
|
}
|
|
|