1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.regions.util;
17 
18 import java.io.IOException;
19 import java.net.URI;
20 import java.util.HashMap;
21 import java.util.Map;
22 import software.amazon.awssdk.annotations.SdkProtectedApi;
23 import software.amazon.awssdk.core.util.SdkUserAgent;
24 
25 /**
26  * <p>
27  * Abstract class to return an endpoint URI from which the resources can be loaded.
28  * </p>
29  * <p>
30  * By default, the request won't be retried if the request fails while computing endpoint.
31  * </p>
32  */
33 @SdkProtectedApi
34 @FunctionalInterface
35 public interface ResourcesEndpointProvider {
36     /**
37      * Returns the URI that contains the credentials.
38      * @return
39      *         URI to retrieve the credentials.
40      *
41      * @throws IOException
42      *                 If any problems are encountered while connecting to the
43      *                 service to retrieve the endpoint.
44      */
endpoint()45     URI endpoint() throws IOException;
46 
47     /**
48      * Allows the extending class to provide a custom retry policy.
49      * The default behavior is not to retry.
50      */
retryPolicy()51     default ResourcesEndpointRetryPolicy retryPolicy() {
52         return ResourcesEndpointRetryPolicy.NO_RETRY;
53     }
54 
55     /**
56      * Allows passing additional headers to the request
57      */
headers()58     default Map<String, String> headers() {
59         Map<String, String> requestHeaders = new HashMap<>();
60         requestHeaders.put("User-Agent", SdkUserAgent.create().userAgent());
61         requestHeaders.put("Accept", "*/*");
62         requestHeaders.put("Connection", "keep-alive");
63 
64         return requestHeaders;
65     }
66 
67 }
68