Sanitise s3 info and fix for s3

This commit is contained in:
Winston Li 2016-08-24 18:26:38 +01:00 committed by Michael Mazour
parent 9936fbe3c9
commit 52e5d2921f
5 changed files with 56 additions and 14 deletions

View file

@ -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

View file

@ -153,6 +153,7 @@ public class SwapJobImpl implements SwapJob {
projName,
swapStore.openDownloadStream(projName)
);
swapStore.remove(projName);
dbStore.setLastAccessedTime(
projName,
Timestamp.valueOf(LocalDateTime.now())

View file

@ -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();
}
}

View file

@ -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.");
}
}

View file

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