diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-09-07 17:58:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-09-07 17:58:09 +0200 |
commit | 8df87ce792be7b0ccdad4cb703e5ca3be66d214a (patch) | |
tree | f28b8705da384f99009f1a63942616aa244d6552 /server/tests/real-world/tools/get-access-token.ts | |
parent | fdbda9e3d6564ec908733c7019305f6a3c363a9f (diff) | |
download | PeerTube-8df87ce792be7b0ccdad4cb703e5ca3be66d214a.tar.gz PeerTube-8df87ce792be7b0ccdad4cb703e5ca3be66d214a.tar.zst PeerTube-8df87ce792be7b0ccdad4cb703e5ca3be66d214a.zip |
Convert real world tools to typescript
Diffstat (limited to 'server/tests/real-world/tools/get-access-token.ts')
-rw-r--r-- | server/tests/real-world/tools/get-access-token.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/tests/real-world/tools/get-access-token.ts b/server/tests/real-world/tools/get-access-token.ts new file mode 100644 index 000000000..a2f076039 --- /dev/null +++ b/server/tests/real-world/tools/get-access-token.ts | |||
@@ -0,0 +1,49 @@ | |||
1 | import * as program from 'commander' | ||
2 | import * as Promise from 'bluebird' | ||
3 | |||
4 | import { | ||
5 | getClient, | ||
6 | loginAndGetAccessToken | ||
7 | } from '../../utils' | ||
8 | |||
9 | program | ||
10 | .option('-u, --url <url>', 'Server url') | ||
11 | .option('-n, --username <username>', 'Username') | ||
12 | .option('-p, --password <token>', 'Password') | ||
13 | .parse(process.argv) | ||
14 | |||
15 | if ( | ||
16 | !program['url'] || | ||
17 | !program['username'] || | ||
18 | !program['password'] | ||
19 | ) { | ||
20 | throw new Error('All arguments are required.') | ||
21 | } | ||
22 | |||
23 | const server = { | ||
24 | url: program['url'], | ||
25 | user: { | ||
26 | username: program['username'], | ||
27 | password: program['password'] | ||
28 | }, | ||
29 | client: { | ||
30 | id: null, | ||
31 | secret: null | ||
32 | } | ||
33 | } | ||
34 | |||
35 | getClient(program.url) | ||
36 | .then(res => { | ||
37 | server.client.id = res.body.client_id | ||
38 | server.client.secret = res.body.client_secret | ||
39 | |||
40 | return loginAndGetAccessToken(server) | ||
41 | }) | ||
42 | .then(accessToken => { | ||
43 | console.log(accessToken) | ||
44 | process.exit(0) | ||
45 | }) | ||
46 | .catch(err => { | ||
47 | console.error(err) | ||
48 | process.exit(-1) | ||
49 | }) | ||