/** * Creates a new profile credentials provider that returns the AWS security credentials for the * specified profiles configuration file and profile name. * * @param profilesConfigFilePath The file path where the profile configuration file is located. * @param profileName The name of a configuration profile in the specified * configuration file. */ public ProfileCredentialsProvider(String profilesConfigFilePath, String profileName) { this(new ProfilesConfigFile(profilesConfigFilePath), profileName); }
/** * Loads the AWS credential profiles file from the default location (~/.aws/credentials) or from * an alternate location if <code>AWS_CREDENTIAL_PROFILES_FILE</code> is set. */ public ProfilesConfigFile() throws SdkClientException { this(getCredentialProfilesFile()); }
/** * Loads the AWS credential profiles from the file. The path of the file is specified as a * parameter to the constructor. */ public ProfilesConfigFile(String filePath) { this(new File(validateFilePath(filePath))); }
@Override public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) { String profileName = properties.get(CredentialPropertyDescriptors.PROFILE_NAME); return new ProfileCredentialsProvider(profileName); }
public ClusterGraphService(String s3CredentialsFilename, Boolean workOffline, String bucket) { if(!workOffline) { if (s3CredentialsFilename != null) { AWSCredentials creds = new ProfileCredentialsProvider(s3CredentialsFilename, "default").getCredentials(); s3 = new AmazonS3Client(creds); } else { // This will first check for credentials in environment variables or ~/.aws/credentials // then fall back on S3 credentials propagated to EC2 instances via IAM roles. s3 = new AmazonS3Client(); } this.graphBucket = bucket; } this.workOffline = workOffline; }
private synchronized BasicProfile getProfile(String profileName) { return getProfilesConfigFile().getAllBasicProfiles().get(profileName); }
private void writeLine(String line) { append(String.format("%s%n", line)); }
private void writeProfileName(String profileName) { writeLine(String.format("[%s]", profileName)); }
/** * Reread data from disk. */ public void refresh() { if (profileFile.lastModified() > profileFileLastModified) { profileFileLastModified = profileFile.lastModified(); allProfiles = loadProfiles(profileFile); } credentialProviderCache.clear(); }
@Override public void refresh() { if (profilesConfigFile != null) { profilesConfigFile.refresh(); lastRefreshed = System.nanoTime(); } }
/** * Modify one profile in the existing credentials file by in-place * modification. This method will rename the existing profile if the * specified Profile has a different name. * * @param destination * The destination file to modify * @param profileName * The name of the existing profile to be modified * @param newProfile * The new Profile object. */ public static void modifyOneProfile(File destination, String profileName, Profile newProfile) { final Map<String, Profile> modifications = Collections.singletonMap(profileName, newProfile); modifyProfiles(destination, modifications); }
/** * Read the existing content of a credentials file, and then make * in-place modification according to the new profiles specified in this * class. */ public void writeWithExistingContent(Scanner existingContent) { buffer.setLength(0); existingProfileProperties.clear(); run(existingContent); }
@Override protected void onEmptyOrCommentLine(String profileName, String line) { /* * Buffer the line until we reach the next property line or the end * of the profile. We do this so that new properties could be * inserted at more appropriate location. For example: * * [default] * # access key * aws_access_key_id=aaa * # secret key * aws_secret_access_key=sss * # We want new properties to be inserted before this line * # instead of after the following empty line * * [next profile] * ... */ if (profileName == null || !deletedProfiles.contains(profileName)) { buffer(line); } }
@Bean public ProfileCredentialsProvider profileCredentialsProvider() { return new ProfileCredentialsProvider(CREDENTIALS_PROFILE_NAME); }
private ProfilesConfigFile getProfilesConfigFile() { if (configFile == null) { synchronized (this) { if (configFile == null) { try { configFile = new ProfilesConfigFile(configFileLocationProvider.getLocation()); } catch (Exception e) { throw new SdkClientException("Unable to load config file", e); } } } } return configFile; } }
/** * Loads the AWS credential profiles from the file. The path of the file is specified as a * parameter to the constructor. */ public ProfilesConfigFile(String filePath, ProfileCredentialsService credentialsService) throws SdkClientException { this(new File(validateFilePath(filePath)), credentialsService); }
private void flush() { if (buffer.length() != 0) { append(buffer.toString()); buffer.setLength(0); } }
private void writeProperty(String propertyKey, String propertyValue) { writeLine(String.format("%s=%s", propertyKey, propertyValue)); }
/** * Loads the AWS credential profiles from the file. The reference to the file is specified as a * parameter to the constructor. */ public ProfilesConfigFile(File file, ProfileCredentialsService credentialsService) throws SdkClientException { profileFile = ValidationUtils.assertNotNull(file, "profile file"); profileCredentialsService = credentialsService; profileFileLastModified = file.lastModified(); allProfiles = loadProfiles(profileFile); }
public CredentialsProviderChain () { super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider()); } }