From e25d28fa6244cf9ee75818a244c5d564d88b2ca4 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 17 Dec 2024 16:54:16 -0500 Subject: [PATCH] Reorganize Signed-off-by: Craig Perkins --- .../create/CreateSampleResourceAction.java | 2 +- .../CreateSampleResourceRestAction.java | 2 +- .../CreateSampleResourceTransportAction.java | 2 +- .../actions/get/GetSampleResourceAction.java | 2 +- .../get/GetSampleResourceRestAction.java | 2 +- .../get/GetSampleResourceTransportAction.java | 4 +- .../list/ListSampleResourceAction.java | 6 ++- .../list/ListSampleResourceRequest.java | 39 ---------------- .../list/ListSampleResourceRestAction.java | 4 +- .../ListSampleResourceTransportAction.java | 30 +++---------- .../UpdateSampleResourceSharingAction.java | 2 +- ...UpdateSampleResourceSharingRestAction.java | 2 +- ...eSampleResourceSharingTransportAction.java | 2 +- .../security/spi/actions/ResourceRequest.java | 11 +---- .../create}/CreateResourceRequest.java | 2 +- .../create}/CreateResourceResponse.java | 2 +- .../CreateResourceTransportAction.java | 2 +- .../get}/GetResourceRequest.java | 12 ++++- .../get}/GetResourceResponse.java | 2 +- .../get}/GetResourceTransportAction.java | 2 +- .../resource/list/ListResourceRequest.java | 33 ++++++++++++++ .../resource/list/ListResourceResponse.java | 17 ++++--- .../list/ListResourceTransportAction.java | 45 +++++++++++++++++++ .../update}/UpdateResourceSharingRequest.java | 2 +- .../UpdateResourceSharingResponse.java | 2 +- .../UpdateResourceSharingTransportAction.java | 2 +- 26 files changed, 128 insertions(+), 105 deletions(-) delete mode 100644 sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRequest.java rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/create}/CreateResourceRequest.java (95%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/create}/CreateResourceResponse.java (96%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/create}/CreateResourceTransportAction.java (98%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/get}/GetResourceRequest.java (65%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/get}/GetResourceResponse.java (96%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => resource/get}/GetResourceTransportAction.java (97%) create mode 100644 spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceRequest.java rename sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceResponse.java => spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceResponse.java (65%) create mode 100644 spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceTransportAction.java rename spi/src/main/java/org/opensearch/security/spi/actions/{ => sharing/update}/UpdateResourceSharingRequest.java (96%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => sharing/update}/UpdateResourceSharingResponse.java (96%) rename spi/src/main/java/org/opensearch/security/spi/actions/{ => sharing/update}/UpdateResourceSharingTransportAction.java (99%) diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceAction.java index 19c2685ec3..618c31f24c 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceAction.java @@ -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 diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceRestAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceRestAction.java index e0be740991..315619b1d3 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceRestAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceRestAction.java @@ -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; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceTransportAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceTransportAction.java index 181947ba8b..05f4c986de 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceTransportAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/create/CreateSampleResourceTransportAction.java @@ -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; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceAction.java index fde94b365e..4ea3e20486 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceAction.java @@ -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 diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceRestAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceRestAction.java index 1ee29cf3e0..bb517d7668 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceRestAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceRestAction.java @@ -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; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceTransportAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceTransportAction.java index 55046c5664..5ea29634e7 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceTransportAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/get/GetSampleResourceTransportAction.java @@ -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 { private static final Logger log = LogManager.getLogger(GetSampleResourceTransportAction.class); diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceAction.java index aac9ab10d9..e91bb7e111 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceAction.java @@ -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 { +public class ListSampleResourceAction extends ActionType> { /** * List sample resource action instance */ @@ -24,6 +26,6 @@ public class ListSampleResourceAction extends ActionType new ListResourceResponse<>(in, SampleResource::from)); } } diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRequest.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRequest.java deleted file mode 100644 index 3a6acb5cfb..0000000000 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRequest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.sampleextension.actions.list; - -import java.io.IOException; - -import org.opensearch.action.ActionRequest; -import org.opensearch.action.ActionRequestValidationException; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.common.io.stream.StreamOutput; - -/** - * Request object for ListSampleResource transport action - */ -public class ListSampleResourceRequest extends ActionRequest { - - public ListSampleResourceRequest() {} - - /** - * Constructor with stream input - * @param in the stream input - * @throws IOException IOException - */ - public ListSampleResourceRequest(final StreamInput in) throws IOException {} - - @Override - public void writeTo(final StreamOutput out) throws IOException {} - - @Override - public ActionRequestValidationException validate() { - return null; - } -} diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRestAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRestAction.java index 4bab2c9ce6..da30b498f5 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRestAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceRestAction.java @@ -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 { @@ -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, diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceTransportAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceTransportAction.java index e7cda7e480..c8004f48e2 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceTransportAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceTransportAction.java @@ -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 { - private final TransportService transportService; - private final Client nodeClient; - private final SampleResourceSharingServiceProvider resourceSharingService; +public class ListSampleResourceTransportAction extends ListResourceTransportAction { + 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 listener) { - ActionListener> 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()); } } diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingAction.java index 4fcd311d3c..3df1e73f6d 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingAction.java @@ -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 diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingRestAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingRestAction.java index 94213787e0..42915299b9 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingRestAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingRestAction.java @@ -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; diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingTransportAction.java b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingTransportAction.java index 7e5981cf90..d21cd43f28 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingTransportAction.java +++ b/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/sharing/UpdateSampleResourceSharingTransportAction.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/ResourceRequest.java b/spi/src/main/java/org/opensearch/security/spi/actions/ResourceRequest.java index ae748e89a5..798bcce874 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/ResourceRequest.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/ResourceRequest.java @@ -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); } @@ -36,10 +31,6 @@ public ActionRequestValidationException validate() { return null; } - public String getResourceId() { - return this.resourceId; - } - public String getResourceIndex() { return this.resourceIndex; } diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceRequest.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceRequest.java similarity index 95% rename from spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceRequest.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceRequest.java index e930cf1ecf..69576bc040 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceRequest.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceRequest.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceResponse.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceResponse.java similarity index 96% rename from spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceResponse.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceResponse.java index 8e13c78c4e..5cbf28c7c9 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceResponse.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceResponse.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceTransportAction.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceTransportAction.java similarity index 98% rename from spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceTransportAction.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceTransportAction.java index ede88c5326..5c62a0b5e9 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/CreateResourceTransportAction.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/create/CreateResourceTransportAction.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceRequest.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceRequest.java similarity index 65% rename from spi/src/main/java/org/opensearch/security/spi/actions/GetResourceRequest.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceRequest.java index 546cf1be36..d7df10e4e8 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceRequest.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceRequest.java @@ -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; } } diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceResponse.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceResponse.java similarity index 96% rename from spi/src/main/java/org/opensearch/security/spi/actions/GetResourceResponse.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceResponse.java index 0b90f90221..6f57097861 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceResponse.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceResponse.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceTransportAction.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceTransportAction.java similarity index 97% rename from spi/src/main/java/org/opensearch/security/spi/actions/GetResourceTransportAction.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceTransportAction.java index 3ada340ef8..bb5e5ba934 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/GetResourceTransportAction.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/get/GetResourceTransportAction.java @@ -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; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceRequest.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceRequest.java new file mode 100644 index 0000000000..b0c1f199ca --- /dev/null +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceRequest.java @@ -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); + } +} diff --git a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceResponse.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceResponse.java similarity index 65% rename from sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceResponse.java rename to spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceResponse.java index 7225ed835d..1d2812a768 100644 --- a/sample-extension-plugin/src/main/java/org/opensearch/security/sampleextension/actions/list/ListSampleResourceResponse.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceResponse.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.sampleextension.actions.list; +package org.opensearch.security.spi.actions.resource.list; import java.io.IOException; import java.util.List; @@ -16,21 +16,20 @@ import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.security.sampleextension.resource.SampleResource; import org.opensearch.security.spi.Resource; /** - * Response to a ListSampleResourceRequest + * Response to a GetSampleResourceRequest */ -public class ListSampleResourceResponse extends ActionResponse implements ToXContentObject { - private final List resources; +public class ListResourceResponse extends ActionResponse implements ToXContentObject { + private final List resources; /** * Default constructor * * @param resources The resources */ - public ListSampleResourceResponse(List resources) { + public ListResourceResponse(List resources) { this.resources = resources; } @@ -44,14 +43,14 @@ public void writeTo(StreamOutput out) throws IOException { * * @param in the stream input */ - public ListSampleResourceResponse(final StreamInput in) throws IOException { - resources = in.readList(SampleResource::from); + public ListResourceResponse(final StreamInput in, Reader resourceReader) throws IOException { + resources = in.readList(resourceReader); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.array("resources", (Object[]) resources.toArray(new Resource[0])); + builder.field("resources", resources); builder.endObject(); return builder; } diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceTransportAction.java b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceTransportAction.java new file mode 100644 index 0000000000..29b405b160 --- /dev/null +++ b/spi/src/main/java/org/opensearch/security/spi/actions/resource/list/ListResourceTransportAction.java @@ -0,0 +1,45 @@ +/* + * 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.util.List; + +import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.HandledTransportAction; +import org.opensearch.core.action.ActionListener; +import org.opensearch.security.spi.Resource; +import org.opensearch.security.spi.ResourceSharingService; +import org.opensearch.tasks.Task; +import org.opensearch.transport.TransportService; + +/** + * Transport action for GetResource. + */ +public class ListResourceTransportAction extends HandledTransportAction> { + private final ResourceSharingService resourceSharingService; + + public ListResourceTransportAction( + TransportService transportService, + ActionFilters actionFilters, + String actionName, + ResourceSharingService resourceSharingService + ) { + super(actionName, transportService, actionFilters, ListResourceRequest::new); + this.resourceSharingService = resourceSharingService; + } + + @Override + protected void doExecute(Task task, ListResourceRequest request, ActionListener> listener) { + ActionListener> sampleResourceListener = ActionListener.wrap(sampleResourcesList -> { + System.out.println("sampleResourcesList: " + sampleResourcesList); + listener.onResponse(new ListResourceResponse(sampleResourcesList)); + }, listener::onFailure); + resourceSharingService.listResources(sampleResourceListener); + } +} diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingRequest.java b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingRequest.java similarity index 96% rename from spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingRequest.java rename to spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingRequest.java index c658b34430..eda3b533b1 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingRequest.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingRequest.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.spi.actions; +package org.opensearch.security.spi.actions.sharing.update; import java.io.IOException; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingResponse.java b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingResponse.java similarity index 96% rename from spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingResponse.java rename to spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingResponse.java index 3fd4887f9c..7bf8fe2f32 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingResponse.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingResponse.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.spi.actions; +package org.opensearch.security.spi.actions.sharing.update; import java.io.IOException; diff --git a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingTransportAction.java b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingTransportAction.java similarity index 99% rename from spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingTransportAction.java rename to spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingTransportAction.java index 35cd9105e4..3157e98255 100644 --- a/spi/src/main/java/org/opensearch/security/spi/actions/UpdateResourceSharingTransportAction.java +++ b/spi/src/main/java/org/opensearch/security/spi/actions/sharing/update/UpdateResourceSharingTransportAction.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.security.spi.actions; +package org.opensearch.security.spi.actions.sharing.update; import java.io.IOException; import java.util.Arrays;