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