Commit 11b49a3d authored by Erik Leckner's avatar Erik Leckner
Browse files

file-azure filepath update

parent bfffd084
Pipeline #7172 failed with stage
in 41 seconds
......@@ -69,7 +69,7 @@ public class AzureTokenServiceImpl {
OffsetDateTime expires = calcTokenExpirationDate(duration, timeUnit);
UserDelegationKey key = rbacKeySource.getUserDelegationKey(OffsetDateTime.now(ZoneOffset.UTC).minusMinutes(1), expires);
BlobSasPermission permissions = BlobSasPermission.parse("crw");
BlobSasPermission permissions = BlobSasPermission.parse("rw");
BlobServiceSasSignatureValues tokenProps = new BlobServiceSasSignatureValues(expires, permissions);
String sasToken = tokenSource.generateUserDelegationSas(tokenProps, key);
String sasUri = String.format("%s?%s", blobUrl, sasToken);
......
......@@ -85,7 +85,12 @@ public class StorageServiceImpl implements IStorageService {
}
private String getFileLocationPrefix(Instant instant, String filename, String userDesID) {
return format("%s", filename);
String folderName = instant.toEpochMilli() + "-"
+ DATE_TIME_FORMATTER
.withZone(ZoneOffset.UTC)
.format(instant);
return format("%s/%s/%s", userDesID, folderName, filename);
}
}
......@@ -35,6 +35,7 @@ import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobContainerClientBuilder;
import com.azure.storage.blob.BlobUrlParts;
import com.azure.storage.blob.specialized.BlockBlobClient;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.file.provider.azure.common.base.MoreObjects;
......@@ -43,6 +44,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
......@@ -76,6 +79,7 @@ public class StorageImpl implements Storage {
return this.internalCreate(blobInfo, content);
}
@SneakyThrows
private Blob internalCreate(BlobInfo info, final byte[] content) {
String blobPath = generateBlobPath(storageAccount, info.getContainer(), info.getName());
BlobUrlParts parts = BlobUrlParts.parse(blobPath);
......@@ -83,7 +87,6 @@ public class StorageImpl implements Storage {
if (!blobContainerClient.exists()) {
createContainer(parts.getBlobContainerName());
}
/* Wei
BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(parts.getBlobName()).getBlockBlobClient();
if (!blockBlobClient.exists()) {
try (ByteArrayInputStream dataStream = new ByteArrayInputStream(content)) {
......@@ -94,7 +97,6 @@ public class StorageImpl implements Storage {
throw e;
}
}
*/
return new Blob(this, new BlobInfo.BuilderImpl(info.getBlobId()));
}
......
......@@ -39,7 +39,7 @@ public final class TestUtils {
public static final String UUID_REGEX = "(.{8})(.{4})(.{4})(.{4})(.{12})";
public static final Pattern AZURE_OBJECT_URI
= Pattern.compile("^https://[\\w,\\s-]+/[\\w,\\s-]+/?.*$");
= Pattern.compile("^https://[\\w,\\s-]+/[\\w,\\s-]+/[\\w,\\s-]+/[\\w,\\s-]+/?.*$");
public static final Condition<String> UUID_CONDITION
= new Condition<>(TestUtils::isValidUuid, "Valid UUID");
public static final Condition<String> AZURE_URL_CONDITION
......@@ -68,15 +68,15 @@ public final class TestUtils {
}
}
public static URI getAzureObjectUri(String containerName, String filename) {
return URI.create(format("%s%stest/%s/%s", AZURE_PROTOCOL, STORAGE_NAME, containerName, filename));
public static URI getAzureObjectUri(String containerName, String folderName, String filename) {
return URI.create(format("%s%stest/%s/%s/%s", AZURE_PROTOCOL, STORAGE_NAME, containerName, folderName, filename));
}
@SneakyThrows
public static URL getAzureObjectUrl(String containerName, String filename) {
public static URL getAzureObjectUrl(String containerName, String folderName, String filename) {
return new URL(format(
"%s%stest/%s/%s?sv=2019-07-07&se=2020-08-08T13A36A49Z&skoid=0fa47244-83d8-4311-b05c-fefb49d8b0a9&sktid=58975fd3-4977-44d0-bea8-37af0baac100&skt=2020-08-08T013A3649Z&ske=2020-08-08T133649Z&sks=b&skv=2019-07-07&sr=b&sp=r&sig=Hh5xGUpvTkEDeArXaWmV6FnSOMbYLRdHSfGlOlsC7wD2020-08-07",
AZURE_PROTOCOL, STORAGE_NAME, containerName, filename));
"%s%stest/%s/%s/%s?sv=2019-07-07&se=2020-08-08T13A36A49Z&skoid=0fa47244-83d8-4311-b05c-fefb49d8b0a9&sktid=58975fd3-4977-44d0-bea8-37af0baac100&skt=2020-08-08T013A3649Z&ske=2020-08-08T133649Z&sks=b&skv=2019-07-07&sr=b&sp=r&sig=Hh5xGUpvTkEDeArXaWmV6FnSOMbYLRdHSfGlOlsC7wD2020-08-07",
AZURE_PROTOCOL, STORAGE_NAME, containerName, folderName, filename));
}
public static Instant now() {
......
......@@ -90,7 +90,7 @@ class StorageServiceImplTest {
@Test
void shouldThrowExceptionWhenResultFilepathIsMoreThan1024Characters() {
// given
String fileId = RandomStringUtils.randomAlphanumeric(1025);
String fileId = RandomStringUtils.randomAlphanumeric(1024);
// when
Throwable thrown = catchThrowable(() -> storageService.createSignedUrl(fileId,
TestUtils.AUTHORIZATION_TOKEN, TestUtils.PARTITION));
......@@ -104,10 +104,11 @@ class StorageServiceImplTest {
private SignedObject getSignedObject() {
String containerName = RandomStringUtils.randomAlphanumeric(4);
String folderName = TestUtils.USER_DES_ID + "/" + RandomStringUtils.randomAlphanumeric(9);
String filename = TestUtils.getUuidString();
URI uri = TestUtils.getAzureObjectUri(containerName, filename);
URL url = TestUtils.getAzureObjectUrl(containerName, filename);
URI uri = TestUtils.getAzureObjectUri(containerName, folderName, filename);
URL url = TestUtils.getAzureObjectUrl(containerName, folderName, filename);
return SignedObject.builder()
.uri(uri)
......
......@@ -74,7 +74,7 @@ class StorageServiceImplTest {
// when
SignedUrl signedUrl = storageService.createSignedUrl(
TestUtils.FILE_ID, TestUtils.AUTHORIZATION_TOKEN, TestUtils.PARTITION);
System.out.println("URI" + signedUrl.getUri().toString());
// then
then(signedUrl).satisfies(url -> {
then(url.getUrl().toString()).is(TestUtils.GCS_URL_CONDITION);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment