Merge pull request #74 from overleaf/ew-add-file-number-limit

add file limit error
This commit is contained in:
Ersun Warncke 2019-11-13 05:47:26 -08:00 committed by GitHub
commit 3c28b30680
6 changed files with 75 additions and 22 deletions

View file

@ -97,23 +97,20 @@ You have to restart the server for configuration changes to take effect.
## Creating OAuth app
In dev-env, run `bin/run rails_v1 rake db:seed`, or, if using this solo, run the following in the v1
database:
In dev-env, run the following command in mongo to create the oauth application
for git-bridge.
```sql
INSERT INTO public.oauth_applications (
"name", uid, secret, redirect_uri, scopes, skip_authorization,
created_at, updated_at, partner, confidential
) VALUES (
'gitbridge',
'264c723c925c13590880751f861f13084934030c13b4452901e73bdfab226edc',
'e6b2e9eee7ae2bb653823250bb69594a91db0547fe3790a7135acb497108e62d',
'http://www.overleaf.test:5000/no-callback-required',
'git_bridge',
true,
now(),
now(),
null,
true
);
```
db.oauthApplications.insert({
"clientSecret" : "e6b2e9eee7ae2bb653823250bb69594a91db0547fe3790a7135acb497108e62d",
"grants" : [
"password"
],
"id" : "264c723c925c13590880751f861f13084934030c13b4452901e73bdfab226edc",
"name" : "Overleaf Git Bridge",
"redirectUris" : [],
"scopes" : [
"git_bridge"
]
})
```

View file

@ -12,6 +12,7 @@
"oauth2Server": "https://localhost"
},
"repoStore": {
"maxFileNum": 2000,
"maxFileSize": 52428800
},
"swapStore": {

View file

@ -12,6 +12,7 @@
"oauth2Server": "http://v2.overleaf.test:4000"
},
"repoStore": {
"maxFileNum": 2000,
"maxFileSize": 52428800
},
"swapStore": {

View file

@ -28,6 +28,7 @@ import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.model.Snapshot;
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
import uk.ac.ic.wlgitbridge.git.exception.SizeLimitExceededException;
import uk.ac.ic.wlgitbridge.git.exception.FileLimitExceededException;
import uk.ac.ic.wlgitbridge.git.handler.WLReceivePackFactory;
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
@ -426,6 +427,7 @@ public class Bridge {
* @throws IOException
* @throws MissingRepositoryException
* @throws ForbiddenException
* @throws GitUserException
*/
public void push(
Optional<Credential> oauth2,
@ -433,7 +435,7 @@ public class Bridge {
RawDirectory directoryContents,
RawDirectory oldDirectoryContents,
String hostname
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException {
) throws SnapshotPostException, IOException, MissingRepositoryException, ForbiddenException, GitUserException {
try (LockGuard __ = lock.lockGuard(projectName)) {
pushCritical(
oauth2,
@ -507,13 +509,23 @@ public class Bridge {
* @throws MissingRepositoryException
* @throws ForbiddenException
* @throws SnapshotPostException
* @throws GitUserException
*/
private void pushCritical(
Optional<Credential> oauth2,
String projectName,
RawDirectory directoryContents,
RawDirectory oldDirectoryContents
) throws IOException, MissingRepositoryException, ForbiddenException, SnapshotPostException {
) throws IOException, MissingRepositoryException, ForbiddenException, SnapshotPostException, GitUserException {
Optional<Long> maxFileNum = config
.getRepoStore()
.flatMap(RepoStoreConfig::getMaxFileNum);
if (maxFileNum.isPresent()) {
long maxFileNum_ = maxFileNum.get();
if (directoryContents.getFileTable().size() > maxFileNum_) {
throw new FileLimitExceededException(directoryContents.getFileTable().size(), maxFileNum_);
}
}
Log.info("[{}] Pushing", projectName);
String postbackKey = postbackManager.makeKeyForProject(projectName);
Log.info(
@ -529,7 +541,7 @@ public class Bridge {
);
) {
Log.info(
"[{}] Candindate snapshot created: {}",
"[{}] Candidate snapshot created: {}",
projectName,
candidate
);

View file

@ -11,11 +11,19 @@ public class RepoStoreConfig {
@Nullable
private final Long maxFileSize;
public RepoStoreConfig(Long maxFileSize) {
@Nullable
private final Long maxFileNum;
public RepoStoreConfig(Long maxFileSize, Long maxFileNum) {
this.maxFileSize = maxFileSize;
this.maxFileNum = maxFileNum;
}
public Optional<Long> getMaxFileSize() {
return Optional.ofNullable(maxFileSize);
}
public Optional<Long> getMaxFileNum() {
return Optional.ofNullable(maxFileNum);
}
}

View file

@ -0,0 +1,34 @@
package uk.ac.ic.wlgitbridge.git.exception;
import uk.ac.ic.wlgitbridge.util.Util;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class FileLimitExceededException extends GitUserException {
private final long numFiles;
private final long maxFiles;
public FileLimitExceededException(long numFiles, long maxFiles) {
this.numFiles = numFiles;
this.maxFiles = maxFiles;
}
@Override
public String getMessage() {
return "too many files";
}
@Override
public List<String> getDescriptionLines() {
return Arrays.asList(
"repository contains " +
numFiles + " files, which exceeds the limit of " +
maxFiles + " files"
);
}
}