Search in sources :

Example 1 with AsyncRequestBodySigner

use of software.amazon.awssdk.core.signer.AsyncRequestBodySigner in project aws-sdk-java-v2 by aws.

the class SigningStage method signRequest.

/**
 * Sign the request if the signer if provided and credentials are present.
 */
private SdkHttpFullRequest signRequest(SdkHttpFullRequest request, RequestExecutionContext context) throws Exception {
    updateInterceptorContext(request, context.executionContext());
    Signer signer = context.signer();
    MetricCollector metricCollector = context.attemptMetricCollector();
    if (shouldSign(signer)) {
        adjustForClockSkew(context.executionAttributes());
        Pair<SdkHttpFullRequest, Duration> measuredSign = MetricUtils.measureDuration(() -> signer.sign(request, context.executionAttributes()));
        metricCollector.reportMetric(CoreMetric.SIGNING_DURATION, measuredSign.right());
        SdkHttpFullRequest signedRequest = measuredSign.left();
        if (signer instanceof AsyncRequestBodySigner) {
            // Transform request body provider with signing operator
            AsyncRequestBody transformedRequestProvider = ((AsyncRequestBodySigner) signer).signAsyncRequestBody(signedRequest, context.requestProvider(), context.executionAttributes());
            context.requestProvider(transformedRequestProvider);
        }
        updateInterceptorContext(signedRequest, context.executionContext());
        return signedRequest;
    }
    return request;
}
Also used : AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner) Signer(software.amazon.awssdk.core.signer.Signer) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Duration(java.time.Duration) AsyncRequestBodySigner(software.amazon.awssdk.core.signer.AsyncRequestBodySigner)

Aggregations

Duration (java.time.Duration)1 AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)1 AsyncRequestBodySigner (software.amazon.awssdk.core.signer.AsyncRequestBodySigner)1 Signer (software.amazon.awssdk.core.signer.Signer)1 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)1 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)1