Search in sources :

Example 46 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class SsoProfileTest method createSsoCredentialsProvider_SsoRoleNameMissing_throwException.

@Test
public void createSsoCredentialsProvider_SsoRoleNameMissing_throwException() {
    String profileContent = "[profile foo]\n" + "sso_account_id=012345678901\n" + "sso_region=us-east-1\n" + "sso_start_url=https://d-abc123.awsapps.com/start-beta\n";
    ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
    assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
        assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_role_name' was not configured");
    });
}
Also used : StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileCredentialsUtils(software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 47 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class SsoProfileTest method createSsoCredentialsProvider_SsoAccountIdMissing_throwException.

@Test
public void createSsoCredentialsProvider_SsoAccountIdMissing_throwException() {
    String profileContent = "[profile foo]\n" + "sso_region=us-east-1\n" + "sso_role_name=SampleRole\n" + "sso_start_url=https://d-abc123.awsapps.com/start-beta\n";
    ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
    assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
        assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_account_id' was not configured");
    });
}
Also used : StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileCredentialsUtils(software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 48 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class Ec2MetadataConfigProvider method resolveProfile.

private Optional<Profile> resolveProfile() {
    ProfileFile profileFileToUse = resolveProfileFile();
    String profileNameToUse = resolveProfileName();
    return profileFileToUse.profile(profileNameToUse);
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile)

Example 49 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class ProfileCredentialsProviderTest method presentProfileReturnsCredentials.

@Test
public void presentProfileReturnsCredentials() {
    ProfileFile file = profileFile("[default]\n" + "aws_access_key_id = defaultAccessKey\n" + "aws_secret_access_key = defaultSecretAccessKey");
    ProfileCredentialsProvider provider = ProfileCredentialsProvider.builder().profileFile(file).profileName("default").build();
    assertThat(provider.resolveCredentials()).satisfies(credentials -> {
        assertThat(credentials.accessKeyId()).isEqualTo("defaultAccessKey");
        assertThat(credentials.secretAccessKey()).isEqualTo("defaultSecretAccessKey");
    });
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 50 with ProfileFile

use of software.amazon.awssdk.profiles.ProfileFile in project aws-sdk-java-v2 by aws.

the class S3EndpointResolutionTest method regionalSettingEnabledViaProfile_usesRegionalIadEndpoint.

@Test
public void regionalSettingEnabledViaProfile_usesRegionalIadEndpoint() throws UnsupportedEncodingException {
    String profile = "[profile test]\n" + "s3_us_east_1_regional_endpoint = regional";
    ProfileFile profileFile = ProfileFile.builder().content(new StringInputStream(profile)).type(ProfileFile.Type.CONFIGURATION).build();
    mockHttpClient.stubNextResponse(mockListObjectsResponse());
    S3Client s3Client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))).httpClient(mockHttpClient).region(Region.US_EAST_1).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("test")).serviceConfiguration(c -> c.pathStyleAccessEnabled(true)).build();
    s3Client.listObjects(ListObjectsRequest.builder().bucket(BUCKET).build());
    assertThat(mockHttpClient.getLastRequest().getUri().getHost()).isEqualTo("s3.us-east-1.amazonaws.com");
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) MockSyncHttpClient(software.amazon.awssdk.testutils.service.http.MockSyncHttpClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) SdkSystemSetting(software.amazon.awssdk.core.SdkSystemSetting) DefaultsMode(software.amazon.awssdk.awscore.defaultsmode.DefaultsMode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) URI(java.net.URI) S3MockUtils.mockListObjectsResponse(software.amazon.awssdk.services.s3.S3MockUtils.mockListObjectsResponse) Region(software.amazon.awssdk.regions.Region) Before(org.junit.Before) EndpointAddressInterceptor(software.amazon.awssdk.services.s3.internal.handlers.EndpointAddressInterceptor) ListObjectsRequest(software.amazon.awssdk.services.s3.model.ListObjectsRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Test(org.junit.Test) Consumer(java.util.function.Consumer) EnvironmentVariableHelper(software.amazon.awssdk.testutils.EnvironmentVariableHelper) StringInputStream(software.amazon.awssdk.utils.StringInputStream) S3MockUtils.mockListBucketsResponse(software.amazon.awssdk.services.s3.S3MockUtils.mockListBucketsResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.Test)

Aggregations

ProfileFile (software.amazon.awssdk.profiles.ProfileFile)50 Test (org.junit.jupiter.api.Test)25 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