Skip to content

Commit

Permalink
Reorganize
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 003b257 commit e25d28f
Show file tree
Hide file tree
Showing 26 changed files with 128 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.opensearch.security.sampleextension.actions.create;

import org.opensearch.action.ActionType;
import org.opensearch.security.spi.actions.CreateResourceResponse;
import org.opensearch.security.spi.actions.resource.create.CreateResourceResponse;

/**
* Action to create a sample resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.actions.CreateResourceRequest;
import org.opensearch.security.spi.actions.resource.create.CreateResourceRequest;

import static java.util.Collections.singletonList;
import static org.opensearch.rest.RestRequest.Method.POST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.client.Client;
import org.opensearch.common.inject.Inject;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.actions.CreateResourceTransportAction;
import org.opensearch.security.spi.actions.resource.create.CreateResourceTransportAction;
import org.opensearch.transport.TransportService;

import static org.opensearch.security.sampleextension.SampleExtensionPlugin.RESOURCE_INDEX_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import org.opensearch.action.ActionType;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.actions.GetResourceResponse;
import org.opensearch.security.spi.actions.resource.get.GetResourceResponse;

/**
* Action to get a sample resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.security.spi.actions.GetResourceRequest;
import org.opensearch.security.spi.actions.resource.get.GetResourceRequest;

import static java.util.Collections.singletonList;
import static org.opensearch.rest.RestRequest.Method.GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import org.opensearch.common.inject.Inject;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.sampleextension.resource.SampleResourceSharingServiceProvider;
import org.opensearch.security.spi.actions.GetResourceTransportAction;
import org.opensearch.security.spi.actions.resource.get.GetResourceTransportAction;
import org.opensearch.transport.TransportService;

/**
* Transport action for UpdateSampleResource.
* Transport action for GetSampleResource.
*/
public class GetSampleResourceTransportAction extends GetResourceTransportAction<SampleResource> {
private static final Logger log = LogManager.getLogger(GetSampleResourceTransportAction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
package org.opensearch.security.sampleextension.actions.list;

import org.opensearch.action.ActionType;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.actions.resource.list.ListResourceResponse;

/**
* Action to list sample resources
*/
public class ListSampleResourceAction extends ActionType<ListSampleResourceResponse> {
public class ListSampleResourceAction extends ActionType<ListResourceResponse<SampleResource>> {
/**
* List sample resource action instance
*/
Expand All @@ -24,6 +26,6 @@ public class ListSampleResourceAction extends ActionType<ListSampleResourceRespo
public static final String NAME = "cluster:admin/sampleresource/list";

private ListSampleResourceAction() {
super(NAME, ListSampleResourceResponse::new);
super(NAME, in -> new ListResourceResponse<>(in, SampleResource::from));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.security.spi.actions.resource.list.ListResourceRequest;

import static java.util.Collections.singletonList;
import static org.opensearch.rest.RestRequest.Method.GET;
import static org.opensearch.security.sampleextension.SampleExtensionPlugin.RESOURCE_INDEX_NAME;

public class ListSampleResourceRestAction extends BaseRestHandler {

Expand All @@ -34,7 +36,7 @@ public String getName() {

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
final ListSampleResourceRequest listSampleResourceRequest = new ListSampleResourceRequest();
final ListResourceRequest listSampleResourceRequest = new ListResourceRequest(RESOURCE_INDEX_NAME);
return channel -> client.executeLocally(
ListSampleResourceAction.INSTANCE,
listSampleResourceRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,28 @@

package org.opensearch.security.sampleextension.actions.list;

import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.client.Client;
import org.opensearch.common.inject.Inject;
import org.opensearch.core.action.ActionListener;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.sampleextension.resource.SampleResourceSharingServiceProvider;
import org.opensearch.tasks.Task;
import org.opensearch.security.spi.actions.resource.list.ListResourceTransportAction;
import org.opensearch.transport.TransportService;

/**
* Transport action for ListSampleResource.
*/
public class ListSampleResourceTransportAction extends HandledTransportAction<ListSampleResourceRequest, ListSampleResourceResponse> {
private final TransportService transportService;
private final Client nodeClient;
private final SampleResourceSharingServiceProvider resourceSharingService;
public class ListSampleResourceTransportAction extends ListResourceTransportAction<SampleResource> {
private static final Logger log = LogManager.getLogger(ListSampleResourceTransportAction.class);

// TODO How can this inject work if either a DefaultResourceSharingService or SecurityResourceSharingService is binded?
@Inject
public ListSampleResourceTransportAction(
TransportService transportService,
ActionFilters actionFilters,
Client nodeClient,
SampleResourceSharingServiceProvider resourceSharingService
) {
super(ListSampleResourceAction.NAME, transportService, actionFilters, ListSampleResourceRequest::new);
this.transportService = transportService;
this.nodeClient = nodeClient;
this.resourceSharingService = resourceSharingService;
}

@Override
protected void doExecute(Task task, ListSampleResourceRequest request, ActionListener<ListSampleResourceResponse> listener) {
ActionListener<List<SampleResource>> sampleResourceListener = ActionListener.wrap(sampleResourcesList -> {
System.out.println("sampleResourcesList: " + sampleResourcesList);
listener.onResponse(new ListSampleResourceResponse(sampleResourcesList));
}, listener::onFailure);
resourceSharingService.get().listResources(sampleResourceListener);
super(transportService, actionFilters, ListSampleResourceAction.NAME, resourceSharingService.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.opensearch.security.sampleextension.actions.sharing;

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

/**
* Action to create a sample resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.opensearch.rest.action.RestToXContentListener;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.ShareWith;
import org.opensearch.security.spi.actions.UpdateResourceSharingRequest;
import org.opensearch.security.spi.actions.sharing.update.UpdateResourceSharingRequest;

import static java.util.Collections.singletonList;
import static org.opensearch.rest.RestRequest.Method.PUT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.opensearch.common.inject.Inject;
import org.opensearch.security.sampleextension.resource.SampleResource;
import org.opensearch.security.spi.ShareWith;
import org.opensearch.security.spi.actions.UpdateResourceSharingTransportAction;
import org.opensearch.security.spi.actions.sharing.update.UpdateResourceSharingTransportAction;
import org.opensearch.transport.TransportService;

import static org.opensearch.security.sampleextension.SampleExtensionPlugin.RESOURCE_INDEX_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
import org.opensearch.core.common.io.stream.StreamOutput;

public class ResourceRequest extends ActionRequest {
protected final String resourceId;

protected final String resourceIndex;

/**
* Default constructor
*/
public ResourceRequest(String resourceId, String resourceIndex) {
this.resourceId = resourceId;
public ResourceRequest(String resourceIndex) {
this.resourceIndex = resourceIndex;
}

public ResourceRequest(StreamInput in) throws IOException {
this.resourceId = in.readString();
this.resourceIndex = in.readString();
}

@Override
public void writeTo(final StreamOutput out) throws IOException {
out.writeString(resourceId);
out.writeString(resourceIndex);
}

Expand All @@ -36,10 +31,6 @@ public ActionRequestValidationException validate() {
return null;
}

public String getResourceId() {
return this.resourceId;
}

public String getResourceIndex() {
return this.resourceIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.create;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.create;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.create;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.get;

import java.io.IOException;

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.security.spi.actions.ResourceRequest;

/**
* Request object for GetSampleResource transport action
*/
public class GetResourceRequest extends ResourceRequest {
private final String resourceId;

/**
* Default constructor
*/
public GetResourceRequest(String resourceId, String resourceIndex) {
super(resourceId, resourceIndex);
super(resourceIndex);
this.resourceId = resourceId;
}

public GetResourceRequest(StreamInput in) throws IOException {
super(in);
this.resourceId = in.readString();
}

public String getResourceId() {
return this.resourceId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.get;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* compatible open source license.
*/

package org.opensearch.security.spi.actions;
package org.opensearch.security.spi.actions.resource.get;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.security.spi.actions.resource.list;

import java.io.IOException;

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.security.spi.actions.ResourceRequest;

/**
* Request object for ListSampleResource transport action
*/
public class ListResourceRequest extends ResourceRequest {

// TODO Change this into Search instead of List

/**
* Default constructor
*/
public ListResourceRequest(String resourceIndex) {
super(resourceIndex);
}

public ListResourceRequest(StreamInput in) throws IOException {
super(in);
}
}
Loading

0 comments on commit e25d28f

Please sign in to comment.