Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2912: Support folder browsing for static resources #2917

Merged
Prev Previous commit
Next Next commit
Issue #2912 Check path type in the cloud
  • Loading branch information
mzueva committed Nov 9, 2022
commit 5b0c9481d6400ceec22a4cb925b8198067d9c009
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,12 @@ public void checkDataStorageObjectExists(final AbstractDataStorage dataStorage,
path, dataStorage.getRoot())));
}

public DataStorageItemType getItemType(final AbstractDataStorage dataStorage,
final String path,
final String version) {
return storageProviderManager.getItemType(dataStorage, path, version);
}

private void assertToolsToMount(final DataStorageVO dataStorageVO) {
if (!CollectionUtils.isEmpty(dataStorageVO.getToolsToMount())) {
for (ToolFingerprint tool : dataStorageVO.getToolsToMount()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -249,4 +250,10 @@ public String verifyOrDefaultRestoreMode(final AbstractDataStorage dataStorage,
final StorageRestoreActionRequest restoreActionRequest) {
return getStorageProvider(dataStorage).verifyOrDefaultRestoreMode(restoreActionRequest);
}

public DataStorageItemType getItemType(final AbstractDataStorage dataStorage,
final String path,
final String version) {
return getStorageProvider(dataStorage).getItemType(dataStorage, path, version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -138,4 +139,6 @@ default StoragePolicy buildPolicy(VersioningAwareRegion region, StoragePolicy st
void verifyRestoreActionSupported();

String verifyOrDefaultRestoreMode(StorageRestoreActionRequest restoreMode);

DataStorageItemType getItemType(T dataStorage, String path, String version);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import com.epam.pipeline.entity.datastorage.StoragePolicy;
import com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage;
import com.epam.pipeline.entity.region.AwsRegion;
import com.epam.pipeline.exception.ObjectNotFoundException;
import com.epam.pipeline.manager.datastorage.providers.ProviderUtils;
import com.epam.pipeline.utils.FileContentUtils;
import com.google.common.primitives.SignedBytes;
Expand Down Expand Up @@ -1113,7 +1114,7 @@ private DataStorageItemType getNonVersionType(AmazonS3 client, String bucket, St
} else if (!listing.getObjectSummaries().isEmpty()) {
return DataStorageItemType.File;
} else {
throw new IllegalArgumentException(messageHelper
throw new ObjectNotFoundException(messageHelper
.getMessage(MessageConstants.ERROR_DATASTORAGE_PATH_NOT_FOUND, path, bucket));
}
}
Expand All @@ -1130,7 +1131,7 @@ private DataStorageItemType getVersionType(AmazonS3 client, String bucket, Strin
} else if (!listing.getVersionSummaries().isEmpty()) {
return DataStorageItemType.File;
} else {
throw new IllegalArgumentException(messageHelper
throw new ObjectNotFoundException(messageHelper
.getMessage(MessageConstants.ERROR_DATASTORAGE_PATH_NOT_FOUND, path, bucket));
}
}
Expand Down Expand Up @@ -1217,6 +1218,12 @@ public static void validateFolderPathMatchingMasks(final S3bucketDataStorage dat
}
}

public DataStorageItemType getItemType(final String bucket,
final String path,
final String version) {
return checkItemType(getDefaultS3Client(), bucket, path, StringUtils.hasValue(version));
}

private static void validatePathMatchingMasks(final S3bucketDataStorage dataStorage, final String path) {
final Set<String> linkingMasks = dataStorage.getLinkingMasks();
if (CollectionUtils.isNotEmpty(linkingMasks)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -442,6 +443,14 @@ public S3Helper getS3Helper(final TemporaryCredentials credentials, final AwsReg
return new TemporaryCredentialsS3Helper(credentials, messageHelper, region);
}

@Override
public DataStorageItemType getItemType(final S3bucketDataStorage dataStorage,
final String path,
final String version) {
return getS3Helper(dataStorage).getItemType(dataStorage.getRoot(),
ProviderUtils.buildPath(dataStorage, path), version);
}

private AwsRegion getAwsRegion(S3bucketDataStorage dataStorage) {
return cloudRegionManager.getAwsRegion(dataStorage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -297,6 +298,13 @@ public String verifyOrDefaultRestoreMode(final StorageRestoreActionRequest actio
throw new UnsupportedOperationException("Restore mechanism isn't supported for this provider.");
}

@Override
public DataStorageItemType getItemType(final AzureBlobStorage dataStorage,
final String path,
final String version) {
throw new UnsupportedOperationException();
}

private AzureStorageHelper getAzureStorageHelper(final AzureBlobStorage storage) {
final AzureRegion region = cloudRegionManager.getAzureRegion(storage);
final AzureRegionCredentials credentials = cloudRegionManager.loadCredentials(region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -253,6 +254,13 @@ public String verifyOrDefaultRestoreMode(final StorageRestoreActionRequest actio
throw new UnsupportedOperationException("Restore mechanism isn't supported for this provider.");
}

@Override
public DataStorageItemType getItemType(final GSBucketStorage dataStorage,
final String path,
final String version) {
throw new UnsupportedOperationException();
}

private GSBucketStorageHelper getHelper(final GSBucketStorage storage) {
final GCPRegion gcpRegion = cloudRegionManager.getGCPRegion(storage);
return new GSBucketStorageHelper(messageHelper, gcpRegion, gcpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.epam.pipeline.entity.datastorage.DataStorageFile;
import com.epam.pipeline.entity.datastorage.DataStorageFolder;
import com.epam.pipeline.entity.datastorage.DataStorageItemContent;
import com.epam.pipeline.entity.datastorage.DataStorageItemType;
import com.epam.pipeline.entity.datastorage.DataStorageListing;
import com.epam.pipeline.entity.datastorage.DataStorageStreamingContent;
import com.epam.pipeline.entity.datastorage.DataStorageType;
Expand Down Expand Up @@ -535,6 +536,13 @@ public String verifyOrDefaultRestoreMode(final StorageRestoreActionRequest actio
throw new UnsupportedOperationException("Restore mechanism isn't supported for this provider.");
}

@Override
public DataStorageItemType getItemType(final NFSDataStorage dataStorage,
final String path,
final String version) {
throw new UnsupportedOperationException();
}

private String encodeUrl(final String path) {
try {
return URLEncoder.encode(path, StandardCharsets.UTF_8.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -68,7 +66,8 @@ public DataStorageStreamingContent getContent(final String path) {
Assert.isTrue(StringUtils.isNotBlank(filePath),
messageHelper.getMessage(MessageConstants.ERROR_STATIC_RESOURCES_INVALID_PATH));
final AbstractDataStorage storage = dataStorageManager.loadByNameOrId(bucketName);
if (Files.isDirectory(Paths.get(path))) {
final DataStorageItemType itemType = dataStorageManager.getItemType(storage, filePath, null);
if (itemType == DataStorageItemType.Folder) {
final List<AbstractDataStorageItem> items = dataStorageManager.getDataStorageItems(storage.getId(),
path, false, null, null).getResults();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix path -> filePath

final String tmplPath = preferenceManager.getPreference(
Expand All @@ -79,7 +78,6 @@ public DataStorageStreamingContent getContent(final String path) {
final String html = buildHtml(items, tmplPath, tmplName, staticResourcesPrefix);
return new DataStorageStreamingContent(new ByteArrayInputStream(html.getBytes()), filePath);
}
dataStorageManager.checkDataStorageObjectExists(storage, filePath, null);
return dataStorageManager.getStreamingContent(storage.getId(), filePath, null);
}

Expand Down