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

feat: Support auto-sharing of folders #265 #272

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -33,6 +33,7 @@ public class ApiKeyData {
private String spanId;
// list of attached file URLs collected from conversation history of the current request
private Set<String> attachedFiles = new HashSet<>();
private List<String> attachedFolders = new ArrayList<>();
// deployment name of the source(application/assistant/model) associated with the current request
private String sourceDeployment;
// Execution path of the root request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public Future<?> handle(String resourceType, String bucket, String path) {

if (!checkFullAccess) {
// some per-request API-keys may have access to the resources implicitly
boolean isAutoShared = context.getApiKeyData().getAttachedFiles().contains(resource.getUrl());
if (isAutoShared) {
if (proxy.getAccessService().isAutoSharedResource(resource, context)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ private void processAttachedFile(String url) {
if (accessService.hasWriteAccess(resource, context)
|| accessService.isSharedResource(resource, context)
|| sourceApiKeyData.getAttachedFiles().contains(resourceUrl)) {
destApiKeyData.getAttachedFiles().add(resourceUrl);
if (resource.isFolder()) {
destApiKeyData.getAttachedFolders().add(resourceUrl);
} else {
destApiKeyData.getAttachedFiles().add(resourceUrl);
}
} else {
throw new HttpException(HttpStatus.FORBIDDEN, "Access denied to the file %s".formatted(url));
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/epam/aidial/core/security/AccessService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.epam.aidial.core.util.UrlUtil;
import lombok.AllArgsConstructor;

import java.util.List;

@AllArgsConstructor
public class AccessService {

Expand Down Expand Up @@ -49,4 +51,19 @@ public boolean isReviewResource(ResourceDescription resource, ProxyContext conte
String actualUserBucket = encryptionService.encrypt(actualUserLocation);
return publicationService != null && publicationService.hasReviewAccess(resource, actualUserBucket, actualUserLocation);
}

public boolean isAutoSharedResource(ResourceDescription resource, ProxyContext context) {
Maxim-Gadalov marked this conversation as resolved.
Show resolved Hide resolved
String resourceUrl = resource.getUrl();
boolean isAutoShared = context.getApiKeyData().getAttachedFiles().contains(resourceUrl);
if (isAutoShared) {
return true;
}
List<String> attachedFolders = context.getApiKeyData().getAttachedFolders();
for (String folder : attachedFolders) {
if (resourceUrl.startsWith(folder)) {
return true;
}
}
return false;
}
}
Loading