1 /*
2  * Copyright 2011-2020 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  * You may obtain a copy of the License at:
7  *
8  *    http://aws.amazon.com/apache2.0
9  *
10  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11  * OR CONDITIONS OF ANY KIND, either express or implied. See the
12  * License for the specific language governing permissions and
13  * limitations under the License.
14  */

15 package com.amazonaws.auth;
16
17 import com.amazonaws.annotation.SdkInternalApi;
18 import com.amazonaws.internal.EC2ResourceFetcher;
19 import com.amazonaws.internal.CredentialsEndpointProvider;
20
21 /**
22  * Loads the credentials from a local endpoint on a container.
23  */

24 @SdkInternalApi
25 class ContainerCredentialsFetcher extends BaseCredentialsFetcher {
26
27     /** Used to load the endpoint where the credentials are stored. */
28     private final CredentialsEndpointProvider credentialsEndpointProvider;
29
30     ContainerCredentialsFetcher(CredentialsEndpointProvider credentialsEndpointProvider) {
31         this.credentialsEndpointProvider = credentialsEndpointProvider;
32     }
33
34     @Override
35     protected String getCredentialsResponse() {
36         return EC2ResourceFetcher.defaultResourceFetcher().readResource(
37             credentialsEndpointProvider.getCredentialsEndpoint(),
38             credentialsEndpointProvider.getRetryPolicy(),
39             credentialsEndpointProvider.getHeaders()
40         );
41     }
42
43     @Override
44     public String toString() {
45         return "ContainerCredentialsFetcher";
46     }
47 }
48