-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapi
executable file
·51 lines (41 loc) · 1.6 KB
/
testapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
const request = require('request-promise');
require('dotenv').config();
const fs = require('fs');
async function main(configurationId, mimeType, path) {
const clientid = process.env.XILLIO_CLIENTID;
const clientsecret = process.env.XILLIO_CLIENTSECRET
const username = process.env.XILLIO_USERNAME;
const password = process.env.XILLIO_PASSWORD;
const tenant = process.env.XILLIO_TENANT;
async function getToken() {
const authentication = await request({
method: 'POST',
uri: `${tenant}/oauth/token`,
headers: {
'Authorization': 'Basic ' + Buffer.from(clientid + ':' + clientsecret).toString('base64'),
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
json: true,
body: 'grant_type=password&username=' + username + '&password=' + password
})
return authentication["access_token"];
}
async function getContents(configurationId, mimeType, path ) {
return await request({
uri: `${tenant}/v2/contents/${configurationId}/${path}`,
headers: {
'Authorization': 'Bearer ' + token,
'Accept': mimeType ? mimeType : 'application/octet-stream'
},
json: true,
});
}
const token = await getToken();
const contents = await getContents(configurationId, mimeType, path);
console.log(contents);
}
const configurationId = process.argv[2];
const mimeType = process.argv[3];
const path = process.argv[4];
main(configurationId, mimeType, path);