Skip to content

Commit

Permalink
WIP on share with rest action from security plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Dec 17, 2024
1 parent 291d33d commit 2593663
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@
import org.opensearch.security.rest.SecurityInfoAction;
import org.opensearch.security.rest.SecurityWhoAmIAction;
import org.opensearch.security.rest.TenantInfoAction;
import org.opensearch.security.rest.resource.ShareWithAction;
import org.opensearch.security.rest.resource.ShareWithTransportAction;
import org.opensearch.security.securityconf.DynamicConfigFactory;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.setting.OpensearchDynamicSetting;
Expand Down Expand Up @@ -701,6 +703,7 @@ public UnaryOperator<RestHandler> getRestHandlerWrapper(final ThreadContext thre
actions.add(new ActionHandler<>(CertificatesActionType.INSTANCE, TransportCertificatesInfoNodesAction.class));
}
actions.add(new ActionHandler<>(WhoAmIAction.INSTANCE, TransportWhoAmIAction.class));
actions.add(new ActionHandler<>(ShareWithAction.INSTANCE, ShareWithTransportAction.class));
}
return actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opensearch.security.configuration.ConfigurationRepository;
import org.opensearch.security.hasher.PasswordHasher;
import org.opensearch.security.privileges.PrivilegesEvaluator;
import org.opensearch.security.rest.resource.ShareWithRestAction;
import org.opensearch.security.spi.ResourceSharingExtension;
import org.opensearch.security.ssl.SslSettingsManager;
import org.opensearch.security.ssl.transport.PrincipalExtractor;
Expand Down Expand Up @@ -107,7 +108,8 @@ public static Collection<RestHandler> getHandler(
certificatesReloadEnabled,
securityApiDependencies
),
new CertificatesApiAction(clusterService, threadPool, securityApiDependencies)
new CertificatesApiAction(clusterService, threadPool, securityApiDependencies),
new ShareWithRestAction(resourceSharingExtensions)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
package org.opensearch.security.rest.resource;

import org.opensearch.action.ActionType;
import org.opensearch.security.spi.actions.sharing.update.UpdateResourceSharingResponse;

/**
* Action to update sharing configuration for a sample resource
*/
public class ShareWithAction extends ActionType<UpdateResourceSharingResponse> {
public class ShareWithAction extends ActionType<ShareWithResponse> {
/**
* Update sharing configuratino for sample resource action instance
* Update sharing configuration for sample resource action instance
*/
public static final ShareWithAction INSTANCE = new ShareWithAction();
/**
Expand All @@ -25,6 +24,6 @@ public class ShareWithAction extends ActionType<UpdateResourceSharingResponse> {
public static final String NAME = "cluster:admin/opendistro_security/resource/share_with";

private ShareWithAction() {
super(NAME, UpdateResourceSharingResponse::new);
super(NAME, ShareWithResponse::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,33 @@
import org.opensearch.action.update.UpdateRequest;
import org.opensearch.action.update.UpdateResponse;
import org.opensearch.client.Client;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.search.SearchHit;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.security.spi.Resource;
import org.opensearch.security.spi.ShareWith;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

/**
* Transport action for UpdateResourceSharing.
*/
public class ShareWithTransportAction<T extends Resource> extends HandledTransportAction<ShareWithRequest, ShareWithResponse> {
public class ShareWithTransportAction extends HandledTransportAction<ShareWithRequest, ShareWithResponse> {
private static final Logger log = LogManager.getLogger(ShareWithTransportAction.class);

public static final String RESOURCE_SHARING_INDEX = ".resource-sharing";

private final TransportService transportService;
private final Client nodeClient;

public ShareWithTransportAction(
TransportService transportService,
ActionFilters actionFilters,
Client nodeClient,
String actionName,
String resourceIndex,
Writeable.Reader<ShareWith> shareWithReader
) {
super(actionName, transportService, actionFilters, (in) -> new ShareWithRequest(in, shareWithReader));
@Inject
public ShareWithTransportAction(TransportService transportService, ActionFilters actionFilters, Client nodeClient) {
super(ShareWithAction.NAME, transportService, actionFilters, (in) -> new ShareWithRequest(in, ShareWith::new));
this.transportService = transportService;
this.nodeClient = nodeClient;
}
Expand Down

0 comments on commit 2593663

Please sign in to comment.