mirror of
https://github.com/valitydev/file-storage.git
synced 2024-11-06 00:35:22 +00:00
BJ-314: rm md5
This commit is contained in:
parent
53a0d7625e
commit
844f1aad6b
@ -16,7 +16,6 @@ import com.rbkmoney.file.storage.util.DamselUtil;
|
||||
import com.rbkmoney.geck.common.util.TypeUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
|
||||
@ -42,7 +41,6 @@ public class AmazonS3StorageService implements StorageService {
|
||||
private static final String FILEDATA_FILE_ID = "x-rbkmoney-filedata-file-id";
|
||||
private static final String FILEDATA_FILE_NAME = "x-rbkmoney-filedata-file-name";
|
||||
private static final String FILEDATA_CREATED_AT = "x-rbkmoney-filedata-created-at";
|
||||
private static final String FILEDATA_MD_5 = "x-rbkmoney-filedata-md5";
|
||||
private static final String FILEDATA_METADATA = "x-rbkmoney-filedata-metadata-";
|
||||
|
||||
private final TransferManager transferManager;
|
||||
@ -81,7 +79,6 @@ public class AmazonS3StorageService implements StorageService {
|
||||
fileId,
|
||||
fileName,
|
||||
createdAt,
|
||||
"",
|
||||
metadata
|
||||
);
|
||||
|
||||
@ -126,7 +123,6 @@ public class AmazonS3StorageService implements StorageService {
|
||||
|
||||
ObjectMetadata objectMetadata = object.getObjectMetadata();
|
||||
objectMetadata.addUserMetadata(FILE_UPLOADED, "true");
|
||||
objectMetadata.addUserMetadata(FILEDATA_MD_5, calculateMd5(multipartFile.getBytes()));
|
||||
objectMetadata.setContentLength(multipartFile.getSize());
|
||||
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(
|
||||
@ -220,7 +216,6 @@ public class AmazonS3StorageService implements StorageService {
|
||||
String fileId = getUserMetadataParameter(objectMetadata, FILEDATA_FILE_ID);
|
||||
String fileName = getUserMetadataParameter(objectMetadata, FILEDATA_FILE_NAME);
|
||||
String createdAt = getUserMetadataParameter(objectMetadata, FILEDATA_CREATED_AT);
|
||||
String md5 = getUserMetadataParameter(objectMetadata, FILEDATA_MD_5);
|
||||
|
||||
Map<String, com.rbkmoney.damsel.msgpack.Value> metadata = objectMetadata.getUserMetadata().entrySet().stream()
|
||||
.filter(entry -> entry.getKey().startsWith(FILEDATA_METADATA) && entry.getValue() != null)
|
||||
@ -235,7 +230,7 @@ public class AmazonS3StorageService implements StorageService {
|
||||
fileId,
|
||||
bucketName
|
||||
);
|
||||
return new FileData(fileId, fileName, createdAt, md5, metadata);
|
||||
return new FileData(fileId, fileName, createdAt, metadata);
|
||||
}
|
||||
|
||||
private URL generatePresignedUrl(String fileId, Instant expirationTime, HttpMethod httpMethod) throws StorageException {
|
||||
@ -300,7 +295,6 @@ public class AmazonS3StorageService implements StorageService {
|
||||
objectMetadata.addUserMetadata(FILEDATA_FILE_ID, fileData.getFileId());
|
||||
objectMetadata.addUserMetadata(FILEDATA_FILE_NAME, fileData.getFileName());
|
||||
objectMetadata.addUserMetadata(FILEDATA_CREATED_AT, fileData.getCreatedAt());
|
||||
objectMetadata.addUserMetadata(FILEDATA_MD_5, fileData.getMd5());
|
||||
fileData.getMetadata().forEach(
|
||||
(key, value) -> objectMetadata.addUserMetadata(FILEDATA_METADATA + key, DamselUtil.toJsonString(value))
|
||||
);
|
||||
@ -354,8 +348,4 @@ public class AmazonS3StorageService implements StorageService {
|
||||
throw new StorageFileNotFoundException(String.format(objectType + " is null, fileId='%s', bucketId='%s'", fileId, bucketName));
|
||||
}
|
||||
}
|
||||
|
||||
private String calculateMd5(byte[] data) throws IOException {
|
||||
return DigestUtils.md5Hex(data);
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.rbkmoney.file.storage;
|
||||
|
||||
import com.rbkmoney.woody.thrift.impl.http.THSpawnClientBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
@ -12,15 +11,12 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
@ -46,21 +42,21 @@ public abstract class AbstractIntegrationTest {
|
||||
|
||||
protected FileStorageSrv.Iface client;
|
||||
|
||||
@ClassRule
|
||||
public static GenericContainer cephContainer = new GenericContainer("dr.rbkmoney.com/ceph-demo:latest")
|
||||
.withEnv("RGW_NAME", "localhost")
|
||||
.withEnv("NETWORK_AUTO_DETECT", "4")
|
||||
.withEnv("CEPH_DEMO_UID", "ceph-test")
|
||||
.withEnv("CEPH_DEMO_ACCESS_KEY", AWS_ACCESS_KEY)
|
||||
.withEnv("CEPH_DEMO_SECRET_KEY", AWS_SECRET_KEY)
|
||||
.withEnv("CEPH_DEMO_BUCKET", BUCKET_NAME)
|
||||
.withExposedPorts(5000, 80)
|
||||
.waitingFor(
|
||||
new HttpWaitStrategy()
|
||||
.forPath("/api/v0.1/health")
|
||||
.forStatusCode(200)
|
||||
.withStartupTimeout(Duration.ofMinutes(10))
|
||||
);
|
||||
// @ClassRule
|
||||
// public static GenericContainer cephContainer = new GenericContainer("dr.rbkmoney.com/ceph-demo:latest")
|
||||
// .withEnv("RGW_NAME", "localhost")
|
||||
// .withEnv("NETWORK_AUTO_DETECT", "4")
|
||||
// .withEnv("CEPH_DEMO_UID", "ceph-test")
|
||||
// .withEnv("CEPH_DEMO_ACCESS_KEY", AWS_ACCESS_KEY)
|
||||
// .withEnv("CEPH_DEMO_SECRET_KEY", AWS_SECRET_KEY)
|
||||
// .withEnv("CEPH_DEMO_BUCKET", BUCKET_NAME)
|
||||
// .withExposedPorts(5000, 80)
|
||||
// .waitingFor(
|
||||
// new HttpWaitStrategy()
|
||||
// .forPath("/api/v0.1/health")
|
||||
// .forStatusCode(200)
|
||||
// .withStartupTimeout(Duration.ofMinutes(10))
|
||||
// );
|
||||
|
||||
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
@ -68,9 +64,9 @@ public abstract class AbstractIntegrationTest {
|
||||
EnvironmentTestUtils.addEnvironment(
|
||||
"testcontainers",
|
||||
configurableApplicationContext.getEnvironment(),
|
||||
"storage.endpoint=" + cephContainer.getContainerIpAddress() + ":" + cephContainer.getMappedPort(80),
|
||||
// "storage.endpoint=" + cephContainer.getContainerIpAddress() + ":" + cephContainer.getMappedPort(80),
|
||||
// в случае, если поднят локальный сторедж в контейнере
|
||||
// "storage.endpoint=localhost:32827",
|
||||
"storage.endpoint=localhost:32827",
|
||||
"storage.signingRegion=" + SIGNING_REGION,
|
||||
"storage.accessKey=" + AWS_ACCESS_KEY,
|
||||
"storage.secretKey=" + AWS_SECRET_KEY,
|
||||
|
Loading…
Reference in New Issue
Block a user