Skip to content

Commit bd1a7d3

Browse files
committed
Merge pull request #71 from rpmoore/master
Gradle Update and Ds3ClientBuilder from Environment Variables
2 parents 21e593b + 96be595 commit bd1a7d3

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
allprojects {
1717
group = 'com.spectralogic.ds3'
18-
version = '1.1.0-RC3'
18+
version = '1.1.0-RC4'
1919
}
2020

2121
subprojects {
@@ -38,7 +38,7 @@ subprojects {
3838
}
3939

4040
task wrapper(type: Wrapper) {
41-
gradleVersion = '2.3'
41+
gradleVersion = '2.4'
4242
}
4343

4444
project(':ds3-sdk-integration') {

ds3-sdk-integration/src/main/java/com/spectralogic/ds3client/integration/Util.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,17 @@ public class Util {
3939
private Util() {}
4040

4141
public static Ds3Client fromEnv() {
42-
final Ds3ClientBuilder builder = clientBuilder();
42+
final Ds3ClientBuilder builder = Ds3ClientBuilder.fromEnv();
4343
builder.withHttps(false);
4444
return builder.build();
4545
}
4646

4747
public static Ds3Client insecureFromEnv() {
48-
final Ds3ClientBuilder builder = clientBuilder();
48+
final Ds3ClientBuilder builder = Ds3ClientBuilder.fromEnv();
4949
builder.withCertificateVerification(false);
5050
return builder.build();
5151
}
5252

53-
private static Ds3ClientBuilder clientBuilder() {
54-
final String endpoint = System.getenv("DS3_ENDPOINT");
55-
final String accessKey = System.getenv("DS3_ACCESS_KEY");
56-
final String secretKey = System.getenv("DS3_SECRET_KEY");
57-
final String httpProxy = System.getenv("http_proxy");
58-
59-
if (endpoint == null) {
60-
throw new IllegalArgumentException("Missing DS3_ENDPOINT");
61-
}
62-
63-
if (accessKey == null) {
64-
throw new IllegalArgumentException("Missing DS3_ACCESS_KEY");
65-
}
66-
67-
if (secretKey == null) {
68-
throw new IllegalArgumentException("Missing DS3_SECRET_KEY");
69-
}
70-
71-
final Ds3ClientBuilder builder = Ds3ClientBuilder.create(endpoint,new Credentials(accessKey, secretKey));
72-
if (httpProxy != null) {
73-
builder.withProxy(httpProxy);
74-
}
75-
return builder;
76-
}
77-
7853
private static final String[] BOOKS = {"beowulf.txt", "sherlock_holmes.txt", "tale_of_two_cities.txt", "ulysses.txt"};
7954
public static void loadBookTestData(final Ds3Client client, final String bucketName) throws IOException, SignatureException, XmlProcessingException, URISyntaxException {
8055

ds3-sdk/src/main/java/com/spectralogic/ds3client/Ds3ClientBuilder.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public class Ds3ClientBuilder implements Builder<Ds3Client> {
3434

3535
static final private Logger LOG = LoggerFactory.getLogger(Ds3ClientBuilder.class);
3636

37+
static final private String ENDPOINT = "DS3_ENDPOINT";
38+
static final private String ACCESS_KEY = "DS3_ACCESS_KEY";
39+
static final private String SECRET_KEY = "DS3_SECRET_KEY";
40+
3741
final private String endpoint;
3842
final private Credentials credentials;
3943

@@ -64,6 +68,38 @@ public static Ds3ClientBuilder create(final String endpoint, final Credentials c
6468
return new Ds3ClientBuilder(endpoint, creds);
6569
}
6670

71+
/**
72+
* Returns a Build which already has the endpoint and credentials populated from environment variables.
73+
* DS3_ENDPOINT, DS3_ACCESS_KEY, and DS3_SECRET_KEY are all used when creating the builder. This will
74+
* also detect if http_proxy is set, and if it is will us it when creating the client and set the proxy
75+
* variable accordingly.
76+
* @return
77+
* @throws IllegalArgumentException
78+
*/
79+
public static Ds3ClientBuilder fromEnv() throws IllegalArgumentException {
80+
final String endpoint = System.getenv(ENDPOINT);
81+
if (endpoint == null) {
82+
throw new IllegalArgumentException("Missing " + ENDPOINT + " environment variable");
83+
}
84+
final String accessKey = System.getenv(ACCESS_KEY);
85+
if (accessKey == null) {
86+
throw new IllegalArgumentException("Missing " + ACCESS_KEY + " environment variable");
87+
}
88+
final String secretKey = System.getenv(SECRET_KEY);
89+
if (secretKey == null) {
90+
throw new IllegalArgumentException("Missing " + SECRET_KEY + " environment variable");
91+
}
92+
93+
final Ds3ClientBuilder builder = create(endpoint, new Credentials(accessKey, secretKey));
94+
95+
final String httpProxy = System.getenv("http_proxy");
96+
97+
if (httpProxy != null) {
98+
builder.withProxy(httpProxy);
99+
}
100+
return builder;
101+
}
102+
67103
/**
68104
* Specifies if the library should use HTTP or HTTPS. The default is HTTP.
69105
* @param secure True will use HTTPS, false will use HTTP.

gradle/wrapper/gradle-wrapper.jar

1.1 KB
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Mar 26 13:58:18 MDT 2015
1+
#Thu May 07 09:33:39 MDT 2015
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

0 commit comments

Comments
 (0)