use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsProviderTest method missingProfileThrowsExceptionInGetCredentials.
@Test
public void missingProfileThrowsExceptionInGetCredentials() {
ProfileFile file = profileFile("[default]\n" + "aws_access_key_id = defaultAccessKey\n" + "aws_secret_access_key = defaultSecretAccessKey");
ProfileCredentialsProvider provider = ProfileCredentialsProvider.builder().profileFile(file).profileName("foo").build();
assertThatThrownBy(provider::resolveCredentials).isInstanceOf(SdkClientException.class);
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsProviderTest method profileWithoutCredentialsThrowsExceptionInGetCredentials.
@Test
public void profileWithoutCredentialsThrowsExceptionInGetCredentials() {
ProfileFile file = profileFile("[default]");
ProfileCredentialsProvider provider = ProfileCredentialsProvider.builder().profileFile(file).profileName("default").build();
assertThatThrownBy(provider::resolveCredentials).isInstanceOf(SdkClientException.class);
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class SdkDefaultClientBuilder method mergeGlobalDefaults.
/**
* Apply global default configuration
*/
private SdkClientConfiguration mergeGlobalDefaults(SdkClientConfiguration configuration) {
// Don't load the default profile file if the customer already gave us one.
ProfileFile configuredProfileFile = configuration.option(PROFILE_FILE);
ProfileFile profileFile = configuredProfileFile != null ? configuredProfileFile : ProfileFile.defaultProfileFile();
return configuration.merge(c -> c.option(EXECUTION_INTERCEPTORS, new ArrayList<>()).option(ADDITIONAL_HTTP_HEADERS, new LinkedHashMap<>()).option(PROFILE_FILE, profileFile).option(PROFILE_NAME, ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow()).option(USER_AGENT_PREFIX, SdkUserAgent.create().userAgent()).option(USER_AGENT_SUFFIX, "").option(CRC32_FROM_COMPRESSED_DATA_ENABLED, false));
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileDisableMultiRegionProviderTest method specifiedInOverrideConfig_shouldUse.
@Test
public void specifiedInOverrideConfig_shouldUse() {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "s3_disable_multiregion_access_points = true\n";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
S3Client s3 = S3Client.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).serviceConfiguration(s -> s.useArnRegionEnabled(true)).build();
String arn = "arn:aws:s3:us-banana-46:12345567890:accesspoint:foo";
assertThatThrownBy(() -> s3.getObject(r -> r.bucket(arn).key("bar"))).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor).beforeTransmission(context.capture(), any());
String host = context.getValue().httpRequest().host();
assertThat(host).contains("us-banana-46");
}
use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.
the class ProfileCredentialsUtilsTest method profileFileWithProcessCredentialsLoadsCorrectly.
@Test
public void profileFileWithProcessCredentialsLoadsCorrectly() {
ProfileFile profileFile = allTypesProfile();
assertThat(profileFile.profile("profile-credential-process")).hasValueSatisfying(profile -> {
assertThat(profile.property(ProfileProperty.REGION)).isNotPresent();
assertThat(new ProfileCredentialsUtils(profileFile, profile, profileFile::profile).credentialsProvider()).hasValueSatisfying(credentialsProvider -> {
assertThat(credentialsProvider.resolveCredentials()).satisfies(credentials -> {
assertThat(credentials).isInstanceOf(AwsBasicCredentials.class);
assertThat(credentials.accessKeyId()).isEqualTo("defaultAccessKey");
assertThat(credentials.secretAccessKey()).isEqualTo("defaultSecretAccessKey");
});
});
});
}
Aggregations