software.amazon.awssdk.services.neptunegraph.endpoints.internal.NeptuneGraphResolveEndpointInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neptunegraph Show documentation
Show all versions of neptunegraph Show documentation
The AWS Java SDK for Neptune Graph module holds the client classes that are used for
communicating with Neptune Graph.
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.neptunegraph.endpoints.internal;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletionException;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.AwsExecutionAttribute;
import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute;
import software.amazon.awssdk.awscore.endpoints.authscheme.EndpointAuthScheme;
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme;
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.SelectedAuthScheme;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.interceptor.Context;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.endpoints.Endpoint;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner;
import software.amazon.awssdk.http.auth.aws.signer.RegionSet;
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
import software.amazon.awssdk.identity.spi.Identity;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.services.neptunegraph.endpoints.NeptuneGraphEndpointParams;
import software.amazon.awssdk.services.neptunegraph.endpoints.NeptuneGraphEndpointProvider;
import software.amazon.awssdk.utils.HostnameValidator;
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
public final class NeptuneGraphResolveEndpointInterceptor implements ExecutionInterceptor {
@Override
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
SdkRequest result = context.request();
if (AwsEndpointProviderUtils.endpointIsDiscovered(executionAttributes)) {
return result;
}
NeptuneGraphEndpointProvider provider = (NeptuneGraphEndpointProvider) executionAttributes
.getAttribute(SdkInternalExecutionAttribute.ENDPOINT_PROVIDER);
try {
long resolveEndpointStart = System.nanoTime();
Endpoint endpoint = provider.resolveEndpoint(ruleParams(result, executionAttributes)).join();
Duration resolveEndpointDuration = Duration.ofNanos(System.nanoTime() - resolveEndpointStart);
Optional metricCollector = executionAttributes
.getOptionalAttribute(SdkExecutionAttribute.API_CALL_METRIC_COLLECTOR);
metricCollector.ifPresent(mc -> mc.reportMetric(CoreMetric.ENDPOINT_RESOLVE_DURATION, resolveEndpointDuration));
if (!AwsEndpointProviderUtils.disableHostPrefixInjection(executionAttributes)) {
Optional hostPrefix = hostPrefix(executionAttributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME),
result);
if (hostPrefix.isPresent()) {
endpoint = AwsEndpointProviderUtils.addHostPrefix(endpoint, hostPrefix.get());
}
}
List endpointAuthSchemes = endpoint.attribute(AwsEndpointAttribute.AUTH_SCHEMES);
SelectedAuthScheme> selectedAuthScheme = executionAttributes
.getAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME);
if (endpointAuthSchemes != null && selectedAuthScheme != null) {
selectedAuthScheme = authSchemeWithEndpointSignerProperties(endpointAuthSchemes, selectedAuthScheme);
executionAttributes.putAttribute(SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME, selectedAuthScheme);
}
executionAttributes.putAttribute(SdkInternalExecutionAttribute.RESOLVED_ENDPOINT, endpoint);
return result;
} catch (CompletionException e) {
Throwable cause = e.getCause();
if (cause instanceof SdkClientException) {
throw (SdkClientException) cause;
} else {
throw SdkClientException.create("Endpoint resolution failed", cause);
}
}
}
@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
Endpoint resolvedEndpoint = executionAttributes.getAttribute(SdkInternalExecutionAttribute.RESOLVED_ENDPOINT);
if (resolvedEndpoint.headers().isEmpty()) {
return context.httpRequest();
}
SdkHttpRequest.Builder httpRequestBuilder = context.httpRequest().toBuilder();
resolvedEndpoint.headers().forEach((name, values) -> {
values.forEach(v -> httpRequestBuilder.appendHeader(name, v));
});
return httpRequestBuilder.build();
}
public static NeptuneGraphEndpointParams ruleParams(SdkRequest request, ExecutionAttributes executionAttributes) {
NeptuneGraphEndpointParams.Builder builder = NeptuneGraphEndpointParams.builder();
builder.region(AwsEndpointProviderUtils.regionBuiltIn(executionAttributes));
builder.useFips(AwsEndpointProviderUtils.fipsEnabledBuiltIn(executionAttributes));
builder.useDualStack(AwsEndpointProviderUtils.dualStackEnabledBuiltIn(executionAttributes));
builder.endpoint(AwsEndpointProviderUtils.endpointBuiltIn(executionAttributes));
setContextParams(builder, executionAttributes.getAttribute(AwsExecutionAttribute.OPERATION_NAME), request);
setStaticContextParams(builder, executionAttributes.getAttribute(AwsExecutionAttribute.OPERATION_NAME));
return builder.build();
}
private static void setContextParams(NeptuneGraphEndpointParams.Builder params, String operationName, SdkRequest request) {
}
private static void setStaticContextParams(NeptuneGraphEndpointParams.Builder params, String operationName) {
switch (operationName) {
case "CancelImportTask":
cancelImportTaskStaticContextParams(params);
break;
case "CancelQuery":
cancelQueryStaticContextParams(params);
break;
case "CreateGraph":
createGraphStaticContextParams(params);
break;
case "CreateGraphSnapshot":
createGraphSnapshotStaticContextParams(params);
break;
case "CreateGraphUsingImportTask":
createGraphUsingImportTaskStaticContextParams(params);
break;
case "CreatePrivateGraphEndpoint":
createPrivateGraphEndpointStaticContextParams(params);
break;
case "DeleteGraph":
deleteGraphStaticContextParams(params);
break;
case "DeleteGraphSnapshot":
deleteGraphSnapshotStaticContextParams(params);
break;
case "DeletePrivateGraphEndpoint":
deletePrivateGraphEndpointStaticContextParams(params);
break;
case "ExecuteQuery":
executeQueryStaticContextParams(params);
break;
case "GetGraph":
getGraphStaticContextParams(params);
break;
case "GetGraphSnapshot":
getGraphSnapshotStaticContextParams(params);
break;
case "GetGraphSummary":
getGraphSummaryStaticContextParams(params);
break;
case "GetImportTask":
getImportTaskStaticContextParams(params);
break;
case "GetPrivateGraphEndpoint":
getPrivateGraphEndpointStaticContextParams(params);
break;
case "GetQuery":
getQueryStaticContextParams(params);
break;
case "ListGraphSnapshots":
listGraphSnapshotsStaticContextParams(params);
break;
case "ListGraphs":
listGraphsStaticContextParams(params);
break;
case "ListImportTasks":
listImportTasksStaticContextParams(params);
break;
case "ListPrivateGraphEndpoints":
listPrivateGraphEndpointsStaticContextParams(params);
break;
case "ListQueries":
listQueriesStaticContextParams(params);
break;
case "ListTagsForResource":
listTagsForResourceStaticContextParams(params);
break;
case "ResetGraph":
resetGraphStaticContextParams(params);
break;
case "RestoreGraphFromSnapshot":
restoreGraphFromSnapshotStaticContextParams(params);
break;
case "StartImportTask":
startImportTaskStaticContextParams(params);
break;
case "TagResource":
tagResourceStaticContextParams(params);
break;
case "UntagResource":
untagResourceStaticContextParams(params);
break;
case "UpdateGraph":
updateGraphStaticContextParams(params);
break;
default:
break;
}
}
private static void cancelImportTaskStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void cancelQueryStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("DataPlane");
}
private static void createGraphStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void createGraphSnapshotStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void createGraphUsingImportTaskStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void createPrivateGraphEndpointStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void deleteGraphStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void deleteGraphSnapshotStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void deletePrivateGraphEndpointStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void executeQueryStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("DataPlane");
}
private static void getGraphStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void getGraphSnapshotStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void getGraphSummaryStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("DataPlane");
}
private static void getImportTaskStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void getPrivateGraphEndpointStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void getQueryStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("DataPlane");
}
private static void listGraphSnapshotsStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void listGraphsStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void listImportTasksStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void listPrivateGraphEndpointsStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void listQueriesStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("DataPlane");
}
private static void listTagsForResourceStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void resetGraphStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void restoreGraphFromSnapshotStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void startImportTaskStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void tagResourceStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void untagResourceStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private static void updateGraphStaticContextParams(NeptuneGraphEndpointParams.Builder params) {
params.apiType("ControlPlane");
}
private SelectedAuthScheme authSchemeWithEndpointSignerProperties(
List endpointAuthSchemes, SelectedAuthScheme selectedAuthScheme) {
for (EndpointAuthScheme endpointAuthScheme : endpointAuthSchemes) {
if (!endpointAuthScheme.schemeId().equals(selectedAuthScheme.authSchemeOption().schemeId())) {
continue;
}
AuthSchemeOption.Builder option = selectedAuthScheme.authSchemeOption().toBuilder();
if (endpointAuthScheme instanceof SigV4AuthScheme) {
SigV4AuthScheme v4AuthScheme = (SigV4AuthScheme) endpointAuthScheme;
if (v4AuthScheme.isDisableDoubleEncodingSet()) {
option.putSignerProperty(AwsV4HttpSigner.DOUBLE_URL_ENCODE, !v4AuthScheme.disableDoubleEncoding());
}
if (v4AuthScheme.signingRegion() != null) {
option.putSignerProperty(AwsV4HttpSigner.REGION_NAME, v4AuthScheme.signingRegion());
}
if (v4AuthScheme.signingName() != null) {
option.putSignerProperty(AwsV4HttpSigner.SERVICE_SIGNING_NAME, v4AuthScheme.signingName());
}
return new SelectedAuthScheme<>(selectedAuthScheme.identity(), selectedAuthScheme.signer(), option.build());
}
if (endpointAuthScheme instanceof SigV4aAuthScheme) {
SigV4aAuthScheme v4aAuthScheme = (SigV4aAuthScheme) endpointAuthScheme;
if (v4aAuthScheme.isDisableDoubleEncodingSet()) {
option.putSignerProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, !v4aAuthScheme.disableDoubleEncoding());
}
if (v4aAuthScheme.signingRegionSet() != null) {
RegionSet regionSet = RegionSet.create(v4aAuthScheme.signingRegionSet());
option.putSignerProperty(AwsV4aHttpSigner.REGION_SET, regionSet);
}
if (v4aAuthScheme.signingName() != null) {
option.putSignerProperty(AwsV4aHttpSigner.SERVICE_SIGNING_NAME, v4aAuthScheme.signingName());
}
return new SelectedAuthScheme<>(selectedAuthScheme.identity(), selectedAuthScheme.signer(), option.build());
}
throw new IllegalArgumentException("Endpoint auth scheme '" + endpointAuthScheme.name()
+ "' cannot be mapped to the SDK auth scheme. Was it declared in the service's model?");
}
return selectedAuthScheme;
}
private static Optional hostPrefix(String operationName, SdkRequest request) {
switch (operationName) {
case "CancelQuery": {
HostnameValidator.validateHostnameCompliant(request.getValueForField("graphIdentifier", String.class).orElse(null),
"graphIdentifier", "cancelQueryRequest");
return Optional.of(String.format("%s.", request.getValueForField("graphIdentifier", String.class).get()));
}
case "ExecuteQuery": {
HostnameValidator.validateHostnameCompliant(request.getValueForField("graphIdentifier", String.class).orElse(null),
"graphIdentifier", "executeQueryRequest");
return Optional.of(String.format("%s.", request.getValueForField("graphIdentifier", String.class).get()));
}
case "GetGraphSummary": {
HostnameValidator.validateHostnameCompliant(request.getValueForField("graphIdentifier", String.class).orElse(null),
"graphIdentifier", "getGraphSummaryRequest");
return Optional.of(String.format("%s.", request.getValueForField("graphIdentifier", String.class).get()));
}
case "GetQuery": {
HostnameValidator.validateHostnameCompliant(request.getValueForField("graphIdentifier", String.class).orElse(null),
"graphIdentifier", "getQueryRequest");
return Optional.of(String.format("%s.", request.getValueForField("graphIdentifier", String.class).get()));
}
case "ListQueries": {
HostnameValidator.validateHostnameCompliant(request.getValueForField("graphIdentifier", String.class).orElse(null),
"graphIdentifier", "listQueriesRequest");
return Optional.of(String.format("%s.", request.getValueForField("graphIdentifier", String.class).get()));
}
default:
return Optional.empty();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy