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

fix: shared file access #156

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public abstract class AccessControlBaseController {
* @param filePath url encoded file path
*/
public Future<?> handle(String bucket, String filePath) {
ResourceType type = ResourceType.FILE;
String urlDecodedBucket = UrlUtil.decodePath(bucket);
String decryptedBucket = proxy.getEncryptionService().decrypt(urlDecodedBucket);
boolean hasReadAccess = isSharedWithMe(bucket, filePath);
boolean hasReadAccess = isSharedWithMe(type, bucket, filePath);
boolean hasWriteAccess = hasWriteAccess(filePath, decryptedBucket);
boolean hasAccess = checkFullAccess ? hasWriteAccess : hasReadAccess || hasWriteAccess;

Expand All @@ -37,7 +38,7 @@ public Future<?> handle(String bucket, String filePath) {

ResourceDescription resource;
try {
resource = ResourceDescription.fromEncoded(ResourceType.FILE, urlDecodedBucket, decryptedBucket, filePath);
resource = ResourceDescription.fromEncoded(type, urlDecodedBucket, decryptedBucket, filePath);
} catch (Exception ex) {
String errorMessage = ex.getMessage() != null ? ex.getMessage() : DEFAULT_RESOURCE_ERROR_MESSAGE.formatted(filePath);
return context.respond(HttpStatus.BAD_REQUEST, errorMessage);
Expand All @@ -48,8 +49,8 @@ public Future<?> handle(String bucket, String filePath) {

protected abstract Future<?> handle(ResourceDescription resource);

protected boolean isSharedWithMe(String bucket, String filePath) {
String url = bucket + BlobStorageUtil.PATH_SEPARATOR + filePath;
protected boolean isSharedWithMe(ResourceType type, String bucket, String filePath) {
String url = type.getGroup() + BlobStorageUtil.PATH_SEPARATOR + bucket + BlobStorageUtil.PATH_SEPARATOR + filePath;
return context.getApiKeyData().getAttachedFiles().contains(url);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/epam/aidial/core/FileApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public void testDownloadSharedFile(Vertx vertx, VertxTestContext context) {
apiKeyData1.setOriginalKey(projectApiKeyData.getOriginalKey());
// set deployment ID for proxyKey1
apiKeyData1.setSourceDeployment("EPM-RTC-GPT");
apiKeyData1.setAttachedFiles(Set.of("7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/folder1/file.txt"));
apiKeyData1.setAttachedFiles(Set.of("files/7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/folder1/file.txt"));
apiKeyStore.assignApiKey(apiKeyData1);

String apiKey1 = apiKeyData1.getPerRequestKey();
Expand Down