Search in sources :

Example 21 with ProfileFile

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);
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 22 with ProfileFile

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);
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 23 with ProfileFile

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));
}
Also used : ArrayList(java.util.ArrayList) ProfileFile(software.amazon.awssdk.profiles.ProfileFile)

Example 24 with ProfileFile

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) AWS_CONFIG_FILE(software.amazon.awssdk.profiles.ProfileFileSystemSetting.AWS_CONFIG_FILE) S3Client(software.amazon.awssdk.services.s3.S3Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdkException(software.amazon.awssdk.core.exception.SdkException) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) Test(org.junit.jupiter.api.Test) Context(software.amazon.awssdk.core.interceptor.Context) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Optional(java.util.Optional) AnonymousCredentialsProvider(software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider) Region(software.amazon.awssdk.regions.Region) TRUE(java.lang.Boolean.TRUE) Context(software.amazon.awssdk.core.interceptor.Context) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) S3Client(software.amazon.awssdk.services.s3.S3Client) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 25 with ProfileFile

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");
            });
        });
    });
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test) ProcessCredentialsProviderTest(software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)

Aggregations

ProfileFile (software.amazon.awssdk.profiles.ProfileFile)47 Test (org.junit.jupiter.api.Test)22 StringInputStream (software.amazon.awssdk.utils.StringInputStream)20 Test (org.junit.Test)14 ProcessCredentialsProviderTest (software.amazon.awssdk.auth.credentials.ProcessCredentialsProviderTest)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 ProfileCredentialsUtils (software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils)9 Region (software.amazon.awssdk.regions.Region)9 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8 URI (java.net.URI)7 Optional (java.util.Optional)6 Arrays (java.util.Arrays)5 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)5 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)5 ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)5 Profile (software.amazon.awssdk.profiles.Profile)5 SdkAutoCloseable (software.amazon.awssdk.utils.SdkAutoCloseable)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)4