use of software.amazon.awssdk.profiles.Profile in project aws-sdk-java-v2 by aws.
the class DualstackEnabledProvider method isDualstackEnabled.
/**
* Returns true when dualstack should be used, false when dualstack should not be used, and empty when there is no global
* dualstack configuration.
*/
public Optional<Boolean> isDualstackEnabled() {
Optional<Boolean> setting = SdkSystemSetting.AWS_USE_DUALSTACK_ENDPOINT.getBooleanValue();
if (setting.isPresent()) {
return setting;
}
ProfileFile profileFile = this.profileFile.get();
Optional<Profile> profile = profileFile.profile(profileName());
return profile.flatMap(p -> p.booleanProperty(ProfileProperty.USE_DUALSTACK_ENDPOINT));
}
use of software.amazon.awssdk.profiles.Profile in project aws-sdk-java-v2 by aws.
the class AssumeRoleIntegrationTest method profileCredentialsProviderCanAssumeRoles.
@Test
public void profileCredentialsProviderCanAssumeRoles() throws InterruptedException {
String ASSUME_ROLE_PROFILE = "[source]\n" + "aws_access_key_id = " + userCredentials.accessKeyId() + "\n" + "aws_secret_access_key = " + userCredentials.secretAccessKey() + "\n" + "\n" + "[test]\n" + "region = us-west-1\n" + "source_profile = source\n" + "role_arn = " + ROLE_ARN;
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(ASSUME_ROLE_PROFILE)).type(ProfileFile.Type.CREDENTIALS).build();
Optional<Profile> profile = profiles.profile("test");
AwsCredentialsProvider awsCredentialsProvider = new ProfileCredentialsUtils(profiles, profile.get(), profiles::profile).credentialsProvider().get();
// Try to assume the role until the eventual consistency catches up.
AwsCredentials awsCredentials = Waiter.run(awsCredentialsProvider::resolveCredentials).ignoringException(StsException.class).orFail();
assertThat(awsCredentials.accessKeyId()).isNotBlank();
assertThat(awsCredentials.secretAccessKey()).isNotBlank();
((SdkAutoCloseable) awsCredentialsProvider).close();
}
use of software.amazon.awssdk.profiles.Profile in project aws-sdk-java-v2 by aws.
the class AssumeRoleIntegrationTest method profileCredentialProviderCanAssumeRolesWithEnvironmentCredentialSource.
@Test
public void profileCredentialProviderCanAssumeRolesWithEnvironmentCredentialSource() throws InterruptedException {
EnvironmentVariableHelper.run(helper -> {
helper.set("AWS_ACCESS_KEY_ID", userCredentials.accessKeyId());
helper.set("AWS_SECRET_ACCESS_KEY", userCredentials.secretAccessKey());
helper.remove("AWS_SESSION_TOKEN");
String ASSUME_ROLE_PROFILE = "[test]\n" + "region = us-west-1\n" + "credential_source = Environment\n" + "role_arn = " + ROLE_ARN;
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(ASSUME_ROLE_PROFILE)).type(ProfileFile.Type.CREDENTIALS).build();
Optional<Profile> profile = profiles.profile("test");
AwsCredentialsProvider awsCredentialsProvider = new ProfileCredentialsUtils(profiles, profile.get(), profiles::profile).credentialsProvider().get();
// Try to assume the role until the eventual consistency catches up.
AwsCredentials awsCredentials = Waiter.run(awsCredentialsProvider::resolveCredentials).ignoringException(StsException.class).orFail();
assertThat(awsCredentials.accessKeyId()).isNotBlank();
assertThat(awsCredentials.secretAccessKey()).isNotBlank();
((SdkAutoCloseable) awsCredentialsProvider).close();
});
}
use of software.amazon.awssdk.profiles.Profile in project aws-sdk-java-v2 by aws.
the class AssumeRoleIntegrationTest method profileCredentialProviderWithEnvironmentCredentialSourceAndSystemProperties.
@Test
public void profileCredentialProviderWithEnvironmentCredentialSourceAndSystemProperties() throws InterruptedException {
System.setProperty("aws.accessKeyId", userCredentials.accessKeyId());
System.setProperty("aws.secretAccessKey", userCredentials.secretAccessKey());
try {
EnvironmentVariableHelper.run(helper -> {
helper.remove("AWS_ACCESS_KEY_ID");
helper.remove("AWS_SECRET_ACCESS_KEY");
helper.remove("AWS_SESSION_TOKEN");
String ASSUME_ROLE_PROFILE = "[test]\n" + "region = us-west-1\n" + "credential_source = Environment\n" + "role_arn = " + ROLE_ARN;
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(ASSUME_ROLE_PROFILE)).type(ProfileFile.Type.CREDENTIALS).build();
Optional<Profile> profile = profiles.profile("test");
AwsCredentialsProvider awsCredentialsProvider = new ProfileCredentialsUtils(profiles, profile.get(), profiles::profile).credentialsProvider().get();
// Try to assume the role until the eventual consistency catches up.
AwsCredentials awsCredentials = Waiter.run(awsCredentialsProvider::resolveCredentials).ignoringException(StsException.class).orFail();
assertThat(awsCredentials.accessKeyId()).isNotBlank();
assertThat(awsCredentials.secretAccessKey()).isNotBlank();
((SdkAutoCloseable) awsCredentialsProvider).close();
});
} finally {
System.clearProperty("aws.accessKeyId");
System.clearProperty("aws.secretAccessKey");
}
}
use of software.amazon.awssdk.profiles.Profile in project aws-sdk-java-v2 by aws.
the class SsoProfileCredentialsProviderFactoryTest method createSsoCredentialsProviderWithFactorySucceed.
@Test
public void createSsoCredentialsProviderWithFactorySucceed() throws IOException {
String startUrl = "https//d-abc123.awsapps.com/start";
String generatedTokenFileName = "6a888bdb653a4ba345dd68f21b896ec2e218c6f4.json";
Map<String, String> properties = new HashMap<>();
properties.put("sso_account_id", "accountId");
properties.put("sso_region", "region");
properties.put("sso_role_name", "roleName");
properties.put("sso_start_url", "https//d-abc123.awsapps.com/start");
Profile profile = Profile.builder().name("foo").properties(properties).build();
String tokenFile = "{\n" + "\"accessToken\": \"base64string\",\n" + "\"expiresAt\": \"2090-01-01T00:00:00Z\",\n" + "\"region\": \"us-west-2\", \n" + "\"startUrl\": \"" + startUrl + "\"\n" + "}";
SsoAccessTokenProvider tokenProvider = new SsoAccessTokenProvider(prepareTestCachedTokenFile(tokenFile, generatedTokenFileName));
SsoProfileCredentialsProviderFactory factory = new SsoProfileCredentialsProviderFactory();
assertThat(factory.create(profile, tokenProvider)).isInstanceOf(AwsCredentialsProvider.class);
}
Aggregations