Skip to content

Commit

Permalink
Renamed new build method and some clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro committed Nov 15, 2018
1 parent 4eaa63a commit f17da2a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/uk/co/lucasweb/aws/v4/signer/Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Signer {
private static final Charset UTF_8 = Throwables.returnableInstance(() -> Charset.forName("UTF-8"), SigningException::new);
private static final String X_AMZ_DATE = "X-Amz-Date";
private static final String HMAC_SHA256 = "HmacSHA256";
private static final String UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";

private final CanonicalRequest request;
private final AwsCredentials awsCredentials;
Expand Down Expand Up @@ -150,6 +151,10 @@ public Signer build(HttpRequest request, String service, String contentSha256) {
CanonicalHeaders canonicalHeaders = getCanonicalHeaders();
String date = canonicalHeaders.getFirstValue(X_AMZ_DATE)
.orElseThrow(() -> new SigningException("headers missing '" + X_AMZ_DATE + "' header"));
return build(request, service, canonicalHeaders, date, contentSha256);
}

private Signer build(HttpRequest request, String service, CanonicalHeaders canonicalHeaders, String date, String contentSha256) {
String dateWithoutTimestamp = formatDateWithoutTimestamp(date);
AwsCredentials awsCredentials = getAwsCredentials();
CanonicalRequest canonicalRequest = new CanonicalRequest(service, request, canonicalHeaders, contentSha256);
Expand All @@ -161,6 +166,10 @@ public Signer buildS3(HttpRequest request, String contentSha256) {
return build(request, S3, contentSha256);
}

public Signer buildS3PresignedUrl(HttpRequest request, String date) {
return build(request, S3, getCanonicalHeaders(), date, UNSIGNED_PAYLOAD);
}

public Signer buildGlacier(HttpRequest request, String contentSha256) {
return build(request, GLACIER, contentSha256);
}
Expand Down

0 comments on commit f17da2a

Please sign in to comment.