Actually verify s3 credentials by using the api

This commit is contained in:
Johannes Zellner
2016-10-11 11:46:28 +02:00
parent cac85b17bc
commit 6e6d4f7413

View File

@@ -163,5 +163,30 @@ function testConfig(apiConfig, callback) {
if (typeof apiConfig.bucket !== 'string') return callback(new SettingsError(SettingsError.BAD_FIELD, 'bucket must be a string'));
if (typeof apiConfig.prefix !== 'string') return callback(new SettingsError(SettingsError.BAD_FIELD, 'prefix must be a string'));
callback();
// attempt to upload and delete a file with new credentials
getBackupCredentials(apiConfig, function (error, credentials) {
if (error) return callback(error);
var params = {
Bucket: apiConfig.bucket,
Key: apiConfig.prefix + '/testfile',
Body: 'testcontent'
};
var s3 = new AWS.S3(credentials);
s3.putObject(params, function (error) {
if (error) return callback(new SettingsError(SettingsError.EXTERNAL_ERROR, error.message));
var params = {
Bucket: apiConfig.bucket,
Key: apiConfig.prefix + '/testfile'
};
s3.deleteObject(params, function (error) {
if (error) return callback(new SettingsError(SettingsError.EXTERNAL_ERROR, error.message));
callback();
});
});
});
}