Commit 03f812f4 authored by Marco Descher's avatar Marco Descher 🏔

[15349] Update system rest interface

parent 3b991f98
Pipeline #10430 passed with stages
in 2 minutes and 24 seconds
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="info.elexis.server.core.rest.v1.RestResource">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="info.elexis.server.core.jaxrs.SystemResource">
<service>
<provide interface="info.elexis.server.core.rest.v1.RestResource"/>
<provide interface="info.elexis.server.core.jaxrs.SystemResource"/>
</service>
<implementation class="info.elexis.server.core.rest.v1.RestResource"/>
<implementation class="info.elexis.server.core.jaxrs.SystemResource"/>
</scr:component>
\ No newline at end of file
package info.elexis.server.core.jaxrs;
import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.osgi.service.component.annotations.Component;
import info.elexis.server.core.Application;
import info.elexis.server.core.common.util.CoreUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
@Api(tags = { "system" })
@Path("system")
@Component(service = SystemResource.class, immediate = true)
public class SystemResource {
@GET
@Path("uptime")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(nickname = "uptime", value = "show how long system has been running")
public String getUptime() {
return Application.uptime();
}
@GET
@Path("log")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(nickname = "downloadTodaysLogAsTxt", value = "download todays log file", authorizations = {
@Authorization(value = "esoauth") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "", response = File.class) })
@RequiresRoles("esadmin")
public Response getLogFileOfToday() {
File logFile = CoreUtil.getHomeDirectory().resolve("logs/elexis-server.log").toFile();
if (logFile.exists() && logFile.canRead()) {
ResponseBuilder response = Response.ok((Object) logFile);
response.header("Content-Disposition", "attachment;filename=" + logFile.getName() + ".txt");
return response.build();
}
return Response.serverError().build();
}
@POST
@ApiOperation(nickname = "restartSystem", value = "perform a system restart", authorizations = {
@Authorization(value = "esoauth") })
@RequiresRoles("esadmin")
@ApiResponses(value = { @ApiResponse(code = 422, message = "restart was vetoed, see message for reason") })
public Response performSystemRestart() {
String veto = Application.restart(false);
if (veto != null) {
return Response.status(422).type(MediaType.TEXT_PLAIN).entity(veto).build();
}
return Response.ok().build();
}
}
package info.elexis.server.core.rest.v1;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.osgi.service.component.annotations.Component;
import info.elexis.server.core.Application;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import io.swagger.annotations.AuthorizationScope;
@Deprecated
@Api(value = "/system", tags = { "system" })
@Path("system/v1")
@Component(service = RestResource.class, immediate = true)
public class RestResource {
@GET
@Path("uptime")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "show how long system has been running")
public String uptime() {
return Application.uptime();
}
@GET
@Path("protected")
@Produces(MediaType.TEXT_PLAIN)
@RequiresRoles("esadmin")
@ApiOperation(value = "Get the system status in plaintext", authorizations = {
@Authorization(value = "esoauth", scopes = {
@AuthorizationScope(scope = "esadmin", description = "bla") }) })
/**
* @return
*/
@Deprecated
public String getStatusPlaintext() {
return "PROTECTED RESOURCE";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment