Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 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 com.amazonaws.auth.profile;
 
Credentials provider based on AWS configuration profiles. This provider vends AWSCredentials from the profile configuration file for the default profile, or for a specific, named profile.

AWS credential profiles allow you to share multiple sets of AWS security credentials between different tools like the AWS SDK for Java and the AWS CLI.

See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html

 
 public class ProfileCredentialsProvider implements AWSCredentialsProvider {

    
The credential profiles file from which this provider loads the security credentials. Lazily loaded by the double-check idiom.
 
     private volatile ProfilesConfigFile profilesConfigFile;

    
The name of the credential profile
 
     private final String profileName;

    
Creates a new profile credentials provider that returns the AWS security credentials configured for the default profile. Loading the credential file is deferred until the getCredentials() method is called.
 
     public ProfileCredentialsProvider() {
         this(null);
     }

    
Creates a new profile credentials provider that returns the AWS security credentials configured for the named profile. Loading the credential file is deferred until the getCredentials() method is called.

Parameters:
profileName The name of a local configuration profile.
 
     public ProfileCredentialsProvider(String profileName) {
         this((ProfilesConfigFile)nullprofileName);
     }

    
Creates a new profile credentials provider that returns the AWS security credentials for the specified profiles configuration file and profile name.

Parameters:
profilesConfigFilePath The file path where the profile configuration file is located.
profileName The name of a configuration profile in the specified configuration file.
 
     public ProfileCredentialsProvider(String profilesConfigFilePathString profileName) {
         this(new ProfilesConfigFile(profilesConfigFilePath), profileName);
     }

    
Creates a new profile credentials provider that returns the AWS security credentials for the specified profiles configuration file and profile name.

Parameters:
profilesConfigFile The profile configuration file containing the profiles used by this credentials provider.
profileName The name of a configuration profile in the specified configuration file.
 
     public ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFileString profileName) {
         this. = profilesConfigFile;
         if (profileName == null) {
            String profileEnvVarOverride = System.getenv(.);
            profileEnvVarOverride = StringUtils.trim(profileEnvVarOverride);
            if (!StringUtils.isNullOrEmpty(profileEnvVarOverride)) {
                this. = profileEnvVarOverride;
            } else {
                String profileSysPropOverride = System.getProperty(.);
                profileSysPropOverride = StringUtils.trim(profileSysPropOverride);
                if (!StringUtils.isNullOrEmpty(profileSysPropOverride)) {
                    this. = profileSysPropOverride;
                } else {
                    this. = .;
                }
            }
        } else {
            this. = profileName;
        }
    }
    @Override
    public AWSCredentials getCredentials() {
        if ( == null) {
            synchronized (this) {
                if ( == null) {
                     = new ProfilesConfigFile();
                }
            }
        }
    }
    @Override
    public void refresh() {}
New to GrepCode? Check out our FAQ X