/** * 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/core/utils/logging/ErrorMacros.h> #include <aws/controltower/ControlTowerClient.h> #include <aws/controltower/ControlTowerErrorMarshaller.h> #include <aws/controltower/ControlTowerEndpointProvider.h> #include <aws/controltower/model/DisableControlRequest.h> #include <aws/controltower/model/EnableControlRequest.h> #include <aws/controltower/model/GetControlOperationRequest.h> #include <aws/controltower/model/ListEnabledControlsRequest.h> #include <smithy/tracing/TracingUtils.h> using namespace Aws; using namespace Aws::Auth; using namespace Aws::Client; using namespace Aws::ControlTower; using namespace Aws::ControlTower::Model; using namespace Aws::Http; using namespace Aws::Utils::Json; using namespace smithy::components::tracing; using ResolveEndpointOutcome = Aws::Endpoint::ResolveEndpointOutcome; const char* ControlTowerClient::SERVICE_NAME = "controltower"; const char* ControlTowerClient::ALLOCATION_TAG = "ControlTowerClient"; ControlTowerClient::ControlTowerClient(const ControlTower::ControlTowerClientConfiguration& clientConfiguration, std::shared_ptr<ControlTowerEndpointProviderBase> endpointProvider) : BASECLASS(clientConfiguration, Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } ControlTowerClient::ControlTowerClient(const AWSCredentials& credentials, std::shared_ptr<ControlTowerEndpointProviderBase> endpointProvider, const ControlTower::ControlTowerClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, Aws::MakeShared<SimpleAWSCredentialsProvider>(ALLOCATION_TAG, credentials), SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } ControlTowerClient::ControlTowerClient(const std::shared_ptr<AWSCredentialsProvider>& credentialsProvider, std::shared_ptr<ControlTowerEndpointProviderBase> endpointProvider, const ControlTower::ControlTowerClientConfiguration& clientConfiguration) : BASECLASS(clientConfiguration, Aws::MakeShared<AWSAuthV4Signer>(ALLOCATION_TAG, credentialsProvider, SERVICE_NAME, Aws::Region::ComputeSignerRegion(clientConfiguration.region)), Aws::MakeShared<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(std::move(endpointProvider)) { init(m_clientConfiguration); } /* Legacy constructors due deprecation */ ControlTowerClient::ControlTowerClient(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<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared<ControlTowerEndpointProvider>(ALLOCATION_TAG)) { init(m_clientConfiguration); } ControlTowerClient::ControlTowerClient(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<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared<ControlTowerEndpointProvider>(ALLOCATION_TAG)) { init(m_clientConfiguration); } ControlTowerClient::ControlTowerClient(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<ControlTowerErrorMarshaller>(ALLOCATION_TAG)), m_clientConfiguration(clientConfiguration), m_executor(clientConfiguration.executor), m_endpointProvider(Aws::MakeShared<ControlTowerEndpointProvider>(ALLOCATION_TAG)) { init(m_clientConfiguration); } /* End of legacy constructors due deprecation */ ControlTowerClient::~ControlTowerClient() { ShutdownSdkClient(this, -1); } std::shared_ptr<ControlTowerEndpointProviderBase>& ControlTowerClient::accessEndpointProvider() { return m_endpointProvider; } void ControlTowerClient::init(const ControlTower::ControlTowerClientConfiguration& config) { AWSClient::SetServiceClientName("ControlTower"); AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider); m_endpointProvider->InitBuiltInParameters(config); } void ControlTowerClient::OverrideEndpoint(const Aws::String& endpoint) { AWS_CHECK_PTR(SERVICE_NAME, m_endpointProvider); m_endpointProvider->OverrideEndpoint(endpoint); } DisableControlOutcome ControlTowerClient::DisableControl(const DisableControlRequest& request) const { AWS_OPERATION_GUARD(DisableControl); AWS_OPERATION_CHECK_PTR(m_endpointProvider, DisableControl, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE); AWS_OPERATION_CHECK_PTR(m_telemetryProvider, DisableControl, CoreErrors, CoreErrors::NOT_INITIALIZED); auto tracer = m_telemetryProvider->getTracer(this->GetServiceClientName(), {}); auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); AWS_OPERATION_CHECK_PTR(meter, DisableControl, CoreErrors, CoreErrors::NOT_INITIALIZED); auto span = tracer->CreateSpan(Aws::String(this->GetServiceClientName()) + ".DisableControl", {{ TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName() }, { TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName() }, { TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE }}, smithy::components::tracing::SpanKind::CLIENT); return TracingUtils::MakeCallWithTiming<DisableControlOutcome>( [&]()-> DisableControlOutcome { auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); AWS_OPERATION_CHECK_SUCCESS(endpointResolutionOutcome, DisableControl, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE, endpointResolutionOutcome.GetError().GetMessage()); endpointResolutionOutcome.GetResult().AddPathSegments("/disable-control"); return DisableControlOutcome(MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER)); }, TracingUtils::SMITHY_CLIENT_DURATION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); } EnableControlOutcome ControlTowerClient::EnableControl(const EnableControlRequest& request) const { AWS_OPERATION_GUARD(EnableControl); AWS_OPERATION_CHECK_PTR(m_endpointProvider, EnableControl, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE); AWS_OPERATION_CHECK_PTR(m_telemetryProvider, EnableControl, CoreErrors, CoreErrors::NOT_INITIALIZED); auto tracer = m_telemetryProvider->getTracer(this->GetServiceClientName(), {}); auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); AWS_OPERATION_CHECK_PTR(meter, EnableControl, CoreErrors, CoreErrors::NOT_INITIALIZED); auto span = tracer->CreateSpan(Aws::String(this->GetServiceClientName()) + ".EnableControl", {{ TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName() }, { TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName() }, { TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE }}, smithy::components::tracing::SpanKind::CLIENT); return TracingUtils::MakeCallWithTiming<EnableControlOutcome>( [&]()-> EnableControlOutcome { auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); AWS_OPERATION_CHECK_SUCCESS(endpointResolutionOutcome, EnableControl, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE, endpointResolutionOutcome.GetError().GetMessage()); endpointResolutionOutcome.GetResult().AddPathSegments("/enable-control"); return EnableControlOutcome(MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER)); }, TracingUtils::SMITHY_CLIENT_DURATION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); } GetControlOperationOutcome ControlTowerClient::GetControlOperation(const GetControlOperationRequest& request) const { AWS_OPERATION_GUARD(GetControlOperation); AWS_OPERATION_CHECK_PTR(m_endpointProvider, GetControlOperation, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE); AWS_OPERATION_CHECK_PTR(m_telemetryProvider, GetControlOperation, CoreErrors, CoreErrors::NOT_INITIALIZED); auto tracer = m_telemetryProvider->getTracer(this->GetServiceClientName(), {}); auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); AWS_OPERATION_CHECK_PTR(meter, GetControlOperation, CoreErrors, CoreErrors::NOT_INITIALIZED); auto span = tracer->CreateSpan(Aws::String(this->GetServiceClientName()) + ".GetControlOperation", {{ TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName() }, { TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName() }, { TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE }}, smithy::components::tracing::SpanKind::CLIENT); return TracingUtils::MakeCallWithTiming<GetControlOperationOutcome>( [&]()-> GetControlOperationOutcome { auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); AWS_OPERATION_CHECK_SUCCESS(endpointResolutionOutcome, GetControlOperation, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE, endpointResolutionOutcome.GetError().GetMessage()); endpointResolutionOutcome.GetResult().AddPathSegments("/get-control-operation"); return GetControlOperationOutcome(MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER)); }, TracingUtils::SMITHY_CLIENT_DURATION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); } ListEnabledControlsOutcome ControlTowerClient::ListEnabledControls(const ListEnabledControlsRequest& request) const { AWS_OPERATION_GUARD(ListEnabledControls); AWS_OPERATION_CHECK_PTR(m_endpointProvider, ListEnabledControls, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE); AWS_OPERATION_CHECK_PTR(m_telemetryProvider, ListEnabledControls, CoreErrors, CoreErrors::NOT_INITIALIZED); auto tracer = m_telemetryProvider->getTracer(this->GetServiceClientName(), {}); auto meter = m_telemetryProvider->getMeter(this->GetServiceClientName(), {}); AWS_OPERATION_CHECK_PTR(meter, ListEnabledControls, CoreErrors, CoreErrors::NOT_INITIALIZED); auto span = tracer->CreateSpan(Aws::String(this->GetServiceClientName()) + ".ListEnabledControls", {{ TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName() }, { TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName() }, { TracingUtils::SMITHY_SYSTEM_DIMENSION, TracingUtils::SMITHY_METHOD_AWS_VALUE }}, smithy::components::tracing::SpanKind::CLIENT); return TracingUtils::MakeCallWithTiming<ListEnabledControlsOutcome>( [&]()-> ListEnabledControlsOutcome { auto endpointResolutionOutcome = TracingUtils::MakeCallWithTiming<ResolveEndpointOutcome>( [&]() -> ResolveEndpointOutcome { return m_endpointProvider->ResolveEndpoint(request.GetEndpointContextParams()); }, TracingUtils::SMITHY_CLIENT_ENDPOINT_RESOLUTION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); AWS_OPERATION_CHECK_SUCCESS(endpointResolutionOutcome, ListEnabledControls, CoreErrors, CoreErrors::ENDPOINT_RESOLUTION_FAILURE, endpointResolutionOutcome.GetError().GetMessage()); endpointResolutionOutcome.GetResult().AddPathSegments("/list-enabled-controls"); return ListEnabledControlsOutcome(MakeRequest(request, endpointResolutionOutcome.GetResult(), Aws::Http::HttpMethod::HTTP_POST, Aws::Auth::SIGV4_SIGNER)); }, TracingUtils::SMITHY_CLIENT_DURATION_METRIC, *meter, {{TracingUtils::SMITHY_METHOD_DIMENSION, request.GetServiceRequestName()}, {TracingUtils::SMITHY_SERVICE_DIMENSION, this->GetServiceClientName()}}); }