Compare commits
No commits in common. "8c0cb1d940ba4ba56c6f758cc21dd73d4d8775ee" and "ac05aa1eddb8553556a5594a78c4f1da556ce35e" have entirely different histories.
8c0cb1d940
...
ac05aa1edd
26
OvhApi.js
26
OvhApi.js
@ -31,13 +31,14 @@ export class OvhApi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestLogs({path, header, body, res, err}){
|
requestLogs({path, header, body, res, err}){
|
||||||
console.log(
|
console.log(`api request at ${path} =>`);
|
||||||
`\napi request at ${path} =>`,
|
console.log('header:');
|
||||||
'header:', header,
|
console.log(header);
|
||||||
'body:', body,
|
console.log('body:')
|
||||||
'\napi response =>'
|
console.log(body);
|
||||||
);
|
console.log('api response =>');
|
||||||
console.assert(res) || console.error(err);
|
if (res) console.log(res);
|
||||||
|
if (err) console.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendSignedRequest({
|
async sendSignedRequest({
|
||||||
@ -47,19 +48,20 @@ 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-Consumer'] = this.credentials.consumerKey || await this.getConsumerKey();
|
header['X-Ovh-Signature'] = await this.getSignature({
|
||||||
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});
|
||||||
}
|
}
|
||||||
|
|
||||||
getSignature({method = 'GET', query, body='', timestamp}){
|
async getSignature({method = 'GET', query, body='', timestamp}){
|
||||||
return '$1$' + sha1(
|
return '$1$' + sha1(
|
||||||
this.credentials.applicationSecret+'+'+
|
this.credentials.applicationSecret+'+'+
|
||||||
this.credentials.consumerKey+'+'+
|
this.credentials.consumerKey+'+'+
|
||||||
@ -86,7 +88,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);
|
||||||
return this.rl.question('continue? (Y/n)', async (input) => {
|
await this.rl.question('continue? (Y/n)', (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