-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
19 lines (17 loc) · 777 Bytes
/
index.js
File metadata and controls
19 lines (17 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const rock = require('rock-req');
const s3 = require('./s3.js');
const swift = require('./swift.js');
if (global.rockReqConf && typeof global.rockReqConf === 'object') {
Object.assign(rock.defaults, global.rockReqConf);
}
module.exports = (config) => {
/** Check the first credential and return storage type: S3 or Swift client */
const _auth = Array.isArray(config) && config.length > 0 ? config[0] : config;
if (_auth?.accessKeyId && _auth?.secretAccessKey && _auth?.url && _auth?.region) {
return s3(config);
} else if (_auth?.username && _auth?.password && _auth?.authUrl && _auth?.region) {
return swift(config);
} else {
throw new Error("Storage connexion not recognised - did you provide correct credentials for a S3 or Swift storage?");
}
};