Skip to content

Commit 587e080

Browse files
committed
Remove sdk-core dependency from profiles module.
1 parent 38824d7 commit 587e080

File tree

9 files changed

+97
-51
lines changed

9 files changed

+97
-51
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"type": "feature",
4+
"description": "Removed sdk-core dependency from the profiles module. This allows reading from profile files without pulling in the rest of the SDK."
5+
}

core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import software.amazon.awssdk.core.SdkSystemSetting;
2525
import software.amazon.awssdk.core.exception.SdkClientException;
2626
import software.amazon.awssdk.profiles.ProfileFile;
27+
import software.amazon.awssdk.profiles.ProfileFileSystemSetting;
2728
import software.amazon.awssdk.utils.IoUtils;
2829
import software.amazon.awssdk.utils.SdkAutoCloseable;
2930
import software.amazon.awssdk.utils.ToString;
@@ -52,7 +53,7 @@ public final class ProfileCredentialsProvider implements AwsCredentialsProvider,
5253
*/
5354
private ProfileCredentialsProvider(BuilderImpl builder) {
5455
this.profileName = builder.profileName != null ? builder.profileName
55-
: SdkSystemSetting.AWS_PROFILE.getStringValueOrThrow();
56+
: ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
5657

5758
// Load the profiles file
5859
this.profileFile = Optional.ofNullable(builder.profileFile)

core/profiles/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
<artifactId>annotations</artifactId>
4444
<version>${awsjavasdk.version}</version>
4545
</dependency>
46-
<dependency>
47-
<groupId>software.amazon.awssdk</groupId>
48-
<artifactId>sdk-core</artifactId>
49-
<version>${awsjavasdk.version}</version>
50-
</dependency>
5146
<dependency>
5247
<groupId>software.amazon.awssdk</groupId>
5348
<artifactId>test-utils</artifactId>

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFile.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Objects;
2929
import java.util.Optional;
3030
import software.amazon.awssdk.annotations.SdkPublicApi;
31-
import software.amazon.awssdk.core.SdkSystemSetting;
3231
import software.amazon.awssdk.profiles.internal.ProfileFileReader;
3332
import software.amazon.awssdk.utils.FunctionalUtils;
3433
import software.amazon.awssdk.utils.IoUtils;
@@ -80,8 +79,8 @@ public static Aggregator aggregator() {
8079
/**
8180
* Get the default profile file, using the credentials file from "~/.aws/credentials", the config file from "~/.aws/config"
8281
* and the "default" profile. This default behavior can be customized using the
83-
* {@link SdkSystemSetting#AWS_SHARED_CREDENTIALS_FILE}, {@link SdkSystemSetting#AWS_CONFIG_FILE} and
84-
* {@link SdkSystemSetting#AWS_PROFILE} settings or by specifying a different profile file and profile name
82+
* {@link ProfileFileSystemSetting#AWS_SHARED_CREDENTIALS_FILE}, {@link ProfileFileSystemSetting#AWS_CONFIG_FILE} and
83+
* {@link ProfileFileSystemSetting#AWS_PROFILE} settings or by specifying a different profile file and profile name
8584
*/
8685
public static ProfileFile defaultProfileFile() {
8786
return ProfileFile.aggregator()

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFileLocation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.regex.Pattern;
2424
import software.amazon.awssdk.annotations.SdkInternalApi;
2525
import software.amazon.awssdk.annotations.SdkPublicApi;
26-
import software.amazon.awssdk.core.SdkSystemSetting;
2726
import software.amazon.awssdk.utils.JavaSystemSetting;
2827
import software.amazon.awssdk.utils.StringUtils;
2928

@@ -44,9 +43,9 @@ private ProfileFileLocation() {
4443
*/
4544
public static Optional<Path> configurationFileLocation() {
4645
return resolveProfileFilePath(
47-
SdkSystemSetting.AWS_CONFIG_FILE.getStringValue()
48-
.orElse(Paths.get(ProfileFileLocation.userHomeDirectory(),
49-
".aws", "config").toString()));
46+
ProfileFileSystemSetting.AWS_CONFIG_FILE.getStringValue()
47+
.orElse(Paths.get(ProfileFileLocation.userHomeDirectory(),
48+
".aws", "config").toString()));
5049
}
5150

5251
/**
@@ -55,9 +54,9 @@ public static Optional<Path> configurationFileLocation() {
5554
*/
5655
public static Optional<Path> credentialsFileLocation() {
5756
return resolveProfileFilePath(
58-
SdkSystemSetting.AWS_SHARED_CREDENTIALS_FILE.getStringValue()
59-
.orElse(Paths.get(userHomeDirectory(),
60-
".aws", "credentials").toString()));
57+
ProfileFileSystemSetting.AWS_SHARED_CREDENTIALS_FILE.getStringValue()
58+
.orElse(Paths.get(userHomeDirectory(),
59+
".aws", "credentials").toString()));
6160
}
6261

6362
/**
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.profiles;
17+
18+
import software.amazon.awssdk.annotations.SdkProtectedApi;
19+
import software.amazon.awssdk.utils.SystemSetting;
20+
21+
/**
22+
* System settings for loading configuration from profile files.
23+
*/
24+
@SdkProtectedApi
25+
public enum ProfileFileSystemSetting implements SystemSetting {
26+
/**
27+
* Configure the default configuration file used in the ProfileFile. When not explicitly
28+
* overridden in a client (eg. by specifying the region or credentials provider), this will be the location used when an
29+
* AWS client is created.
30+
*
31+
* See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information on configuring the
32+
* SDK via a configuration file.
33+
*/
34+
AWS_CONFIG_FILE("aws.configFile", null),
35+
36+
/**
37+
* Configure the default credentials file used in the ProfileFile. When not explicitly
38+
* overridden in a client (eg. by specifying the region or credentials provider), this will be the location used when an
39+
* AWS client is created.
40+
*
41+
* See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information on configuring the
42+
* SDK via a credentials file.
43+
*/
44+
AWS_SHARED_CREDENTIALS_FILE("aws.sharedCredentialsFile", null),
45+
46+
/**
47+
* Configure the default profile that should be loaded from the {@link #AWS_CONFIG_FILE}
48+
*
49+
* @see #AWS_CONFIG_FILE
50+
*/
51+
AWS_PROFILE("aws.profile", "default");
52+
53+
private final String systemProperty;
54+
private final String defaultValue;
55+
56+
ProfileFileSystemSetting(String systemProperty, String defaultValue) {
57+
this.systemProperty = systemProperty;
58+
this.defaultValue = defaultValue;
59+
}
60+
61+
@Override
62+
public String property() {
63+
return systemProperty;
64+
}
65+
66+
@Override
67+
public String environmentVariable() {
68+
return name();
69+
}
70+
71+
@Override
72+
public String defaultValue() {
73+
return defaultValue;
74+
}
75+
}

core/regions/src/main/java/software/amazon/awssdk/regions/providers/AwsProfileRegionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package software.amazon.awssdk.regions.providers;
1717

1818
import software.amazon.awssdk.annotations.SdkProtectedApi;
19-
import software.amazon.awssdk.core.SdkSystemSetting;
2019
import software.amazon.awssdk.core.exception.SdkClientException;
2120
import software.amazon.awssdk.profiles.ProfileFile;
21+
import software.amazon.awssdk.profiles.ProfileFileSystemSetting;
2222
import software.amazon.awssdk.profiles.ProfileProperty;
2323
import software.amazon.awssdk.regions.Region;
2424

@@ -28,7 +28,7 @@
2828
@SdkProtectedApi
2929
public final class AwsProfileRegionProvider implements AwsRegionProvider {
3030

31-
private final String profileName = SdkSystemSetting.AWS_PROFILE.getStringValueOrThrow();
31+
private final String profileName = ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
3232

3333
@Override
3434
public Region getRegion() {

core/regions/src/test/java/software/amazon/awssdk/regions/providers/AwsProfileRegionProviderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import java.nio.file.Paths;
2323
import org.junit.Rule;
2424
import org.junit.Test;
25-
import software.amazon.awssdk.core.SdkSystemSetting;
2625
import software.amazon.awssdk.core.exception.SdkClientException;
26+
import software.amazon.awssdk.profiles.ProfileFileSystemSetting;
2727
import software.amazon.awssdk.regions.Region;
2828
import software.amazon.awssdk.testutils.EnvironmentVariableHelper;
2929

@@ -34,8 +34,8 @@ public class AwsProfileRegionProviderTest {
3434

3535
@Test
3636
public void nonExistentDefaultConfigFile_ThrowsException() {
37-
settingsHelper.set(SdkSystemSetting.AWS_CONFIG_FILE, "/var/tmp/this/is/invalid.txt");
38-
settingsHelper.set(SdkSystemSetting.AWS_SHARED_CREDENTIALS_FILE, "/var/tmp/this/is/also.invalid.txt");
37+
settingsHelper.set(ProfileFileSystemSetting.AWS_CONFIG_FILE, "/var/tmp/this/is/invalid.txt");
38+
settingsHelper.set(ProfileFileSystemSetting.AWS_SHARED_CREDENTIALS_FILE, "/var/tmp/this/is/also.invalid.txt");
3939
assertThatThrownBy(() -> new AwsProfileRegionProvider().getRegion())
4040
.isInstanceOf(SdkClientException.class)
4141
.hasMessageContaining("No region provided in profile: default");
@@ -45,8 +45,8 @@ public void nonExistentDefaultConfigFile_ThrowsException() {
4545
public void profilePresentAndRegionIsSet_ProvidesCorrectRegion() throws URISyntaxException {
4646
String testFile = "/profileconfig/test-profiles.tst";
4747

48-
settingsHelper.set(SdkSystemSetting.AWS_PROFILE, "test");
49-
settingsHelper.set(SdkSystemSetting.AWS_CONFIG_FILE, Paths.get(getClass().getResource(testFile).toURI()).toString());
48+
settingsHelper.set(ProfileFileSystemSetting.AWS_PROFILE, "test");
49+
settingsHelper.set(ProfileFileSystemSetting.AWS_CONFIG_FILE, Paths.get(getClass().getResource(testFile).toURI()).toString());
5050
assertThat(new AwsProfileRegionProvider().getRegion()).isEqualTo(Region.of("saa"));
5151
}
5252
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/SdkSystemSetting.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@
2323
*/
2424
@SdkProtectedApi
2525
public enum SdkSystemSetting implements SystemSetting {
26-
27-
/**
28-
* Configure the default configuration file used in the ProfileFile. When not explicitly
29-
* overridden in a client (eg. by specifying the region or credentials provider), this will be the location used when an
30-
* AWS client is created.
31-
*
32-
* See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information on configuring the
33-
* SDK via a configuration file.
34-
*/
35-
AWS_CONFIG_FILE("aws.configFile", null),
36-
37-
/**
38-
* Configure the default profile that should be loaded from the {@link #AWS_CONFIG_FILE}
39-
*
40-
* @see #AWS_CONFIG_FILE
41-
*/
42-
AWS_PROFILE("aws.profile", "default"),
43-
44-
/**
45-
* Configure the default credentials file used in the ProfileFile. When not explicitly
46-
* overridden in a client (eg. by specifying the region or credentials provider), this will be the location used when an
47-
* AWS client is created.
48-
*
49-
* See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html for more information on configuring the
50-
* SDK via a credentials file.
51-
*/
52-
AWS_SHARED_CREDENTIALS_FILE("aws.sharedCredentialsFile", null),
53-
5426
/**
5527
* Configure the AWS access key ID.
5628
*

0 commit comments

Comments
 (0)