Skip to content

Commit ff647a7

Browse files
committed
[aws] Cleanup
1 parent fe1efcb commit ff647a7

36 files changed

+520
-1251
lines changed

biz.aQute.api/s3.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aws.s3.api

biz.aQute.api/ses.bnd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-includepackage: biz.aQute.aws.ses.api

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/s3/Bucket.java biz.aQute.api/src/main/java/biz/aQute/aws/s3/api/Bucket.java

+18-42
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,13 @@
1-
package biz.aQute.aws.s3;
1+
package biz.aQute.aws.s3.api;
22

3-
import java.io.*;
4-
import java.net.*;
5-
import java.util.*;
3+
import java.io.InputStream;
4+
import java.net.URI;
5+
import java.util.Collection;
6+
import java.util.Date;
67

7-
import biz.aQute.aws.s3.S3.*;
8-
9-
public class Bucket {
10-
final String name;
11-
final S3 parent;
12-
13-
// TODO verify bucket name
14-
15-
Bucket(S3 parent, String name) {
16-
this.parent = parent;
17-
this.name = name;
18-
}
19-
20-
public String getName() {
21-
return name;
22-
}
23-
24-
public GetRequest getObject(String key) {
25-
return new GetRequestImpl(parent, this, key);
26-
}
27-
28-
public void delete(String key) throws Exception {
29-
parent.construct(S3.METHOD.DELETE, this, key, null, null, null);
30-
}
31-
32-
public PutRequest putObject(String key) {
33-
return new PutRequestImpl(parent, this, key);
34-
}
35-
36-
public ListRequest listObjects() throws Exception {
37-
return new ListRequestImpl(parent, this);
38-
}
39-
40-
public String toString() {
41-
return name;
42-
}
8+
public interface Bucket {
439

10+
String getName();
4411
public static class Content {
4512
public Bucket bucket;
4613
public String key;
@@ -106,15 +73,15 @@ public interface PutRequest extends CommonRequest<PutRequest> {
10673

10774
PutRequest expires(long ms);
10875

109-
PutRequest storageClass(S3.StorageClass storageClass);
76+
PutRequest storageClass(StorageClass storageClass);
11077

11178
PutRequest contentLength(long length);
11279

11380
void put(InputStream in) throws Exception;
11481

11582
/**
11683
* Put a string as UTF-8 encoded data.
117-
*
84+
*
11885
* @param in
11986
* The string to put
12087
* @throws Exception
@@ -134,4 +101,13 @@ public interface ListRequest extends CommonRequest<ListRequest>, Iterable<Conten
134101
ListRequest prefix(String prefix);
135102
}
136103

104+
PutRequest putObject(String key);
105+
106+
GetRequest getObject(String key);
107+
108+
void delete(String key) throws Exception;
109+
110+
ListRequest listObjects() throws Exception;
111+
112+
137113
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package biz.aQute.aws.s3.api;
2+
3+
import java.util.List;
4+
5+
public interface S3 {
6+
7+
Bucket createBucket(String bucket, String ...region) throws Exception;
8+
9+
void deleteBucket(String bucket) throws Exception;
10+
11+
Bucket getBucket(String name) throws Exception;
12+
13+
List<Bucket> listBuckets() throws Exception;
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package biz.aQute.aws.s3.api;
2+
public enum StorageClass {
3+
STANDARD, REDUCED_REDUNDANCY
4+
}
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@org.osgi.annotation.bundle.Export
2+
@Version("1.0.0")
3+
package biz.aQute.aws.s3.api;
4+
5+
import org.osgi.annotation.versioning.Version;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package biz.aQute.aws.ses.api;
2+
3+
public interface SES {
4+
5+
SESRequest subject(String subject) throws Exception;
6+
7+
8+
interface SESRequest {
9+
10+
SESRequest html(String html);
11+
12+
SESRequest text(String text);
13+
14+
SESRequest to(String address);
15+
16+
17+
SESRequest from(String address);
18+
19+
SESRequest bcc(String address);
20+
21+
SESRequest replyTo(String address);
22+
23+
SESRequest cc(String address);
24+
25+
SESRequest returnPath(String address);
26+
27+
String send() throws Exception;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@org.osgi.annotation.bundle.Export
2+
@Version("1.0.0")
3+
package biz.aQute.aws.ses.api;
4+
5+
import org.osgi.annotation.versioning.Version;

biz.aQute.aws.provider/bnd.bnd

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77
org.osgi.service.component.annotations,\
88
aQute.libg,\
99
org.osgi.service.log,\
10-
slf4j.api
11-
10+
slf4j.api,\
11+
org.osgi.service.metatype.annotations,\
12+
org.apache.felix.gogo.runtime,\
13+
biz.aQute.api.ses, \
14+
biz.aQute.api.s3
1215

1316
-testpath: \
1417
biz.aQute.wrapper.junit, \
1518
biz.aQute.wrapper.hamcrest, \
1619
org.assertj.core
1720

21+
Export-Package : \
22+
biz.aQute.aws.ses.api, \
23+
biz.aQute.aws.s3.api
24+
25+
26+
-conditionalpackage: \
27+
aQute.lib*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package biz.aQute.aws.config;
2+
3+
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
4+
5+
@ObjectClassDefinition
6+
public @interface S3Config {
7+
String region() default "https://email.us-east-1.amazonaws.com/";
8+
9+
String id();
10+
11+
String _secret();
12+
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package biz.aQute.aws.config;
2+
3+
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
4+
5+
@ObjectClassDefinition
6+
public @interface SESConfig {
7+
String region() default "https://email.us-east-1.amazonaws.com/";
8+
9+
String from();
10+
11+
String id();
12+
13+
String _secret();
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@Export
2+
@org.osgi.annotation.versioning.Version("1.0.0")
3+
package biz.aQute.aws.config;
4+
5+
import org.osgi.annotation.bundle.Export;

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/credentials/UserCredentials.java

+4
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ private synchronized Properties getProperties(){
4242
}
4343
return properties;
4444
}
45+
46+
public String getProperty(String key, String deflt) {
47+
return getProperties().getProperty(key,deflt);
48+
}
4549
}

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/AWSException.java biz.aQute.aws.provider/src/main/java/biz/aQute/aws/impl/AWSException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package biz.aQute.aws;
1+
package biz.aQute.aws.impl;
22

33
public class AWSException extends RuntimeException {
44
private static final long serialVersionUID = 1L;

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/AWS.java biz.aQute.aws.provider/src/main/java/biz/aQute/aws/impl/AWSImpl.java

+44-38
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
package biz.aQute.aws;
2-
3-
import java.io.*;
4-
import java.net.*;
5-
import java.security.*;
6-
import java.text.*;
7-
import java.util.*;
8-
9-
import javax.crypto.*;
10-
import javax.crypto.spec.*;
11-
import javax.xml.parsers.*;
1+
package biz.aQute.aws.impl;
2+
3+
import java.io.IOException;
4+
import java.io.UnsupportedEncodingException;
5+
import java.net.HttpURLConnection;
6+
import java.net.MalformedURLException;
7+
import java.net.URL;
8+
import java.net.URLEncoder;
9+
import java.security.NoSuchAlgorithmException;
10+
import java.text.ParseException;
11+
import java.text.SimpleDateFormat;
12+
import java.util.Date;
13+
import java.util.Locale;
14+
import java.util.Map;
15+
16+
import javax.crypto.Mac;
17+
import javax.crypto.spec.SecretKeySpec;
18+
import javax.xml.parsers.DocumentBuilder;
19+
import javax.xml.parsers.DocumentBuilderFactory;
20+
import javax.xml.parsers.ParserConfigurationException;
1221

1322
import aQute.lib.base64.Base64;
14-
import biz.aQute.aws.s3.*;
15-
import biz.aQute.aws.ses.*;
16-
import biz.aQute.aws.sqs.*;
23+
import biz.aQute.aws.s3.S3Impl;
24+
import biz.aQute.aws.sqs.SQSImpl;
1725

1826
/**
1927
* https://email.us-east-1.amazonaws.com/ ?Action=SendEmail
@@ -33,20 +41,25 @@
3341
* &AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE
3442
* &Signature=RhU864jFu893mg7g9N9j9nr6h7EXAMPLE &Algorithm=HMACSHA256
3543
*/
36-
public class AWS {
44+
45+
public class AWSImpl {
3746
final private String accessKey;
3847
final private String secretKey;
3948
final private Mac mac;
4049
final private SecretKeySpec secret;
41-
final private static SimpleDateFormat awsDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
42-
static SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
50+
final private static SimpleDateFormat awsDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",
51+
Locale.ENGLISH);
52+
static SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z",
53+
Locale.ENGLISH);
4354
final private static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
55+
final String region;
4456
static {
4557
dbf.setNamespaceAware(false);
4658
}
4759

48-
public AWS(String accessKey, String secretKey) throws NoSuchAlgorithmException {
60+
public AWSImpl(String accessKey, String secretKey, String region) throws NoSuchAlgorithmException {
4961
this.accessKey = accessKey;
62+
this.region = region;
5063
this.mac = Mac.getInstance("HmacSHA256");
5164
this.secret = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
5265
this.secretKey = secretKey;
@@ -67,12 +80,12 @@ public HttpURLConnection sign() throws Exception {
6780
synchronized (secret) {
6881

6982
switch (protocol.signature) {
70-
case 2 :
71-
return signVersion2(protocol);
72-
case 3 :
73-
return signVersion3();
74-
default :
75-
throw new IllegalArgumentException("Invalid signature version");
83+
case 2:
84+
return signVersion2(protocol);
85+
case 3:
86+
return signVersion3();
87+
default:
88+
throw new IllegalArgumentException("Invalid signature version");
7689
}
7790
}
7891
}
@@ -122,7 +135,7 @@ private StringBuilder buildRequest() {
122135
StringBuilder sb = new StringBuilder();
123136
String del = "";
124137

125-
for (Map.Entry<String,Object> parameter : arguments.entrySet()) {
138+
for (Map.Entry<String, Object> parameter : arguments.entrySet()) {
126139
Object value = parameter.getValue();
127140
if (value != null) {
128141
sb.append(del) //
@@ -147,32 +160,25 @@ private String encodeUrl(String value) {
147160
try {
148161
// TODO Not very efficient now
149162
return URLEncoder.encode(value, "utf-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
150-
}
151-
catch (final UnsupportedEncodingException ex) {
163+
} catch (final UnsupportedEncodingException ex) {
152164
throw new RuntimeException(ex);
153165
}
154166
}
155167

156168
private byte[] hmacSha256(final String str) {
157169
try {
158170
mac.init(secret);
159-
}
160-
catch (final Exception e) {
171+
} catch (final Exception e) {
161172
throw new RuntimeException(e);
162173
}
163174
return mac.doFinal(str.getBytes());
164175
}
165176

166-
public S3 s3() {
167-
return new S3(accessKey, secretKey);
168-
}
169-
170-
public SES ses() {
171-
return new SES(new Protocol(this, "https://email.us-east-1.amazonaws.com/", null, 3));
177+
public S3Impl s3() {
178+
return new S3Impl(accessKey, secretKey);
172179
}
173-
174-
public SQS sqs(String region) {
175-
return new SQS(new Protocol(this, region, SQS.version, 2));
180+
public SQSImpl sqs() {
181+
return new SQSImpl(new Protocol(this, region, SQSImpl.version, 2));
176182
}
177183

178184
}

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/Protocol.java biz.aQute.aws.provider/src/main/java/biz/aQute/aws/impl/Protocol.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package biz.aQute.aws;
1+
package biz.aQute.aws.impl;
22

33
public class Protocol {
44
final int signature;
5-
final AWS aws;
5+
final AWSImpl aws;
66
final String endpoint;
77
final String version;
88

9-
Protocol(AWS aws, String endpoint, String version, int signature) {
9+
public Protocol(AWSImpl aws, String endpoint, String version, int signature) {
1010
this.aws = aws;
1111
this.endpoint = endpoint;
1212
this.version = version;

biz.aQute.aws.provider/src/main/java/biz/aQute/aws/Request.java biz.aQute.aws.provider/src/main/java/biz/aQute/aws/impl/Request.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package biz.aQute.aws;
1+
package biz.aQute.aws.impl;
22

33
import java.io.*;
44
import java.net.*;

0 commit comments

Comments
 (0)