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;
}

Check warning on line 46 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L44-L46

Added lines #L44 - L46 were not covered by tests

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

Check warning on line 50 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L48-L50

Added lines #L48 - L50 were not covered by tests

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

Check warning on line 53 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L53

Added line #L53 was not covered by tests
}

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<>();

Check warning on line 68 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L68

Added line #L68 was not covered by tests

if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
parser.nextToken();

Check warning on line 71 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L71

Added line #L71 was not covered by tests
Expand All @@ -90,7 +90,7 @@ public String getWriteableName() {

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

Check warning on line 94 in server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/ShareWith.java#L93-L94

Added lines #L93 - L94 were not covered by tests

@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();

Check warning on line 35 in server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java#L35

Added line #L35 was not covered by tests
}

/**
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;

Check warning on line 74 in server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/plugins/NoOpResourceAccessControlPlugin.java#L74

Added line #L74 was not covered by tests
}
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.