@Test public void testBoth() throws Exception { Map<String, String> immutableEnv = System.getenv(); Class<?> unMap = Class.forName("java.util.Collections$UnmodifiableMap"); Field m = unMap.getDeclaredField("m"); m.setAccessible(true); @SuppressWarnings("unchecked") Map<String, String> env = (Map<String, String>) m.get(immutableEnv); try { env.put(AwsProfileNameLoader.AWS_PROFILE_ENVIRONMENT_VARIABLE, "test"); System.setProperty(AwsProfileNameLoader.AWS_PROFILE_SYSTEM_PROPERTY, "bogus"); ProfileCredentialsProvider provider = newProvider(); AWSCredentials credentials = provider.getCredentials(); Assert.assertEquals("test", credentials.getAWSAccessKeyId()); Assert.assertEquals("test key", credentials.getAWSSecretKey()); } finally { System.setProperty(AwsProfileNameLoader.AWS_PROFILE_SYSTEM_PROPERTY, ""); env.remove(AwsProfileNameLoader.AWS_PROFILE_ENVIRONMENT_VARIABLE); } }
@Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); @Override AWSCredentials getCredentials(); @Override void refresh(); long getRefreshIntervalNanos(); void setRefreshIntervalNanos(long refreshIntervalNanos); long getRefreshForceIntervalNanos(); void setRefreshForceIntervalNanos(long refreshForceIntervalNanos); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); @Override AWSCredentials getCredentials(); @Override void refresh(); long getRefreshIntervalNanos(); void setRefreshIntervalNanos(long refreshIntervalNanos); long getRefreshForceIntervalNanos(); void setRefreshForceIntervalNanos(long refreshForceIntervalNanos);  }