Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ProfileFile to support reading sub-properties. #5560

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import software.amazon.awssdk.profiles.internal.ProfileFileReader;
import software.amazon.awssdk.utils.FunctionalUtils;
import software.amazon.awssdk.utils.IoUtils;
import software.amazon.awssdk.utils.StringInputStream;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.Validate;
import software.amazon.awssdk.utils.builder.SdkBuilder;
Expand Down Expand Up @@ -233,6 +234,14 @@ public enum Type {
* required fields.
*/
public interface Builder extends SdkBuilder<Builder, ProfileFile> {
/**
* Configure the content of the profile file. This stream will be read from and then closed when {@link #build()} is
* invoked.
*/
default Builder content(String content) {
return content(new StringInputStream(content));
}

/**
* Configure the content of the profile file. This stream will be read from and then closed when {@link #build()} is
* invoked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public final class ProfileProperty {
*/
public static final String REQUEST_MIN_COMPRESSION_SIZE_BYTES = "request_min_compression_size_bytes";

/**
* The endpoint override to use. This may also be specified under a service-specific parent property to override the
* endpoint just for that one service.
*/
public static final String ENDPOINT_URL = "endpoint_url";

private ProfileProperty() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ private static void readPropertyContinuationLine(ParserState state, String line)

// If this is a sub-property, make sure it can be parsed correctly by the CLI.
if (state.validatingContinuationsAsSubProperties) {
parsePropertyDefinition(state, line);
parsePropertyDefinition(state, line).ifPresent(p -> {
String subPropertyDefinition = state.currentPropertyBeingRead + "." + p.left();
profileProperties.put(subPropertyDefinition, p.right());
});
}

profileProperties.put(state.currentPropertyBeingRead, newPropertyValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ public void propertiesCanHaveSubProperties() {
assertThat(configFileProfiles("[profile foo]\n" +
"s3 =\n" +
" name = value"))
.isEqualTo(profiles(profile("foo", property("s3", "\nname = value"))));
.isEqualTo(profiles(profile("foo",
property("s3", "\nname = value"),
property("s3.name", "value"))));
}

@Test
Expand All @@ -359,7 +361,9 @@ public void subPropertiesCanHaveEmptyValues() {
assertThat(configFileProfiles("[profile foo]\n" +
"s3 =\n" +
" name ="))
.isEqualTo(profiles(profile("foo", property("s3", "\nname ="))));
.isEqualTo(profiles(profile("foo",
property("s3", "\nname ="),
property("s3.name", ""))));
}

@Test
Expand All @@ -385,7 +389,10 @@ public void subPropertiesCanHaveBlankLines() {
" name = value\n" +
"\t \n" +
" name2 = value2"))
.isEqualTo(profiles(profile("foo", property("s3", "\nname = value\nname2 = value2"))));
.isEqualTo(profiles(profile("foo",
property("s3", "\nname = value\nname2 = value2"),
property("s3.name", "value"),
property("s3.name2", "value2"))));
}

@Test
Expand Down Expand Up @@ -565,7 +572,7 @@ public void returnsEmptyMap_when_AwsFilesDoNotExist() {

private ProfileFile configFile(String configFile) {
return ProfileFile.builder()
.content(new StringInputStream(configFile))
.content(configFile)
.type(ProfileFile.Type.CONFIGURATION)
.build();
}
Expand All @@ -576,7 +583,7 @@ private Map<String, Profile> configFileProfiles(String configFile) {

private ProfileFile credentialFile(String credentialFile) {
return ProfileFile.builder()
.content(new StringInputStream(credentialFile))
.content(credentialFile)
.type(ProfileFile.Type.CREDENTIALS)
.build();
}
Expand Down
Loading