forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#11079 from IQSS/10930-marketplace-external-to…
…ols-apis add new non-admin APIs for external tools registration (for marketplace)
- Loading branch information
Showing
5 changed files
with
236 additions
and
2 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
doc/release-notes/10930-marketplace-external-tools-apis.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## New APIs for External Tools Registration for Marketplace | ||
|
||
New API base path /api/externalTools created that mimics the admin APIs /api/admin/externalTools. These new add and delete apis require an authenticated superuser token. | ||
|
||
Example: | ||
``` | ||
API_TOKEN='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' | ||
export TOOL_ID=1 | ||
curl http://localhost:8080/api/externalTools | ||
curl http://localhost:8080/api/externalTools/$TOOL_ID | ||
curl -s -H "X-Dataverse-key:$API_TOKEN" -X POST -H 'Content-type: application/json' http://localhost:8080/api/externalTools --upload-file fabulousFileTool.json | ||
curl -s -H "X-Dataverse-key:$API_TOKEN" -X DELETE http://localhost:8080/api/externalTools/$TOOL_ID | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/edu/harvard/iq/dataverse/api/ExternalToolsApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.harvard.iq.dataverse.api; | ||
|
||
import edu.harvard.iq.dataverse.api.auth.AuthRequired; | ||
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@Path("externalTools") | ||
public class ExternalToolsApi extends AbstractApiBean { | ||
|
||
@Inject | ||
ExternalTools externalTools; | ||
|
||
@GET | ||
public Response getExternalTools() { | ||
return externalTools.getExternalTools(); | ||
} | ||
|
||
@GET | ||
@Path("{id}") | ||
public Response getExternalTool(@PathParam("id") long externalToolIdFromUser) { | ||
return externalTools.getExternalTool(externalToolIdFromUser); | ||
} | ||
|
||
@POST | ||
@AuthRequired | ||
public Response addExternalTool(@Context ContainerRequestContext crc, String manifest) { | ||
Response notAuthorized = authorize(crc); | ||
return notAuthorized == null ? externalTools.addExternalTool(manifest) : notAuthorized; | ||
} | ||
|
||
@DELETE | ||
@AuthRequired | ||
@Path("{id}") | ||
public Response deleteExternalTool(@Context ContainerRequestContext crc, @PathParam("id") long externalToolIdFromUser) { | ||
Response notAuthorized = authorize(crc); | ||
return notAuthorized == null ? externalTools.deleteExternalTool(externalToolIdFromUser) : notAuthorized; | ||
} | ||
|
||
private Response authorize(ContainerRequestContext crc) { | ||
try { | ||
AuthenticatedUser user = getRequestAuthenticatedUserOrDie(crc); | ||
if (!user.isSuperuser()) { | ||
return error(Response.Status.FORBIDDEN, "Superusers only."); | ||
} | ||
} catch (WrappedResponse ex) { | ||
return error(Response.Status.FORBIDDEN, "Superusers only."); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters