mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #39 from sharelatex/bg-use-aws-sdk-to-copy-files
use the aws sdk to copy files in S3PersistorManager
This commit is contained in:
commit
04176d479b
2 changed files with 18 additions and 9 deletions
|
@ -11,6 +11,7 @@ path = require("path")
|
||||||
LocalFileWriter = require("./LocalFileWriter")
|
LocalFileWriter = require("./LocalFileWriter")
|
||||||
Errors = require("./Errors")
|
Errors = require("./Errors")
|
||||||
_ = require("underscore")
|
_ = require("underscore")
|
||||||
|
awsS3 = require "aws-sdk/clients/s3"
|
||||||
|
|
||||||
thirtySeconds = 30 * 1000
|
thirtySeconds = 30 * 1000
|
||||||
|
|
||||||
|
@ -25,6 +26,12 @@ buildDefaultOptions = (bucketName, method, key)->
|
||||||
uri:"https://#{bucketName}.s3.amazonaws.com/#{key}"
|
uri:"https://#{bucketName}.s3.amazonaws.com/#{key}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s3 = new awsS3({
|
||||||
|
credentials:
|
||||||
|
accessKeyId: settings.filestore.s3.key,
|
||||||
|
secretAccessKey: settings.filestore.s3.secret
|
||||||
|
})
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
sendFile: (bucketName, key, fsPath, callback)->
|
sendFile: (bucketName, key, fsPath, callback)->
|
||||||
|
@ -91,11 +98,9 @@ module.exports =
|
||||||
|
|
||||||
copyFile: (bucketName, sourceKey, destKey, callback)->
|
copyFile: (bucketName, sourceKey, destKey, callback)->
|
||||||
logger.log bucketName:bucketName, sourceKey:sourceKey, destKey: destKey, "copying file in s3"
|
logger.log bucketName:bucketName, sourceKey:sourceKey, destKey: destKey, "copying file in s3"
|
||||||
s3Client = knox.createClient
|
source = bucketName + '/' + sourceKey
|
||||||
key: settings.filestore.s3.key
|
# use the AWS SDK instead of knox due to problems with error handling (https://github.com/Automattic/knox/issues/114)
|
||||||
secret: settings.filestore.s3.secret
|
s3.copyObject {Bucket: bucketName, Key: destKey, CopySource: source}, (err) ->
|
||||||
bucket: bucketName
|
|
||||||
s3Client.copyFile sourceKey, destKey, (err)->
|
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "something went wrong copying file in aws"
|
logger.err err:err, bucketName:bucketName, sourceKey:sourceKey, destKey:destKey, "something went wrong copying file in aws"
|
||||||
callback(err)
|
callback(err)
|
||||||
|
|
|
@ -25,11 +25,15 @@ describe "S3PersistorManagerTests", ->
|
||||||
get: sinon.stub()
|
get: sinon.stub()
|
||||||
@knox =
|
@knox =
|
||||||
createClient: sinon.stub().returns(@stubbedKnoxClient)
|
createClient: sinon.stub().returns(@stubbedKnoxClient)
|
||||||
|
@stubbedS3Client =
|
||||||
|
copyObject:sinon.stub()
|
||||||
|
@awsS3 = sinon.stub().returns @stubbedS3Client
|
||||||
@LocalFileWriter =
|
@LocalFileWriter =
|
||||||
writeStream: sinon.stub()
|
writeStream: sinon.stub()
|
||||||
deleteFile: sinon.stub()
|
deleteFile: sinon.stub()
|
||||||
@requires =
|
@requires =
|
||||||
"knox": @knox
|
"knox": @knox
|
||||||
|
"aws-sdk/clients/s3": @awsS3
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
"./LocalFileWriter":@LocalFileWriter
|
"./LocalFileWriter":@LocalFileWriter
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
|
@ -207,11 +211,11 @@ describe "S3PersistorManagerTests", ->
|
||||||
@destKey = "my/dest/key"
|
@destKey = "my/dest/key"
|
||||||
@S3PersistorManager = SandboxedModule.require modulePath, requires: @requires
|
@S3PersistorManager = SandboxedModule.require modulePath, requires: @requires
|
||||||
|
|
||||||
it "should use knox to copy file", (done)->
|
it "should use AWS SDK to copy file", (done)->
|
||||||
@stubbedKnoxClient.copyFile.callsArgWith(2, @error)
|
@stubbedS3Client.copyObject.callsArgWith(1, @error)
|
||||||
@S3PersistorManager.copyFile @bucketName, @sourceKey, @destKey, (err)=>
|
@S3PersistorManager.copyFile @bucketName, @sourceKey, @destKey, (err)=>
|
||||||
err.should.equal @error
|
err.should.equal @error
|
||||||
@stubbedKnoxClient.copyFile.calledWith(@sourceKey, @destKey).should.equal true
|
@stubbedS3Client.copyObject.calledWith({Bucket: @bucketName, Key: @destKey, CopySource: @bucketName + '/' + @key}).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "deleteDirectory", ->
|
describe "deleteDirectory", ->
|
||||||
|
|
Loading…
Reference in a new issue