mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 10:14:08 +00:00
Throw an exception if the API returns 410
This commit is contained in:
parent
9b42bfb511
commit
8b4c29ec83
6 changed files with 52 additions and 12 deletions
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge
bridge
server
snapshot/base
|
@ -35,6 +35,7 @@ import uk.ac.ic.wlgitbridge.git.handler.hook.WriteLatexPutHook;
|
|||
import uk.ac.ic.wlgitbridge.server.FileHandler;
|
||||
import uk.ac.ic.wlgitbridge.server.PostbackContents;
|
||||
import uk.ac.ic.wlgitbridge.server.PostbackHandler;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.DisabledRepositoryException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.getforversion.SnapshotAttachment;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.push.PostbackManager;
|
||||
|
@ -383,6 +384,7 @@ public class Bridge {
|
|||
* @param hostname
|
||||
* @throws SnapshotPostException
|
||||
* @throws IOException
|
||||
* @throws DisabledRepositoryException
|
||||
* @throws ForbiddenException
|
||||
*/
|
||||
public void push(
|
||||
|
@ -391,7 +393,7 @@ public class Bridge {
|
|||
RawDirectory directoryContents,
|
||||
RawDirectory oldDirectoryContents,
|
||||
String hostname
|
||||
) throws SnapshotPostException, IOException, ForbiddenException {
|
||||
) throws SnapshotPostException, IOException, DisabledRepositoryException, ForbiddenException {
|
||||
try (LockGuard __ = lock.lockGuard(projectName)) {
|
||||
pushCritical(
|
||||
oauth2,
|
||||
|
@ -460,6 +462,7 @@ public class Bridge {
|
|||
* @param directoryContents
|
||||
* @param oldDirectoryContents
|
||||
* @throws IOException
|
||||
* @throws DisabledRepositoryException
|
||||
* @throws ForbiddenException
|
||||
* @throws SnapshotPostException
|
||||
*/
|
||||
|
@ -468,7 +471,7 @@ public class Bridge {
|
|||
String projectName,
|
||||
RawDirectory directoryContents,
|
||||
RawDirectory oldDirectoryContents
|
||||
) throws IOException, ForbiddenException, SnapshotPostException {
|
||||
) throws IOException, DisabledRepositoryException, ForbiddenException, SnapshotPostException {
|
||||
Log.info("[{}] Pushing", projectName);
|
||||
String postbackKey = postbackManager.makeKeyForProject(projectName);
|
||||
Log.info(
|
||||
|
|
|
@ -2,6 +2,7 @@ package uk.ac.ic.wlgitbridge.bridge.snapshot;
|
|||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import uk.ac.ic.wlgitbridge.data.CandidateSnapshot;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.DisabledRepositoryException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.getdoc.GetDocResult;
|
||||
|
@ -33,13 +34,14 @@ public interface SnapshotApi {
|
|||
String postbackKey);
|
||||
|
||||
static <T> T getResult(CompletableFuture<T> result)
|
||||
throws FailedConnectionException, ForbiddenException {
|
||||
throws DisabledRepositoryException, FailedConnectionException, ForbiddenException {
|
||||
try {
|
||||
return result.join();
|
||||
} catch (CompletionException e) {
|
||||
try {
|
||||
throw e.getCause();
|
||||
} catch (FailedConnectionException
|
||||
} catch (DisabledRepositoryException
|
||||
| FailedConnectionException
|
||||
| ForbiddenException
|
||||
| RuntimeException r) {
|
||||
throw r;
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.google.api.client.auth.oauth2.Credential;
|
|||
import uk.ac.ic.wlgitbridge.data.CandidateSnapshot;
|
||||
import uk.ac.ic.wlgitbridge.data.model.Snapshot;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.DisabledRepositoryException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.getdoc.GetDocResult;
|
||||
|
@ -65,7 +66,7 @@ public class SnapshotApiFacade {
|
|||
Optional<Credential> oauth2,
|
||||
CandidateSnapshot candidateSnapshot,
|
||||
String postbackKey
|
||||
) throws FailedConnectionException, ForbiddenException {
|
||||
) throws DisabledRepositoryException, FailedConnectionException, ForbiddenException {
|
||||
return SnapshotApi.getResult(api.push(
|
||||
oauth2, candidateSnapshot, postbackKey));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.apache.commons.codec.binary.Base64;
|
|||
import org.eclipse.jetty.server.Request;
|
||||
import uk.ac.ic.wlgitbridge.application.config.Oauth2;
|
||||
import uk.ac.ic.wlgitbridge.bridge.snapshot.SnapshotApi;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.DisabledRepositoryException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.getdoc.GetDocRequest;
|
||||
import uk.ac.ic.wlgitbridge.util.Instance;
|
||||
|
@ -76,6 +77,9 @@ public class Oauth2Filter implements Filter {
|
|||
filterChain
|
||||
);
|
||||
return;
|
||||
} catch (DisabledRepositoryException e) {
|
||||
Log.info("[{}] Git access disabled", project);
|
||||
throw new ServletException(e);
|
||||
}
|
||||
Log.info("[{}] Auth not needed", project);
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package uk.ac.ic.wlgitbridge.snapshot.base;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.SnapshotAPIException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class DisabledRepositoryException extends SnapshotAPIException {
|
||||
|
||||
@Override
|
||||
public void fromJSON(JsonElement json) {}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "project not accessible over git";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescriptionLines() {
|
||||
return Arrays.asList(getMessage());
|
||||
}
|
||||
|
||||
}
|
|
@ -50,7 +50,7 @@ public abstract class Request<T extends Result> {
|
|||
return ret;
|
||||
}
|
||||
|
||||
private T getResult() throws FailedConnectionException, ForbiddenException {
|
||||
private T getResult() throws DisabledRepositoryException, FailedConnectionException, ForbiddenException {
|
||||
try {
|
||||
HttpResponse response = future.get();
|
||||
Log.info(
|
||||
|
@ -68,12 +68,18 @@ public abstract class Request<T extends Result> {
|
|||
throw new FailedConnectionException();
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof HttpResponseException &&
|
||||
(((HttpResponseException) cause).getStatusCode() ==
|
||||
HttpServletResponse.SC_UNAUTHORIZED ||
|
||||
((HttpResponseException) cause).getStatusCode() ==
|
||||
HttpServletResponse.SC_FORBIDDEN)) {
|
||||
throw new ForbiddenException();
|
||||
if (cause instanceof HttpResponseException) {
|
||||
HttpResponseException httpCause = (HttpResponseException) cause;
|
||||
switch (httpCause.getStatusCode()) {
|
||||
case HttpServletResponse.SC_UNAUTHORIZED:
|
||||
case HttpServletResponse.SC_FORBIDDEN:
|
||||
throw new ForbiddenException();
|
||||
case HttpServletResponse.SC_GONE:
|
||||
throw new DisabledRepositoryException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
throw new FailedConnectionException(cause);
|
||||
} else {
|
||||
throw new FailedConnectionException(cause);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue