Просмотр исходного кода

Sanitise s3 info and fix for s3

Winston Li 10 лет назад
Родитель
Сommit
52e5d2921f

+ 17 - 9
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

+ 1 - 0
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())

+ 13 - 0
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 : "<awsAccessKey>",
+                awsSecret == null ? null : "<awsSecret>",
+                s3BucketName
+        );
+    }
+
+    public static SwapStoreConfig sanitisedCopy(SwapStoreConfig swapStore) {
+        return swapStore == null ? null : swapStore.sanitisedCopy();
+    }
+    
 }

+ 8 - 2
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.");
         }
     }

+ 17 - 3
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\": " +