2016-10-17 18:41:17 +03:00
|
|
|
const credentials = {
|
|
|
|
url: process.env.SDC_URL,
|
|
|
|
account: process.env.SDC_ACCOUNT,
|
|
|
|
user: process.env.SDC_USER || '',
|
|
|
|
keyId: process.env.SDC_KEY_ID,
|
|
|
|
};
|
2016-10-10 18:37:26 +03:00
|
|
|
|
|
|
|
const auth = require('smartdc-auth');
|
|
|
|
const cloudapi = require('triton/lib/cloudapi2');
|
|
|
|
const bunyan = require('bunyan');
|
2016-10-14 14:51:09 +03:00
|
|
|
const pkg = require('../../package.json');
|
2016-10-10 18:37:26 +03:00
|
|
|
|
|
|
|
var log = bunyan.createLogger({
|
2016-10-14 14:51:09 +03:00
|
|
|
name: pkg.name,
|
2016-10-10 18:37:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
var client = cloudapi.createClient({
|
|
|
|
log: log,
|
|
|
|
url: credentials.url,
|
|
|
|
account: credentials.account,
|
|
|
|
user: credentials.user,
|
|
|
|
sign: auth.cliSigner({
|
|
|
|
log: log,
|
|
|
|
keyId: credentials.keyId,
|
|
|
|
user: credentials.account,
|
|
|
|
subuser: credentials.user
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = (method, args) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const fn = client[method].bind(client);
|
|
|
|
|
|
|
|
const cb = (err, res) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(res);
|
|
|
|
};
|
|
|
|
|
|
|
|
return args ? fn(args, cb) : fn(cb);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.client = client;
|