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  * 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 package com.amazonaws.profile.path;
16
17 import com.amazonaws.annotation.SdkInternalApi;
18 import com.amazonaws.profile.path.AwsProfileFileLocationProvider;
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 /**
26  * Delegates to a chain of {@link AwsProfileFileLocationProvider}. Returns null if no provider in
27  * the chain can come up with a location to the shared credentials file.
28  */

29 @SdkInternalApi
30 public class AwsProfileFileLocationProviderChain implements AwsProfileFileLocationProvider {
31
32     private final List<AwsProfileFileLocationProvider> providers = new ArrayList<AwsProfileFileLocationProvider>();
33
34     public AwsProfileFileLocationProviderChain(AwsProfileFileLocationProvider... providers) {
35         Collections.addAll(this.providers, providers);
36     }
37
38     @Override
39     public File getLocation() {
40         for (AwsProfileFileLocationProvider provider : providers) {
41             File path = provider.getLocation();
42             if (path != null) {
43                 return path;
44             }
45         }
46         return null;
47     }
48 }
49