Compare commits

..

No commits in common. "8c0cb1d940ba4ba56c6f758cc21dd73d4d8775ee" and "ac05aa1eddb8553556a5594a78c4f1da556ce35e" have entirely different histories.

View File

@ -31,13 +31,14 @@ export class OvhApi{
}
requestLogs({path, header, body, res, err}){
console.log(
`\napi request at ${path} =>`,
'header:', header,
'body:', body,
'\napi response =>'
);
console.assert(res) || console.error(err);
console.log(`api request at ${path} =>`);
console.log('header:');
console.log(header);
console.log('body:')
console.log(body);
console.log('api response =>');
if (res) console.log(res);
if (err) console.error(err)
}
async sendSignedRequest({
@ -47,19 +48,20 @@ export class OvhApi{
header={accept: 'json'},
timestamp = (Date.now()/1000).toFixed()
}){
if (!this.credentials.consumerKey) await this.getConsumerKey();
header['X-Ovh-Timestamp'] = timestamp;
header['X-Ovh-Consumer'] = this.credentials.consumerKey || await this.getConsumerKey();
header['X-Ovh-Application'] = this.credentials.applicationKey;
header['X-Ovh-Signature'] = this.getSignature({
header['X-Ovh-Signature'] = await this.getSignature({
method: getMethod(this.methods),
query: this.baseUrl+path,
body: JSON.stringify(body),
timestamp
});
header['X-Ovh-Consumer'] = this.credentials.consumerKey;
header['X-Ovh-Application'] = this.credentials.applicationKey;
return await this.sendRequest({path, body, getMethod, header});
}
getSignature({method = 'GET', query, body='', timestamp}){
async getSignature({method = 'GET', query, body='', timestamp}){
return '$1$' + sha1(
this.credentials.applicationSecret+'+'+
this.credentials.consumerKey+'+'+
@ -86,7 +88,7 @@ export class OvhApi{
this.credentials.consumerKey = res.consumerKey;
console.log('please validate on ovh site:');
console.log(res.validationUrl);
return this.rl.question('continue? (Y/n)', async (input) => {
await this.rl.question('continue? (Y/n)', (input) => {
switch (input) {
case 'n': process.exit(); break;
default: return res.consumerKey;