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.cred;
16
17 import com.amazonaws.annotation.SdkInternalApi;
18 import com.amazonaws.profile.path.AwsDirectoryBasePathProvider;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import java.io.File;
24
25 /**
26  * Treats the CLI config file as the source of credentials. We support this for legacy reasons,
27  * ideally credentials should be defined in the separate shared credentials file
28  * (~/.aws/credentials). Any credentials defined in the shared credentials file take precedence over
29  * credentials sourced from here.
30  */

31 @SdkInternalApi
32 public class CredentialsLegacyConfigLocationProvider extends AwsDirectoryBasePathProvider {
33
34     private static final Log LOG = LogFactory.getLog(CredentialsLegacyConfigLocationProvider.class);
35
36     /**
37      * File name of the default location of the CLI config file.
38      */

39     private static final String LEGACY_CONFIG_PROFILES_FILENAME = "config";
40
41     @Override
42     public File getLocation() {
43         File legacyConfigProfiles = new File(getAwsDirectory(), LEGACY_CONFIG_PROFILES_FILENAME);
44         if (legacyConfigProfiles.exists() && legacyConfigProfiles.isFile()) {
45             LOG.warn("Found the legacy config profiles file at [" +
46                      legacyConfigProfiles.getAbsolutePath() +
47                      "]. Please move it to the latest default location [~/.aws/credentials].");
48             return legacyConfigProfiles;
49         }
50         return null;
51     }
52 }
53