Skip to content

Commit

Permalink
Convert sets to lists
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 5, 2024
1 parent 04a02cb commit e468f91
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;

/**
* This class contains information about whom a resource is shared with and at what scope.
Expand All @@ -39,17 +39,17 @@
*/
public class ShareWith implements ToXContentFragment, NamedWriteable {

private final List<SharedWithScope> sharedWithScopes;
private final Set<SharedWithScope> sharedWithScopes;

public ShareWith(List<SharedWithScope> sharedWithScopes) {
public ShareWith(Set<SharedWithScope> sharedWithScopes) {
this.sharedWithScopes = sharedWithScopes;
}

public ShareWith(StreamInput in) throws IOException {
this.sharedWithScopes = in.readList(SharedWithScope::new);
this.sharedWithScopes = in.readSet(SharedWithScope::new);
}

public List<SharedWithScope> getSharedWithScopes() {
public Set<SharedWithScope> getSharedWithScopes() {
return sharedWithScopes;
}

Expand All @@ -65,7 +65,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

public static ShareWith fromXContent(XContentParser parser) throws IOException {
List<SharedWithScope> sharedWithScopes = new ArrayList<>();
Set<SharedWithScope> sharedWithScopes = new HashSet<>();

if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
parser.nextToken();
Expand All @@ -90,7 +90,7 @@ public String getWriteableName() {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeList(sharedWithScopes);
out.writeCollection(sharedWithScopes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.opensearch.accesscontrol.resources.ResourceSharing;
import org.opensearch.accesscontrol.resources.ShareWith;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* This plugin class defines a no-op implementation of Resource Plugin.
Expand All @@ -29,10 +29,10 @@ public class NoOpResourceAccessControlPlugin implements ResourceAccessControlPlu
* @return empty list
*/
@Override
public List<String> listAccessibleResourcesInPlugin(String systemIndexName) {
public Set<String> listAccessibleResourcesInPlugin(String systemIndexName) {
// returns an empty list since security plugin is disabled
// TODO: check whether this should return all entries in the given index
return List.of();
return Set.of();
}

/**
Expand Down Expand Up @@ -68,8 +68,8 @@ public ResourceSharing shareWith(String resourceId, String systemIndexName, Shar
public ResourceSharing revokeAccess(
String resourceId,
String systemIndexName,
Map<EntityType, List<String>> revokeAccess,
List<String> scopes
Map<EntityType, Set<String>> revokeAccess,
Set<String> scopes
) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.opensearch.accesscontrol.resources.ResourceSharing;
import org.opensearch.accesscontrol.resources.ShareWith;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* This interface determines presence of security plugin in the cluster.
Expand All @@ -31,9 +31,9 @@ public interface ResourceAccessControlPlugin {
/**
* Returns all accessible resources for current user for a given system .
*
* @return list of {@link ResourceSharing} items accessible by current user.
* @return set of {@link ResourceSharing} items accessible by current user.
*/
List<String> listAccessibleResourcesInPlugin(String systemIndex);
Set<String> listAccessibleResourcesInPlugin(String systemIndex);

/**
* Checks whether current user has permission to given resource.
Expand Down Expand Up @@ -64,12 +64,7 @@ public interface ResourceAccessControlPlugin {
* @param scopes Scopes to be checked for revoking access. If empty, all scopes will be checked.
* @return the updated ResourceSharing record
*/
ResourceSharing revokeAccess(
String resourceId,
String systemIndexName,
Map<EntityType, List<String>> revokeAccess,
List<String> scopes
);
ResourceSharing revokeAccess(String resourceId, String systemIndexName, Map<EntityType, Set<String>> revokeAccess, Set<String> scopes);

/**
* Deletes an entry from .resource_sharing index
Expand Down

0 comments on commit e468f91

Please sign in to comment.