All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.cloudformation.proxy.ProxyClient Maven / Gradle / Ivy

/*
* Copyright 2010-2019 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.cloudformation.proxy;

import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

import software.amazon.awssdk.awscore.AwsRequest;
import software.amazon.awssdk.awscore.AwsResponse;

/**
 * This class provides a wrapper for the client and provides methods to inject
 * scoped credentials for each request context when invoking AWS services. This
 * is the primary mechanism for handlers to invoke service requests to ensure
 * the right scoped credentials are being injected. IMPORTANT: DO NOT
 * DIRECTLY INVOKE methods on the client. Use the client to provide method
 * references to be invoked. See example below
 *
 * {@code
 *    CreateStreamResponse call(ProxyClient client, CreateStreamRequest request) {
 *        return client.injectCredentialsAndInvokeV2( request,
 * client.client()::createStream); // method reference } }
 *
 * @param  the AWS client like KinesisClient that is used to invoke the
 *            web service
 */
public interface ProxyClient {
    /**
     * This is the synchronous version of making API calls.
     *
     * @param request, the AWS service request that we need to make
     * @param requestFunction, this is a Lambda closure that provide the actual API
     *            that needs to the invoked.
     * @param  the request type
     * @param  the response from the request
     * @return the response if successful. Else it will propagate all
     *         {@link software.amazon.awssdk.awscore.exception.AwsServiceException}
     *         that is thrown or
     *         {@link software.amazon.awssdk.core.exception.SdkClientException} if
     *         there is client side problem
     *
     */
    
        ResponseT
        injectCredentialsAndInvokeV2(RequestT request, Function requestFunction);

    /**
     * This is the asynchronous version of making API calls.
     *
     * @param request, the AWS service request that we need to make
     * @param requestFunction, this is a Lambda closure that provide the actual API
     *            that needs to the invoked.
     * @param  the request type
     * @param  the response from the request
     * @return the response if successful. Else it will propagate all
     *         {@link software.amazon.awssdk.awscore.exception.AwsServiceException}
     *         that is thrown or
     *         {@link software.amazon.awssdk.core.exception.SdkClientException} if
     *         there is client side problem
     */
    
        CompletableFuture
        injectCredentialsAndInvokeV2Aync(RequestT request, Function> requestFunction);

    /**
     * @return the actual AWS service client that we need to use to provide the
     *         actual method we are going to call.
     */
    ClientT client();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy