use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsUtilsTest method profileWithBothCredentialSourceAndSourceProfileThrowsException.
@Test
public void profileWithBothCredentialSourceAndSourceProfileThrowsException() {
ProfileFile configFile = configFile("[profile test]\n" + "source_profile=source\n" + "credential_source=Environment\n" + "role_arn=arn:aws:iam::123456789012:role/testRole3\n" + "\n" + "[profile source]\n" + "aws_access_key_id=defaultAccessKey\n" + "aws_secret_access_key=defaultSecretAccessKey");
assertThatThrownBy(() -> new ProfileCredentialsUtils(configFile, configFile.profile("test").get(), configFile::profile).credentialsProvider()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Invalid profile file: profile has both source_profile and credential_source.");
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsUtilsTest method roleProfileWithMissingSourceThrowsException.
@Test
public void roleProfileWithMissingSourceThrowsException() {
ProfileFile profileFile = configFile("[profile test]\n" + "source_profile=source\n" + "role_arn=arn:aws:iam::123456789012:role/testRole");
assertThatThrownBy(new ProfileCredentialsUtils(profileFile, profileFile.profile("test").get(), profileFile::profile)::credentialsProvider).hasMessageContaining("source profile has no credentials configured.");
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsUtilsTest method roleProfileCanInheritFromAnotherFile.
@Test
public void roleProfileCanInheritFromAnotherFile() {
String sourceProperties = "aws_access_key_id=defaultAccessKey\n" + "aws_secret_access_key=defaultSecretAccessKey";
String childProperties = "source_profile=source\n" + "role_arn=arn:aws:iam::123456789012:role/testRole";
String configSource = "[profile source]\n" + sourceProperties;
String credentialsSource = "[source]\n" + sourceProperties;
String configChild = "[profile child]\n" + childProperties;
String credentialsChild = "[child]\n" + childProperties;
ProfileFile sourceProfile = aggregateFileProfiles(configSource, credentialsChild);
ProfileFile configProfile = aggregateFileProfiles(configChild, credentialsSource);
Consumer<ProfileFile> profileValidator = profileFile -> assertThatThrownBy(new ProfileCredentialsUtils(profileFile, profileFile.profiles().get("child"), profileFile::profile)::credentialsProvider).hasMessageContaining("the 'sts' service module must be on the class path");
assertThat(sourceProfile).satisfies(profileValidator);
assertThat(configProfile).satisfies(profileValidator);
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsUtils method roleAndSourceProfileBasedProfileCredentialsProvider.
/**
* Load an assumed-role credentials provider that has been configured in this profile. This will attempt to locate the STS
* module in order to generate the credentials provider. If it's not available, an illegal state exception will be raised.
*
* @param children The child profiles that source credentials from this profile.
*/
private AwsCredentialsProvider roleAndSourceProfileBasedProfileCredentialsProvider(Set<String> children) {
requireProperties(ProfileProperty.SOURCE_PROFILE);
Validate.validState(!children.contains(name), "Invalid profile file: Circular relationship detected with profiles %s.", children);
Validate.validState(credentialsSourceResolver != null, "The profile '%s' must be configured with a source profile in order to use assumed roles.", name);
children.add(name);
AwsCredentialsProvider sourceCredentialsProvider = credentialsSourceResolver.apply(properties.get(ProfileProperty.SOURCE_PROFILE)).flatMap(p -> new ProfileCredentialsUtils(profileFile, p, credentialsSourceResolver).credentialsProvider(children)).orElseThrow(this::noSourceCredentialsException);
return stsCredentialsProviderFactory().create(sourceCredentialsProvider, profile);
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsProviderTest method profileWithWebIdentityToken.
@Test
public void profileWithWebIdentityToken() {
String token = "/User/home/test";
ProfileFile file = profileFile("[default]\n" + "aws_access_key_id = defaultAccessKey\n" + "aws_secret_access_key = defaultSecretAccessKey\n" + "web_identity_token_file = " + token);
assertThat(file.profile("default").get().property(ProfileProperty.WEB_IDENTITY_TOKEN_FILE).get()).isEqualTo(token);
}
Aggregations