Fix call to S3
This commit is contained in:
parent
e14353a565
commit
ba679d80e2
2 changed files with 10 additions and 9 deletions
|
|
@ -8,18 +8,16 @@ import javax.crypto.spec.SecretKeySpec;
|
|||
import java.net.URI;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @author Maksim Tereshin
|
||||
*/
|
||||
public class S3HttpConnection {
|
||||
|
||||
public static HttpRequest buildHttpRequest(S3Request request, String file) throws Exception {
|
||||
S3ConnectionParams connectionParams = request.getS3ConnectionParams();
|
||||
String host = connectionParams.getHost() + ":" + connectionParams.getPort();
|
||||
String host = connectionParams.getProtocol() + "://" + connectionParams.getHost() + ":" + connectionParams.getPort();
|
||||
String s3Key = connectionParams.getS3Key();
|
||||
String s3Secret = connectionParams.getS3Secret();
|
||||
String method = connectionParams.getMethod().toUpperCase();
|
||||
|
|
@ -27,12 +25,12 @@ public class S3HttpConnection {
|
|||
|
||||
String resource = "/" + file;
|
||||
String contentType = connectionParams.getContentType();
|
||||
String date = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME);
|
||||
String date = ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
|
||||
|
||||
String signature = generateSignature(method, contentType, date, resource, s3Secret);
|
||||
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||
.uri(URI.create("http://" + host + resource))
|
||||
.uri(URI.create(host + resource))
|
||||
.header("Date", date)
|
||||
.header("Content-Type", contentType)
|
||||
.header("Authorization", "AWS " + s3Key + ":" + signature);
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ package org.micord.models.requests;
|
|||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author Maksim Tereshin
|
||||
*/
|
||||
@Setter
|
||||
public class S3ConnectionParams {
|
||||
|
||||
private String s3Key;
|
||||
private String s3Secret;
|
||||
private String protocol;
|
||||
private String host;
|
||||
private String port;
|
||||
private String contentType;
|
||||
|
|
@ -27,6 +25,11 @@ public class S3ConnectionParams {
|
|||
return s3Secret;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Protocol")
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
@XmlElement(name = "Host")
|
||||
public String getHost() {
|
||||
return host;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue