Skip to content

Commit

Permalink
Fixes NPE
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 8, 2024
1 parent 4dc7597 commit 0349537
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opensearch.sample.actions.access.revoke.RevokeResourceAccessAction;
import org.opensearch.sample.actions.access.revoke.RevokeResourceAccessRequest;
import org.opensearch.sample.actions.access.revoke.RevokeResourceAccessResponse;
import org.opensearch.sample.utils.SampleResourcePluginException;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

Expand All @@ -37,22 +38,25 @@ public RevokeResourceAccessTransportAction(TransportService transportService, Ac
@Override
protected void doExecute(Task task, RevokeResourceAccessRequest request, ActionListener<RevokeResourceAccessResponse> listener) {
try {
revokeAccess(request);
ResourceSharing revoke = revokeAccess(request);
if (revoke == null) {
log.error("Failed to revoke access to resource {}", request.getResourceId());
SampleResourcePluginException se = new SampleResourcePluginException(
"Failed to revoke access to resource " + request.getResourceId()
);
listener.onFailure(se);
return;
}
log.info("Revoked resource access for resource: {} with {}", request.getResourceId(), revoke.toString());
listener.onResponse(new RevokeResourceAccessResponse("Resource " + request.getResourceId() + " access revoked successfully."));
} catch (Exception e) {
listener.onFailure(e);
}
}

private void revokeAccess(RevokeResourceAccessRequest request) {
try {
ResourceService rs = SampleResourcePlugin.GuiceHolder.getResourceService();
ResourceSharing revoke = rs.getResourceAccessControlPlugin()
.revokeAccess(request.getResourceId(), RESOURCE_INDEX_NAME, request.getRevokeAccess(), request.getScopes());
log.info("Revoked resource access for resource: {} with {}", request.getResourceId(), revoke.toString());
} catch (Exception e) {
log.info("Failed to revoke access for resource {}", request.getResourceId(), e);
throw e;
}
private ResourceSharing revokeAccess(RevokeResourceAccessRequest request) {
ResourceService rs = SampleResourcePlugin.GuiceHolder.getResourceService();
return rs.getResourceAccessControlPlugin()
.revokeAccess(request.getResourceId(), RESOURCE_INDEX_NAME, request.getRevokeAccess(), request.getScopes());
}
}

0 comments on commit 0349537

Please sign in to comment.