diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/config/Config.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/config/Config.java index eb64fe15be..53c9ad7d46 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/config/Config.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/config/Config.java @@ -29,7 +29,9 @@ public class Config implements JSONSource { config.apiBaseURL, config.postbackURL, config.serviceName, - Oauth2.asSanitised(config.oauth2) + Oauth2.asSanitised(config.oauth2), + SwapStoreConfig.sanitisedCopy(config.swapStore), + config.swapJob ); } @@ -56,14 +58,18 @@ public class Config implements JSONSource { fromJSON(new Gson().fromJson(reader, JsonElement.class)); } - public Config(int port, - String rootGitDirectory, - String username, - String password, - String apiBaseURL, - String postbackURL, - String serviceName, - Oauth2 oauth2) { + public Config( + int port, + String rootGitDirectory, + String username, + String password, + String apiBaseURL, + String postbackURL, + String serviceName, + Oauth2 oauth2, + SwapStoreConfig swapStore, + SwapJobConfig swapJob + ) { this.port = port; this.rootGitDirectory = rootGitDirectory; this.username = username; @@ -72,6 +78,8 @@ public class Config implements JSONSource { this.postbackURL = postbackURL; this.serviceName = serviceName; this.oauth2 = oauth2; + this.swapStore = swapStore; + this.swapJob = swapJob; } @Override diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java index 9556412162..73e82fd6c9 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImpl.java @@ -153,6 +153,7 @@ public class SwapJobImpl implements SwapJob { projName, swapStore.openDownloadStream(projName) ); + swapStore.remove(projName); dbStore.setLastAccessedTime( projName, Timestamp.valueOf(LocalDateTime.now()) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/store/SwapStoreConfig.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/store/SwapStoreConfig.java index de10c5d506..61219d02ee 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/store/SwapStoreConfig.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/swap/store/SwapStoreConfig.java @@ -60,4 +60,17 @@ public class SwapStoreConfig { return s3BucketName; } + public SwapStoreConfig sanitisedCopy() { + return new SwapStoreConfig( + type, + awsAccessKey == null ? null : "", + awsSecret == null ? null : "", + s3BucketName + ); + } + + public static SwapStoreConfig sanitisedCopy(SwapStoreConfig swapStore) { + return swapStore == null ? null : swapStore.sanitisedCopy(); + } + } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java index 0da75e1c49..d524adfaaf 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java @@ -62,14 +62,20 @@ public class WLRepositoryResolver /* Such as FailedConnectionException */ throw e; } catch (RuntimeException e) { - Log.warn("Runtime exception when trying to open repo", e); + Log.warn( + "Runtime exception when trying to open repo: " + projName, + e + ); throw new ServiceMayNotContinueException(e); } catch (ForbiddenException e) { throw new ServiceNotAuthorizedException(); } catch (GitUserException e) { throw new ServiceMayNotContinueException(e.getMessage(), e); } catch (IOException e) { - Log.warn("IOException when trying to open repo", e); + Log.warn( + "IOException when trying to open repo: " + projName, + e + ); throw new ServiceMayNotContinueException("Internal server error."); } } diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java index 3a6d048aba..516f99b1a2 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java @@ -16,6 +16,7 @@ import uk.ac.ic.wlgitbridge.snapshot.servermock.util.FileUtil; import uk.ac.ic.wlgitbridge.util.Util; import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; @@ -629,8 +630,18 @@ public class WLGitBridgeIntegrationTest { int exitCode = gitProcess.waitFor(); if (exitCode != 0) { System.err.println("git clone failed. Dumping stderr and stdout."); - System.err.println(IOUtils.toString(gitProcess.getErrorStream())); - System.err.println(IOUtils.toString(gitProcess.getInputStream())); + System.err.println( + IOUtils.toString( + gitProcess.getErrorStream(), + StandardCharsets.UTF_8 + ) + ); + System.err.println( + IOUtils.toString( + gitProcess.getInputStream(), + StandardCharsets.UTF_8 + ) + ); fail("git clone failed"); } File repositoryDir = new File(dir, repositoryName); @@ -680,7 +691,10 @@ public class WLGitBridgeIntegrationTest { if (swapCfg != null) { cfgStr += ",\n" + " \"swapStore\": {\n" + - " \"type\": \"memory\"\n" + + " \"type\": \"memory\",\n" + + " \"awsAccessKey\": null,\n" + + " \"awsSecret\": null,\n" + + " \"s3BucketName\": \"com.overleaf.testbucket\"\n" + " },\n" + " \"swapJob\": {\n" + " \"minProjects\": " +