]>
Commit | Line | Data |
---|---|---|
677618d4 C |
1 | 'use strict' |
2 | ||
3 | const program = require('commander') | |
4 | ||
3fad43ac C |
5 | const utilsClient = require('../../utils/clients') |
6 | const utilsLogin = require('../../utils/login') | |
677618d4 C |
7 | |
8 | program | |
9 | .option('-u, --url <url>', 'Server url') | |
10 | .option('-n, --username <username>', 'Username') | |
11 | .option('-p, --password <token>', 'Password') | |
12 | .parse(process.argv) | |
13 | ||
14 | if ( | |
15 | !program.url || | |
16 | !program.username || | |
17 | !program.password | |
18 | ) { | |
19 | throw new Error('All arguments are required.') | |
20 | } | |
21 | ||
22 | const server = { | |
23 | url: program.url, | |
24 | user: { | |
25 | username: program.username, | |
26 | password: program.password | |
27 | }, | |
28 | client: { | |
29 | id: null, | |
30 | secret: null | |
31 | } | |
32 | } | |
33 | ||
3fad43ac | 34 | utilsClient.getClient(program.url, function (err, res) { |
677618d4 C |
35 | if (err) throw err |
36 | ||
37 | server.client.id = res.body.client_id | |
38 | server.client.secret = res.body.client_secret | |
39 | ||
3fad43ac | 40 | utilsLogin.loginAndGetAccessToken(server, function (err, accessToken) { |
677618d4 C |
41 | if (err) throw err |
42 | ||
43 | console.log(accessToken) | |
44 | }) | |
45 | }) |