1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-07 09:30:13 +02:00
copilot/cloudapi-graphql/src/api/request.js
Sérgio Ramos 8e832f9f03 enable triton credentials from credentials.json
credentials can be set not only using ENV variables,
but also with credentials.json (if it is found)
2016-10-20 10:58:19 +01:00

41 lines
861 B
JavaScript

const credentials = require('../credentials');
const auth = require('smartdc-auth');
const cloudapi = require('triton/lib/cloudapi2');
const bunyan = require('bunyan');
const pkg = require('../../package.json');
var log = bunyan.createLogger({
name: pkg.name,
});
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;