|
|
@@ -10,9 +10,12 @@ import lombok.NonNull; |
|
|
|
import org.glassfish.jersey.server.ContainerRequest; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import javax.annotation.Nullable; |
|
|
|
import javax.ws.rs.*; |
|
|
|
import javax.ws.rs.core.Context; |
|
|
|
import javax.ws.rs.core.Response; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import static bubble.ApiConstants.*; |
|
|
|
import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON; |
|
|
@@ -37,13 +40,19 @@ public class LogsResource { |
|
|
|
} |
|
|
|
|
|
|
|
@POST @Path(EP_START) |
|
|
|
@NonNull public Response startLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(true); } |
|
|
|
@NonNull public Response startLogging(@NonNull @Context final ContainerRequest ctx, |
|
|
|
@Nullable @QueryParam("ttlDays") final Byte ttlDays) { |
|
|
|
return setLogFlag(true, Optional.ofNullable(ttlDays)); |
|
|
|
} |
|
|
|
|
|
|
|
@POST @Path(EP_STOP) |
|
|
|
@NonNull public Response stopLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(false); } |
|
|
|
@NonNull public Response stopLogging(@NonNull @Context final ContainerRequest ctx) { |
|
|
|
return setLogFlag(false, Optional.empty()); |
|
|
|
} |
|
|
|
|
|
|
|
@NonNull private Response setLogFlag(final boolean b) { |
|
|
|
@NonNull private Response setLogFlag(final boolean b, @NonNull final Optional<Byte> ttlInDays) { |
|
|
|
if (!account.admin()) throw forbiddenEx(); // caller must be admin |
|
|
|
selfNodeService.setLogFlag(b); |
|
|
|
selfNodeService.setLogFlag(b, ttlInDays.map(days -> (int) TimeUnit.DAYS.toSeconds(days))); |
|
|
|
return ok(); |
|
|
|
} |
|
|
|
} |